linux系統優化指令碼
#!/bin/bash
#Author: Andy
#operation system initial
#set ulimit
#最大開啟檔案數設定
limit()
{
echo "ulimit -SHn 65535" >>/etc/rc.local
sed "/End of file/i * - nofile 65535" -i /etc/security/limits.conf
}
#set locale
#字符集設定
locale()
{
true>/etc/sysconfig/i18n
cat>>/etc/sysconfig/i18n<
LANG="en_US.UTF-8"
SUPPORTED="zh_CN.GBK:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
LC_ALL="en_US.UTF-8"
EOF
source /etc/sysconfig/i18n
}
#set sysctl
#核心引數
sysctl()
{
true>/etc/sysctl.conf
cat >>/etc/sysctl.conf<
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_users_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!"
}
initab()
{
sed -i "s/id:5:initdefault:/id:3:initdefault:/" /etc/inittab
sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
}
#禁止更改重要檔案
purview()
{
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow
}
#disable ipv6
#禁用ipv6
disipv6()
{
echo "alias net -pf -10 off" >>/etc/modprobe.conf
echo "alias ipv6 off">>/etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
echo "ipv6 is disabled"
}
#disable selinux
#禁用selinux
diselinux()
{
sed -i "/SELINUX/s/enabled/disabled/" /etc/selinux/config
echo "selinux is disabled,you must reboot system"
}
#init ssh
ssh()
{
sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config
}
#關閉不常用服務
#chkser
chkser()
{
for server in `ls /etc/rc3.d/S*`;do
#Author: Andy
#operation system initial
#set ulimit
#最大開啟檔案數設定
limit()
{
echo "ulimit -SHn 65535" >>/etc/rc.local
sed "/End of file/i * - nofile 65535" -i /etc/security/limits.conf
}
#set locale
#字符集設定
locale()
{
true>/etc/sysconfig/i18n
cat>>/etc/sysconfig/i18n<
SUPPORTED="zh_CN.GBK:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
LC_ALL="en_US.UTF-8"
EOF
source /etc/sysconfig/i18n
}
#set sysctl
#核心引數
sysctl()
{
true>/etc/sysctl.conf
cat >>/etc/sysctl.conf<
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_users_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!"
}
initab()
{
sed -i "s/id:5:initdefault:/id:3:initdefault:/" /etc/inittab
sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
}
#禁止更改重要檔案
purview()
{
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow
}
#disable ipv6
#禁用ipv6
disipv6()
{
echo "alias net -pf -10 off" >>/etc/modprobe.conf
echo "alias ipv6 off">>/etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
echo "ipv6 is disabled"
}
#disable selinux
#禁用selinux
diselinux()
{
sed -i "/SELINUX/s/enabled/disabled/" /etc/selinux/config
echo "selinux is disabled,you must reboot system"
}
#init ssh
ssh()
{
sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config
}
#關閉不常用服務
#chkser
chkser()
{
for server in `ls /etc/rc3.d/S*`;do
curserver=`echo ${server}|cut -c 15-`
echo ${curserver}
case ${curserver} in
crond|irqbalance|microcode_ctl|network|random|sshd|syslog|local)
echo "basic service,skip"
;;
*)
echo "set ${curserver} off"
chkconfig --level 235 ${curserver} off
service ${curserver} stop
;;
esac
done
}
#==================
limit
locale
sysctl
initab
purview
disipv6
diselinux
ssh
chkser
echo ${curserver}
case ${curserver} in
crond|irqbalance|microcode_ctl|network|random|sshd|syslog|local)
echo "basic service,skip"
;;
*)
echo "set ${curserver} off"
chkconfig --level 235 ${curserver} off
service ${curserver} stop
;;
esac
done
}
#==================
limit
locale
sysctl
initab
purview
disipv6
diselinux
ssh
chkser
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-775750/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CentOS 6 系統優化檢測指令碼CentOS優化指令碼
- 初始化linux系統指令碼薦Linux指令碼
- Linux 系統優化Linux優化
- Linux系統配置(系統優化)Linux優化
- Linux系統初始化*引數初始化(指令碼)Linux指令碼
- Linux系統檢查指令碼Linux指令碼
- linux系統最小化安裝後的初始化指令碼Linux指令碼
- linux系統for迴圈小指令碼Linux指令碼
- Linux 系統健康巡檢指令碼Linux指令碼
- Solaris linux 系統監控指令碼Linux指令碼
- 系統初始化SHELL指令碼薦指令碼
- Linux系統安全常規優化Linux優化
- Linux系統效能測試指令碼(unixbenchnmon)Linux指令碼
- dbms_stats.gather_schema_stats 新匯入系統優化簡單指令碼優化指令碼
- javascript指令碼的效能優化JavaScript指令碼優化
- Shell指令碼語言有什麼優勢?linux系統學習步驟指令碼Linux
- Linux 效能優化之 IO 子系統Linux優化
- 熟悉Linux系統的安全和優化Linux優化
- linux系統軟體啟動sh指令碼Linux指令碼
- Linux系統指令碼分析之rc.sysinitLinux指令碼
- (mysql優化-3) 系統優化MySql優化
- Linux 檔案許可權、系統優化Linux優化
- 快速檢視LINUX 系統硬體的指令碼Linux指令碼
- Linux下XWindow系統啟動指令碼分析(轉)Linux指令碼
- Linux優化之IO子系統監控與調優Linux優化
- CUDA優化之指令優化優化
- <Linux系統isosize指令用法>Linux
- <Linux系統stat指令用法>Linux
- 系統巡檢指令碼指令碼
- Linux 作業系統指令碼格式問題導致指令碼無法執行Linux作業系統指令碼
- 使用 Shell 指令碼監控 Linux 系統程式資源指令碼Linux
- Linux系統程式設計(15)——shell指令碼語法Linux程式設計指令碼
- linux系統下重啟tomcat的shell指令碼LinuxTomcat指令碼
- 使用Linux系統的Shell指令碼維護Oracle(轉)Linux指令碼Oracle
- Linux系統優化部分核心引數調優中文註釋Linux優化
- MySQL優化之系統變數優化MySql優化變數
- Linux系統調優Linux
- linux系統指令碼中trap訊號都有哪些?Linux運維Linux指令碼運維