标签:shell
#!/bin/sh sz=`uname -a|grep "x86_64"|wc -l` if [ $sz -ne 1 ] then echo "system hardware-platform error" exit 1 fi echo "----------------------------------------------------------------------" echo "close some services" { chkconfig --level 3 abrtd off chkconfig --level 3 acpid off chkconfig --level 3 atd off chkconfig --level 3 auditd off chkconfig --level 3 autofs off chkconfig --level 3 avahi-daemon off chkconfig --level 3 certmonger off chkconfig --level 3 cgconfig off chkconfig --level 3 cgred off chkconfig --level 3 cpuspeed off chkconfig --level 3 cups off chkconfig --level 3 haldaemon off chkconfig --level 3 ip6tables off chkconfig --level 3 ipsec off chkconfig --level 3 kdump off chkconfig --level 3 lvm2-monitor off chkconfig --level 3 mdmonitor off chkconfig --level 3 messagebus off chkconfig --level 3 netconsole off chkconfig --level 3 netfs off chkconfig --level 3 nfs off chkconfig --level 3 nfslock off chkconfig --level 3 ntpd off chkconfig --level 3 ntpdate off chkconfig --level 3 oddjobd off chkconfig --level 3 portreserve off chkconfig --level 3 postfix off chkconfig --level 3 psacct off chkconfig --level 3 quota_nld off chkconfig --level 3 rdisc off chkconfig --level 3 restorecond off chkconfig --level 3 rhnsd off chkconfig --level 3 rhsmcertd off chkconfig --level 3 rpcbind off chkconfig --level 3 rpcgssd off chkconfig --level 3 rpcidmapd off chkconfig --level 3 rpcsvcgssd off chkconfig --level 3 saslauthd off chkconfig --level 3 smartd off chkconfig --level 3 sssd off chkconfig --level 3 sysstat off chkconfig --level 3 udev-post off chkconfig --level 3 bluetooth off chkconfig --level 3 qpidd off chkconfig --level 3 ypbind off chkconfig --level 3 irqbalance off chkconfig --level 3 blk-availability off chkconfig --level 3 libvirt-guests off chkconfig --level 3 firstboot off } > /dev/null 2>&1 chkconfig --list |grep "3:on" >> /root/install echo "----------------------------------------------------------------------" echo "config the iptables" sz=`grep "161" /etc/sysconfig/iptables|wc -l` if [ $sz -eq 0 ];then { cat <<‘huiye‘ # Firewall configuration written by system-config-securitylevel # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :RH-Firewall-1-INPUT - [0: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 --icmp-type any -j ACCEPT -A RH-Firewall-1-INPUT -s 172.20.0.0/16 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT huiye } > /etc/sysconfig/iptables sed -i ‘245a echo "2621400" > /proc/sys/net/netfilter/nf_conntrack_max‘ /etc/init.d/iptables fi echo "----------------------------------------------------------------------" echo "config the hosts.allow" sz=`grep "222.240.X.X" /etc/hosts.allow|wc -l` if [ $sz -eq 0 ];then { cat <<‘huiye‘ ##lan sshd:172.20.0.0/255.255.0.0 sshd:172.40.0.0/255.255.0.0 huiye } > /etc/hosts.allow chattr +i /etc/hosts.deny fi /usr/sbin/ntpdate clock.isc.org echo "----------------------------------------------------------------------" echo "config rc.local" sz=`grep "proc" /etc/rc.d/rc.local|wc -l` if [ $sz -eq 0 ];then { cat <<‘huiye‘ echo "1" >/proc/sys/net/ipv4/tcp_syncookies echo "1" > /proc/sys/net/ipv4/tcp_synack_retries echo "1" > /proc/sys/net/ipv4/tcp_syn_retries echo "4096000"> /proc/sys/net/ipv4/route/max_size echo "8192" > /proc/sys/net/core/somaxconn echo "2621400" > /proc/sys/net/netfilter/nf_conntrack_max echo "600" > /proc/sys/net/netfilter/nf_conntrack_tcp_timeout_established echo "1048576" > /sys/module/nf_conntrack/parameters/hashsize echo "1024 65534" > /proc/sys/net/ipv4/ip_local_port_range /usr/sbin/ntpdate clock.isc.org /usr/local/snmpd/sbin/snmpd -c /usr/local/snmpd/snmpd.conf -p /var/run/snmpd /usr/local/irq.py huiye } >> /etc/rc.d/rc.local fi echo "* soft nofile 65536" >> /etc/security/limits.conf echo "* hard nofile 65536" >> /etc/security/limits.conf echo "----------------------------------------------------------------------" echo "config crontab" sz=`grep "monitor-base" /var/spool/cron/root|wc -l` if [ $sz -eq 0 ];then { cat <<‘huiye‘ 1 0 * * * /usr/sbin/ntpdate clock.isc.org & 1 1 * * * /usr/sbin/ntpdate ntp.cc.sandai.net & */5 * * * * /sbin/iptables -Z #*/5 * * * * /usr/local/monitor-base/o.sh >/dev/null 2>&1 & huiye } > /var/spool/cron/root fi echo "----------------------------------------------------------------------" echo "keep ipv6" if [ ! -f /etc/modprobe.d/ipv6-off.conf ];then { cat <<‘huiye‘ alias net-pf-10 off options ipv6 disable=1 #alias ipv6 off huiye } >> /etc/modprobe.d/ipv6-off.conf grep "NETWORKING_IPV6" /etc/sysconfig/network ||echo "NETWORKING_IPV6=no" >> /etc/sysconfig/network sed -i ‘s/NETWORKING_IPV6=yes/NETWORKING_IPV6=no/g‘ /etc/sysconfig/network fi #sudo config cp /etc/sudoers /etc/sudoers_backup echo "monitor ALL = /sbin/route, /sbin/ip, /sbin/ifconfig, /bin/ping, /usr/bin/net, /sbin/iptables, /sbin/ethtool, /sbin/service, /sbin/fdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount, /usr/bin/reboot, /sbin/shutdown, /sbin/modprobe" >> /etc/sudoers sz=`cat /etc/sudoers|grep monitor|wc -l` st=`/usr/sbin/visudo -c|grep OK|wc -l` if [ $st -gt 0 -a $sz -gt 0 ]; then echo "update sudouser success!!!" >> /root/install else echo "update sudouser fail!!!" >> /root/install fi echo "----------------------------------------------------------------------" echo "modify the fstab" cp /etc/fstab /etc/fstab_dist sed -i ‘/UUID/ s/defaults/defaults,noatime/g‘ /etc/fstab #sed -i "s/LABEL=\/usr\/local \/usr\/local ext3 defaults 1 2/LABEL=\/usr\/local \/usr\/local ext3 defaults,noatime 1 2/g" /etc/fstab #sed -i "s/LABEL=\/data \/data ext3 defaults 1 2/LABEL=\/data \/data ext3 defaults,noatime 1 2/g" /etc/fstab #for i in {1..15} #$do #sed -i "s/LABEL=\/data$i \/data$i ext3 defaults 1 2/LABEL=\/data$i \/data$i ext3 defaults,noatime 1 2/g" /etc/fstab #$done #root alias rm sz=`cat /home/root1/.bashrc |grep "alias"|grep "rm"|wc -l` if [ $sz -ge 1 ]; then echo "root1 alias had been update success!!" else sed -i "/User specific aliases and functions/a alias rm=‘rm -i‘\nalias cp=‘cp -i‘\nalias mv=‘mv -i‘" /home/root1/.bashrc echo "root1 alias updated success! " fi # crontab alias for bashrc in /home/root1/.bashrc /root/.bashrc;do grep "alias crontab=‘crontab -i‘" $bashrc >/dev/null && echo "$bashrc alias crontab already done before !" || { sed -i "/User specific aliases and functions/ a alias crontab=‘crontab -i‘" $bashrc && grep "alias crontab=‘crontab -i‘" $bashrc >/dev/null && echo "$bashrc alias crontab succeed !" } done #config yum echo "config yum -------------------------------------------------------------------" mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget http://centos.yum.sandai.net/.help/CentOS-Base6.repo -O /etc/yum.repos.d/CentOS-Base.repo rpm -ivh http://centos.yum.sandai.net/.help/epel-release-6-8.noarch.rpm mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo_backup wget http://centos.yum.sandai.net/.help/epel6.repo -O /etc/yum.repos.d/epel.repo yum clean all;yum makecache yum -y install sysstat vnstat telnet jwhois vim lshw yum-plugin-priorities OpenIPMI ipmitool iptraf xinetd iperf #yum -y update kernel wget http://centos.yum.sandai.net/centos/6.4/updates/x86_64/Packages/kernel-2.6.32-358.23.2.el6.x86_64.rpm -O /tmp/kernel-2.6.32-358.23.2.el6.x86_64.rpm wget http://centos.yum.sandai.net/centos/6.4/updates/x86_64/Packages/kernel-firmware-2.6.32-358.23.2.el6.noarch.rpm -O /tmp/kernel-firmware-2.6.32-358.23.2.el6.noarch.rpm wget http://centos.yum.sandai.net/centos/6.4/updates/x86_64/Packages/kernel-devel-2.6.32-358.23.2.el6.x86_64.rpm -O /tmp/kernel-devel-2.6.32-358.23.2.el6.x86_64.rpm cd /tmp/; rpm -ivh kernel-2.6.32-358.23.2.el6.x86_64.rpm kernel-firmware-2.6.32-358.23.2.el6.noarch.rpm kernel-devel-2.6.32-358.23.2.el6.x86_64.rpm [ ! -s /etc/yum.repos.d/CentOS-Base.repo ] && echo "config yum fail!" >> /root/install /usr/sbin/ntpdate clock.isc.org #config xinetd.conf echo "config xinetd.conf-------------------------------------------------------------" cp /etc/xinetd.conf /etc/xinetd.conf_backup sed -i ‘/cps/ s/50 10/500 10/g‘ /etc/xinetd.conf sed -i ‘/instances/ s/50/500/g‘ /etc/xinetd.conf sed -i ‘/per_source/ s/10/200/g‘ /etc/xinetd.conf echo "----------------------------------------------------------------------" echo "sleep for 5 seconds before reboot" echo "`date`" >> /root/install sleep 5 reboot
本文出自 “湘江吹疯” 博客,请务必保留此出处http://xjcf00.blog.51cto.com/10170403/1642556
标签:shell
原文地址:http://xjcf00.blog.51cto.com/10170403/1642556