服务器全局部署:
- cat init_server.sh
- #!/bin/bash
- cat << EOF
- +--------------------------------------------------------------+
- | === Centos System init server configure=== |
- +--------------------------------------------------------------+
- +--------------------------by iceeggplant 2012.7.27-------------------+
- EOF
- #---------------------------update yum------------------------------------------------
- YUM_DIR=/etc/yum.repos.d/CentOS-Base.repo
- wget http://10.0.0.x/xx/CentOS-Base.repo -P /tmp
- /bin/cp $YUM_DIR ${YUM_DIR}.default
- /bin/cp /tmp/CentOS-Base.repo $YUM_DIR
- #-----------set physical-host ntp time,vhost is not need.------------------------------
- [ ! -d /root/tasks ] && mkdir /root/tasks
- #echo -e "#!/bin/sh\n/usr/sbin/ntpdate 172.16.2.x\n/sbin/hwclock --systohc">>/root/tasks/nt.sh
- ##add to crontab
- #echo "1 1 * * 1 /bin/sh /root/tasks/nt.sh >/dev/null 2>&1" >>/var/spool/cron/root
- #--------------------------user account manager-----------------------------------------
- #add user account
- groupadd -g 500 admins
- useradd -u 500 -g 500 admp
- useradd -u 501 -g 500 adms
- #add ssh-key authorize
- wget http://10.0.0.x/xx/key-ins.sh -P /tmp
- su - admp -c "/bin/sh /tmp/key-ins.sh"
- su - adms -c "/bin/sh /tmp/key-ins.sh"
- rm -f /tmp/key-ins.sh
- #account security,init ssh
- SSH_DIR=/etc/ssh/sshd_config
- /bin/cp $SSH_DIR ${SSH_DIR}.default
- sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' $SSH_DIR
- sed -i 's/#UseDNS yes/UseDNS no/' $SSH_DIR
- sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords yes/' $SSH_DIR
- /etc/init.d/sshd restart
- #---------------------------------------------------------------------------------
- cat << EOF
- +---------------------------------------------------------------------+
- | system optimization part |
- +---------------------------------------------------------------------+
- EOF
- #set ulimit
- echo "ulimit -SHn 65536" >> /etc/rc.local
- #set sysctl
- cat >> /etc/sysctl.conf << EOF
- net.ipv4.tcp_fin_timeout = 2
- net.ipv4.tcp_tw_reuse = 1
- net.ipv4.tcp_tw_recycle = 1
- net.ipv4.tcp_syncookies = 1
- net.ipv4.tcp_keepalive_time = 600
- net.ipv4.ip_local_port_range = 4000 65000
- net.ipv4.tcp_max_syn_backlog = 16384
- net.ipv4.tcp_max_tw_buckets = 36000
- net.ipv4.route.gc_timeout = 100
- net.ipv4.tcp_syn_retries = 1
- net.ipv4.tcp_synack_retries = 1
- net.ipv4.ip_conntrack_max = 25000000
- net.ipv4.netfilter.ip_conntrack_max=25000000
- net.ipv4.netfilter.ip_conntrack_tcp_timeout_established=180
- net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait=120
- net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait=60
- net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait=120
- EOF
- /sbin/sysctl -p
- echo "sysctl set is OK!!"
- #disable selinux
- sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
- setenforce 0
- #---------------------------------------------------------------------------------
- cat << EOF
- +--------------------------------------------------------------+
- | === shut down unnecessary services === |
- +--------------------------------------------------------------+
- EOF
- for service in `chkconfig --list |grep 3:on |awk '{print $1}'`
- do
- chkconfig --level 3 $service off
- done
- for service in network syslog sshd acpid anacron atd auditd crond irqbalance cpuspeed haldaemon irqbalance lm_sensors messagebus
- do
- chkconfig --level 3 $service on
- done
- echo "service is init is ok.............."
- #---------------------------------------------------------------------------------
- cat << EOF
- +--------------------------------------------------------------+
- | === add monitoring of cacti === |
- +--------------------------------------------------------------+
- EOF
- #!/bin/bash
- plat=`uname -i`
- eth0=/etc/sysconfig/network-scripts/ifcfg-eth0
- eth1=/etc/sysconfig/network-scripts/ifcfg-eth1
- [ -d /etc/snmp ] && echo software was installed ,exit .... && exit
- case "$plat"
- in
- x86_64)
- # yum remove net-snmp-libs.i386 -y
- yum install net-snmp.x86_64 -y;;
- i386)
- yum -y install net-snmp.i386;;
- esac
- snmp_file=/etc/snmp/snmpd.conf
- function fun_snmp()
- {
- sed -i '62s/systemview/all/' $snmp_file
- sed -i '85s/#//' $snmp_file
- sed -i '122s/#//' $snmp_file
- chkconfig snmpd on
- chkconfig snmptrapd on
- /etc/init.d/snmpd start
- /etc/init.d/snmptrapd start
- sleep 2
- snmpnew=`netstat -anpt|grep snmpd`
- if [ "$snmpnew" != "" ]
- then
- echo -----------------------------------------------------------
- echo ------------------cacti is runing--------------------------
- echo -----------------------------------------------------------
- fi
- }
- if grep -E '(222.73|172.20)' $eth0;then
- sed -i '41s/default/10.0.0.x/' $snmp_file
- echo 'snmpd:10.0.0.21'>>/etc/hosts.allow
- fun_snmp
- exit
- fi
- if grep -E '(172.20|172.16)' $eth1;then
- sed -i '41s/default/10.0.0.x/' $snmp_file
- fun_snmp
- exit
- fi
- #sudoers manager
- sed -i 's/Defaults requiretty/#Defaults requiretty/' /etc/sudoers
- echo "xxx ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
- #hosts file add
- cat >>/etc/hosts <<EOF
- 10.0.0.x svn1.xxx.com
- 10.0.0.x svn.xx.xxx.com
- EOF
- #nameserver add
- echo 'nameserver 10.0.0.1' >>/etc/resolv.conf
web-server类配置部署:
- cat web-init.sh
- #!/bin/bash
- #--------add account----------------------------
- groupadd -g 501 devs
- useradd -u 502 -g 501 xx_ba
- #--------project file create-------------------
- mkdir -p /var/www/html/xx/ba
- chown -R xx_ba.devs /var/www/html/xx/ba
- mkdir /var/www/conf
- touch /var/www/conf/xx_ba.conf
- chown xx_ba.devs /var/www/conf/xx_ba.conf
- touch /var/www/conf/user.txt
- echo "xx: " >/var/www/conf/user.txt
- echo "xx_ba: " >>/var/www/conf/user.txt
- #---------install package----------------------
- yum remove mysql mysql-server php php-common
- yum install -y subversion.x86_64 subversion-perl.x86_64 perl-libwww-perl
- yum install -y php53-pdo.x86_64 php53-mysql.x86_64 php53-pgsql.x86_64 php53-process.x86_64 php53-xmlrpc.x86_64 php53-soap.x86_64 php53-ldap.x86_64 php53-dba.x86_64 php53-xml.x86_64 php53-odbc.x86_64 php53-pspell.x86_64 php53-intl.x86_64 php53-snmp.x86_64 php53-gd.x86_64 php53-mbstring.x86_64 php53-bcmath.x86_64 php53-imap.x86_64 php53.x86_64 php53-pecl-memcache
- #--------open log permission------------------
- chmod o+rx /var/log/httpd
- #-------configure file backup-----------------
- htpath=/etc/httpd/conf
- /bin/cp $htpath/httpd.conf $htpath/httpd.conf.default
- /bin/cp /etc/php.ini /etc/php.ini.default
- #------install svn update program--------------
- wget http://10.0.0.x/xx/SyncServers.gz -P /var/www
- tar zxpf /var/www/SyncServers.gz -C /var/www
- rm -f /var/www/SyncServers.gz
- #------sudo permission manager----------------echo 'Cmnd_Alias SERCMD = /sbin/service, /etc/init.d/httpd' >>/etc/sudoersecho '%devs ALL=(root) NOPASSWD: SERCMD' >>/etc/sudoer