本帖最后由 乐橙306 于 2016-4-21 17:13 编辑
参考文档
centos 新装服务器环境设置脚本 base_setting.sh
http://www.linuser.com/thread-1147-1-1.html
参考文档
centos 新装服务器环境设置脚本 base_setting.sh
http://www.linuser.com/thread-1147-1-1.html
0
本帖最后由 乐橙306 于 2016-4-21 15:29 编辑
- 自己模仿着写的 见谅
- #!/bin/bash
- check_ok() {
- if [ $? != 0 ]
- then
- echo "Error, Check the error log."
- exit 1
- fi
- }
- ###ping###
- echo "1.check network is ok "
- k=`cat /etc/resolv.conf | grep nameserver |wc -l`
- ping -w 6 -c 4 www.qq.com > /tmp/ping.txt
- p=`cat /tmp/ping.txt | grep "transmitted" | awk '{print $4 }'`
- if [[ $k -gt 1 && $p -gt 0 ]]
- then
- echo "network is ok"
- exit 1
- fi
- ###root###
- echo "2.this script must run by root"
- if [ $USER != root ]
- then
- echo "only root can run this script"
- exit 1
- fi
- ###yum###
- echo "3.yum some general package "
- yum install -y wget gcc make perl lrzsz
- check_ok
- ###limit.conf###
- echo "4.change ulimit -SHn 65535"
- cp /etc/security/limits.conf /etc/security/limits.conf.bak
- cat >> /etc/security/limits.conf << eof
- * soft nproc 65535
- * hard nproc 65535
- * soft nofile 65535
- * hard nofile 65535
- eof
- check_ok
- ulimit -SHn 65535
- ###sysctl.conf###
- echo "5.change sysctl.conf "
- cp /etc/sysctl.conf /etc/sysctl.conf.bak
- cat >> /etc/sysctl.conf << eof
- ###syn flood###
- net.ipv4.tcp_synack_retries = 0
- net.ipv4.tcp_max_syn_backlog = 1024
- net.ipv4.tcp_syncookies = 0
- eof
- check_ok
- /sbin/sysctl -p
- check_ok
- ###iptables###
- echo "6.stop iptables "
- iptables -F
- /etc/init.d/iptables save
- /etc/init.d/iptables stop
- chkconfig iptables off
- /usr/sbin/getenforce | grep "Enforcing"
- if [ $? -eq 0 ]
- then
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
- exit
- fi
- getenforce 0
- check_ok
- ###history bashrc###
- echo "7.change /etc/profile "
- cat >> /etc/profile << eof
- export HISTFILESIZE=2000
- export HISTSIZE=2000
- export HISTTIMEFORMAT="%F %T `whoami` "
- alias cp="cp -i"
- alias mv="mv -i"
- alias rm="rm -i"
- eof
- source /etc/profile
- check_ok
- ###ntpdate###
- echo "8.ntpdate time.windows.com"
- /usr/sbin/ntpdate time.windows.com
- echo "30 3 * * * /usr/sbin/ntpdate time.windows.com" >> /etc/crontab
- check_ok
- ###reboot###
- sync
- sleep 10
- reboot
编辑回复