We usually need to configure and optimize many parameters when installing the new Linux system, while the installation of the server operating system is usually minimized, which is also the most stable in the production environment.
This script is used to configure CentOS6.X, such as disabling iptable, SElinux, and ipv6, optimizing the system kernel, and stopping unnecessary system services. You can also add or modify the content in the script as needed, especially when deploying a large number of servers.
#! /Bin/bash
# Created by Anson
# MAIL: 744120325@qq.com
# BLOG: http://523514.blog.51cto.com
#2014.01.21
Cat <EOF
+ -------------------------------------------------------------- +
| === Welcome to CentOS System init ==|
+ -------------------------------------------------------------- +
+ -------------------------- By Anson ------------------------------ +
EOF
# Set ntp
Yum-y install ntp yum-plugin * nmap telnet lrzsz gcc
Ntpdate time.windows.com
Ntpdate 210.72.145.44
Echo "* 3 ***/usr/sbin/ntpdate 210.72.145.44>/dev/null 2> & 1">/etc/crontab
Service crond restart
# Set ulimit
Echo "ulimit-SHn 102400">/etc/rc. local
# Set locale
# True>/etc/sysconfig/i18n
# Cat>/etc/sysconfig/i18n <EOF
# LANG = "zh_CN.GB18030"
# SUPPORTED = "zh_CN.GB18030: zh_CN: zh: en_US.UTF-8: en_US: en"
# SYSFONT = "latarcyrheb-sun16"
# EOF
# 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
EOF
/Sbin/sysctl-p
Echo "sysctl set OK !! "
# Close ctrl + alt + del for 5.x
# Sed-I "s/ca: ctrlaltdel: \/sbin \/shutdown-t3-r now/# ca: ctrlaltdel: \/sbin \/shutdown-t3-r now/"/etc/inittab
# Close ctrl + alt + del for 6.x
Mv/etc/init/control-alt-delete.conf/etc/init/control-alt-delete.conf.bak
# Set purview
Chmod 600/etc/passwd
Chmod 600/etc/shadow
Chmod 600/etc/group
Chmod 600/etc/gshadow
# Disable ipv6
Cat <EOF
+ -------------------------------------------------------------- +
| === Welcome to Disable IPV6 ==|
+ -------------------------------------------------------------- +
EOF
# Disable IPv6 for 5.x
# Echo "alias net-pf-10 off">/etc/modprobe. conf
# Echo "alias ipv6 off">/etc/modprobe. conf
# Disable IPv6 for 6.x
Echo "alias net-pf-10 off">/etc/modprobe. d/ECS. conf
Echo "alias ipv6 off">/etc/modprobe. d/ECS. conf
/Sbin/chkconfig -- level 35 ip6tables off
Echo "ipv6 is disabled! "
# Disable selinux
Sed-I '/SELINUX/s/enforcing/disabled/'/etc/selinux/config
Echo "selinux is disabled, you must reboot! "
# Vim
Sed-I "8 s/^/alias vi = 'vim '/"/root/. bashrc
Echo 'syntax on'>/root/. vimrc
# Zh_cn
# Sed-I-e's/^ LANG =. */LANG = "en"/'/etc/sysconfig/i18n
# Init_ssh
# Ssh_cf = "/etc/ssh/sshd_config"
# Sed-I-e '74 s/^/#/'-I-e '76 s/^/#/' $ ssh_cf
# Sed-I "s/# Port 22/Port 65535/" $ ssh_cf
# Sed-I "s/# UseDNS yes/UseDNS no/" $ ssh_cf
# Client
# Sed-I-e '44 s/^/#/'-I-e' 48 s/^/#/'$ ssh_cf
# Service sshd restart
# Echo "ssh is init is OK .............."
# Chkser
# Tunoff services
#--------------------------------------------------------------------------------
Cat <EOF
+ -------------------------------------------------------------- +
| === Welcome to Tunoff services ===|
+ -------------------------------------------------------------- +
EOF
#---------------------------------------------------------------------------------
For I in 'ls/etc/rc3.d/S *'
Do
CURSRV = 'echo $ I | cut-c 15 -'
Echo $ CURSRV
Case $ CURSRV in
Crond | irqbalance | microcode_ctl | network | random | iptables | sshd | syslog | local)
Echo "Base services, Skip! "
;;
*)
Echo "change $ CURSRV to off"
Chkconfig -- level 235 $ CURSRV off
Service $ CURSRV stop
;;
Esac
Done
Echo "service is init is OK .............."
Replace Linux Shell Parameters
Shell for parameters
Pass Linux/Unix Shell parameters to SQL scripts
Introduction to parameter passing methods in Shell scripts
PASS command line parameters through Shell scripts