- #!/bin/bash
- #1
- #############system service#############################
- for i in abrt-ccpp abrt-oops abrtd acpid atd auditd autofs avahi-daemon certmonger cgconfig cgred cpuspeed crond cups haldaemon ip6tables iptables irqbalance kdump libvirt-guests lvm2-monitor matahari-broker matahari-host matahari-network matahari-service matahari-sysconfig mcelogd mdmonitor messagebus netconsole netfs network nfs nfslock ntpd ntpdate oddjobd portreserve postfix psacct qpidd quota_nld rdisc restorecond rpcbind rpcgssd rpcidmapd rpcsvcgssd rsyslog saslauthd smartd sshd sssd sysstat udev-post xinetd ypbind
- do
- chkconfig --level 345 ${i} off
- done
- for k in crond cpuspeed irqbalance iptables libvirt-guests network mcelogd rsyslog sshd sysstat xinetd
- do
- chkconfig --level 345 ${k} on
- done
- echo "########################system service is ok######################################################"
- sleep 10
- echo " * softnofile 65500" >> /etc/security/limits.conf
- echo " * hardnofile 65533" >> /etc/security/limits.conf
- echo "############################### basic is OK #####################################################"
- service iptables stop
- sleep 3
- cat /dev/null > /etc/sysconfig/iptables
- cat > /etc/sysconfig/iptables << EOF
- *filter
- :INPUT ACCEPT [0:0]
- :FORWARD ACCEPT [0:0]
- :OUTPUT ACCEPT [0:0]
- :RH-Firewall-1-INPUT - [0]
- -A INPUT -j RH-Firewall-1-INPUT
- -A FORWARD -j RH-Firewall-1-INPUT
- -A RH-Firewall-1-INPUT -i lo -j ACCEPT
- -A RH-Firewall-1-INPUT -p icmp -j ACCEPT
- -A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
- -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
- -A RH-Firewall-1-INPUT -j DROP
- COMMIT
- EOF
- service iptables start > /dev/null 2>&1
- sleep 10
- echo "############################### iptables is OK ###################################################"
- mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
- wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O /etc/yum.repos.d/CentOS-Base.repo
- yum makecache
- sleep 10
- echo "############################### yum is OK ###################################################"
- cat >> /etc/sysctl.conf << EOF
- kernel.shmall = 4294967296
- kernel.shmmni = 32
- kernel.shmmax = 68719476736
- kernel.msgmnb = 65536
- kernel.msgmax = 65536
- kernel.sysrq = 0
- kernel.core_uses_pid = 1
- net.ipv4.ip_local_port_range = 1024 65000
- net.ipv4.tcp_timestamps = 1
- net.ipv4.tcp_syncookies = 1
- net.ipv4.tcp_syn_retries = 1
- net.ipv4.tcp_synack_retries = 1
- net.ipv4.tcp_tw_recycle = 1
- net.ipv4.tcp_tw_reuse = 1
- net.ipv4.tcp_fin_timeout = 5
- net.ipv4.route.gc_timeout = 30
- net.ipv4.tcp_keepalive_time = 30
- net.ipv4.tcp_max_syn_backlog = 650000
- EOF
- /sbin/sysctl -p
- sleep 10
- echo "############################### sysctl is OK ###################################################"
- echo "5,10,15 2 * * * /usr/sbin/ntpdate 192.168.1.50 > /dev/null 2>&1" >> /var/spool/cron/root
- echo "############################### crontab is OK ###################################################"
转载于:https://blog.51cto.com/cheese/884641