#!/bin/bash
# This scripts is written by jerry
# createdate 2013/3/5
# updatedate 2013/7/12
#set DNS
echo "nameserver 202.96.209.133" >> /etc/resolv.conf
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
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
#add nginx
#rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
#update system pack
yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 mlocate flex sysstat lsof setuptool system-config-network-tui system-config-firewall-tui libaio-devel wget ntp ntpdate
#add epel
rpm -Uvh http://mirrors.ustc.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
#add rpmfprge
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
#set ntp
echo "*/50 * * * * /usr/sbin/ntpdate 10.10.99.106 > /dev/null 2>&1" > /var/spool/cron/root
service crond restart
#set ulimit
echo "ulimit -SHn 65536" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
* soft nofile 65536
* hard nofile 65536
EOF
#set max user processes
sed -i 's/1024/102400/' /etc/security/limits.d/90-nproc.conf
ulimit -u 102400
# turnoff the control-alt-delete
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf
#close useless service
for i in `ls /etc/rc3.d/S*`
do
CURSRV=`echo $i|cut -c 15-`
echo $CURSRV
case $CURSRV in
crond | irqbalance | network | postfix | sshd | rsyslog | sysstat )
echo "Base services, Skip!"
;;
*)
echo "change $CURSRV to off"
chkconfig --level 2345 $CURSRV off
service $CURSRV stop
;;
esac
done
echo "service is init is ok.............."
#set LANG
:> /etc/sysconfig/i18n
cat >> /etc/sysconfig/i18n << EOF
LANG="en_US.UTF-8"
EOF
#set ssh
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%' /etc/ssh/sshd_config
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
#sed -i 's/#Port 22/Port 6343/' /etc/ssh/sshd_config
service sshd restart
#set username
useradd ops
echo 0ps.iz3n3|passwd --stdin ops
useradd lscm
echo izene123|passwd --stdin lscm
chown -R lscm.lscm /opt
#set user to sudo
echo "ops ALL=(root) NOPASSWD: ALL" >> /etc/sudoers
#set time
cp -a /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#set inittab
sed -i '/tty[2-6]/s/^/#/' /etc/inittab
#set sysctl
true > /etc/sysctl.conf
cat >> /etc/sysctl.conf << EOF
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65535
vm.swappiness = 0
EOF
/sbin/sysctl -p
echo "sysctl set OK!!"
#disable ipv6
echo "alias net-pf-10 off" >> /etc/modprobe.d/dist.conf
echo "alias ipv6 off" >> /etc/modprobe.d/dist.conf
/sbin/chkconfig ip6tables off
echo "ipv6 is disabled!"
#disable selinux
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
setenforce 0
#vim setting
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc
echo 'syntax on' > /root/.vimrc
#install zabbix_agentd monitor
wget http://10.10.99.106:/software/autozabbix_client.sh && sh /root/autozabbix_client.sh
#edit profile
wget http://10.10.99.106:/software/export.sh && sh /root/export.sh
cat << EOF
+--------------------------------------------------------------+
| ===System init over=== |
+--------------------------------------------------------------+
+---------------------------by jerry--------------------------+
EOF
echo "###############################################################"