#/bin/bash
if [ $UID -ne 0 ]; then
echo "Superuser privileges are required to run this script."
exit 1
fi
#Check it Fail or Success
function check_ok(){
[ $? -ne 0 ] && exit 1 && echo "$1 Is Fail !" || echo "$1 Is Access !"
}
#Check User ,if not ,add the user
function check_user(){
grep "$1" /etc/group
[ $? != 0 ] && groupadd $1 || echo "$1 group was added"
grep "$1" /etc/passwd
[ $? != 0 ] && useradd -g $1 $1 || echo "$1 User was added"
}
#安装扩展源,必要开发包,系统升级
yum install -y epel-release
yum install -y lrzsz gcc gcc-c++ make man vim unzip wget curl lua-devel lua-static patch libxml2-devel libxslt libxslt-devel gd gd-devel ntp ntpdate screen sysstat tree rsync lsof openssh-clients telnet iftop telnet dos2unix vim rng-tools cronolog
yum update -y
check_ok "yum "
#获取当前路径,移动其他文件致/usr/local/src
PWD=`pwd`
DownDir=/usr/local/src
#配置PS 环境:
echo "1、Will set SYSTEM PS."
sed -i '/^PS1=.*/d' /etc/profile
echo "PS1='\[\e[35;1m\][\u@\h \w \t&&\#]\\$\[\e[m\]'" >> /etc/profile
check_ok
#查看是否有设置普通用户:bwttomcat
check_user bwttomcat
echo '123qwe!@#' |passwd --stdin bwttomcat
check_ok "Change bwttomcat passsword"
#更改root 用户密码
#echo 'seven@2015' |passwd --stdin root
#check_ok "Change root passsword"
sed -i '/^PermisRootLogin.*/d' /etc/ssh/sshd_config && echo "PermitRootLogin no" >> /etc/ssh/sshd_config
sed -i '/^UseDNS.*/d' /etc/ssh/sshd_config && echo "UseDNS no" >> /etc/ssh/sshd_config
sed -i '/^StrictHostKeyChecking/d' /etc/ssh/ssh_config && echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
check_ok "sshd_config"
service sshd restart
#关闭系统selinux
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
check_ok "selinuxconfig"
#设置服务器时区为AMT,#将每10分钟同步系统时间写入计划任务
#cp $DownDir/localtime /etc/
cp /usr/share/zoneinfo/America/Boa_Vista /etc/localtime
echo "*/10 * * * * root /usr/sbin/ntpdate time.windows.com" >> /etc/crontab
check_ok
#系统调优:
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 = 15000
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 = 30
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
fs.file-max = 13000000
#减少超时前的探测次数
net.ipv4.tcp_keepalive_probes=5
net.ipv4.tcp_orphan_retries=3
net.ipv4.tcp_synack_retries=2
kernel.printk_ratelimit = 30
kernel.printk_ratelimit_burst = 200
fs.inotify.max_user_watches=65535
EOF
cat > /etc/security/limits.d/90-nproc.conf <<EOF
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* - nproc 65535
* - nofile 65535
#root soft nproc unlimited
EOF
sed -i '/End of file/d' /etc/security/limits.conf
cat >> /etc/security/limits.conf <<EOF
* - nproc 102400
* - nofile 102400
# End of file
EOF
sed -i 's/d:5:i/d:3:i/g' /etc/inittab
cat > /etc/sysconfig/i18n <<EOF
LANG="zh_CN.GB18030"
LANGUAGE="en_US.UTF-8:zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="lat0-sun16"
EOF
cat >> /etc/bashrc <<EOF
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
export HISTFILESIZE=1000000
export HISTSIZE=2000
EOF
source /etc/bashrc
sync
echo "IS OK"