脚本修改默认端口,替换iptables防火墙等,内容如下
#!/bin/bash #关闭selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config setenforce 0 #安装wget yum -y install wget yum-utils #更换yum源 repo=`ls /etc/yum.repos.d/repo.bak | wc -l` if [ $repo -eq 0 ]; then mkdir /etc/yum.repos.d/repo.bak mv /etc/yum.repos.d/CentOS* /etc/yum.repos.d/repo.bak cd /etc/yum.repos.d/ wget https://blog.whsir.com/uploads/CentOS7-Base-163.repo yum clean all yum makecache else echo "yum OK" fi #更新时间和系统 cd yum -y install vim screen ntp /usr/sbin/ntpdate ntp1.aliyun.com yum -y update #更改端口 sed -i 's/#Port 22/Port 2188/' /etc/ssh/sshd_config #设置防火墙ifconfig systemctl stop firewalld.service systemctl disable firewalld.service yum -y install iptables-services net-tools systemctl enable iptables.service sed -i 's/22/2188/' /etc/sysconfig/iptables systemctl restart iptables.service systemctl restart sshd yum -y install epel-release #关闭postfix systemctl disable postfix #更改ulimit limit=`cat /etc/security/limits.conf | grep 65535 | wc -l` if [ $limit -eq 0 ]; then echo "ulimit -SHn 65535" >> /etc/rc.local cat >> /etc/security/limits.conf << EOF * soft nofile 65535 * hard nofile 65535 EOF else echo "ulimit ok" fi #开机启动优化 for i in acpid gpm lvm2-monitor anacron haldaemon mcstrans oddjobd setroubleshoot atd halt mdmonitor pand single auditd hidd mdmpd pcscd smartd hplip messagebus avahi-daemon ip6tables microcode_ctl snmptrapd avahi-dnsconfd ipmi multipathd psacct bluetooth rawdevices svnserve conman irda netconsole rdisc cpuspeed irqbalance netfs readahead_early tcsd iscsi netplugd readahead_later winbind cups iscsid restorecond wpa_supplicant cups-config-daemon kdump NetworkManager rpcgssd dnsmasq killall nfs rpcidmapd ypbind dund krb524 nfslock rpcsvcgssd yum-updatesd firstboot lm_sensors nscd saslauthd do chkconfig $i off > /dev/null 2>&1 done date
|----------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #!/bin/bash #关闭selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config setenforce 0 #安装wget yum -y install wget yum-utils #更换yum源 repo=`ls /etc/yum.repos.d/repo.bak | wc -l` if [ $repo -eq 0 ]; then mkdir /etc/yum.repos.d/repo.bak mv /etc/yum.repos.d/CentOS* /etc/yum.repos.d/repo.bak cd /etc/yum.repos.d/ wget http://blog.whsir.com/uploads/CentOS7-Base-163.repo yum clean all yum makecache else echo "yum OK" fi #更新时间和系统 cd yum -y install vim screen ntp /usr/sbin/ntpdate ntp1.aliyun.com yum -y update #更改端口 sed -i 's/#Port 22/Port 2188/' /etc/ssh/sshd_config #设置防火墙ifconfig systemctl stop firewalld.service systemctl disable firewalld.service yum -y install iptables-services net-tools systemctl enable iptables.service sed -i 's/22/2188/' /etc/sysconfig/iptables systemctl restart iptables.service systemctl restart sshd yum -y install epel-release #关闭postfix systemctl disable postfix #更改ulimit limit=`cat /etc/security/limits.conf | grep 65535 | wc -l` if [ $limit -eq 0 ]; then echo "ulimit -SHn 65535" >> /etc/rc.local cat >> /etc/security/limits.conf << EOF * soft nofile 65535 * hard nofile 65535 EOF else echo "ulimit ok" fi #开机启动优化 for i in acpid gpm lvm2-monitor anacron haldaemon mcstrans oddjobd setroubleshoot atd halt mdmonitor pand single auditd hidd mdmpd pcscd smartd hplip messagebus avahi-daemon ip6tables microcode_ctl snmptrapd avahi-dnsconfd ipmi multipathd psacct bluetooth rawdevices svnserve conman irda netconsole rdisc cpuspeed irqbalance netfs readahead_early tcsd iscsi netplugd readahead_later winbind cups iscsid restorecond wpa_supplicant cups-config-daemon kdump NetworkManager rpcgssd dnsmasq killall nfs rpcidmapd ypbind dund krb524 nfslock rpcsvcgssd yum-updatesd firstboot lm_sensors nscd saslauthd do chkconfig $i off > /dev/null 2>&1 done date |
下载地址:
wget https://down.whsir.com/downloads/centos7init.sh
|---|------------------------------------------------------| | 1 | wget https://down.whsir.com/downloads/centos7init.sh |