分享個簡易版Linux服務(wù)器初始化Shell腳本
來源:易賢網(wǎng) 閱讀:877 次 日期:2014-09-05 15:05:01
溫馨提示:易賢網(wǎng)小編為您整理了“分享個簡易版Linux服務(wù)器初始化Shell腳本”,方便廣大網(wǎng)友查閱!

該Shell腳本主要用于新安裝Linux服務(wù)器系統(tǒng)的初始化工作,包括關(guān)閉IPv6模塊,關(guān)閉SELinux,讓vim顯示顏色,設(shè)置系統(tǒng)語言編碼,優(yōu)化系統(tǒng)服務(wù),內(nèi)核參數(shù)優(yōu)化等

該Shell腳本主要用于新安裝Linux服務(wù)器系統(tǒng)的初始化工作,具體包括:

關(guān)閉IPv6模塊

關(guān)閉SELinux

讓vim顯示顏色

設(shè)置系統(tǒng)語言編碼

優(yōu)化系統(tǒng)服務(wù)

內(nèi)核參數(shù)優(yōu)化等。

可以根據(jù)自己的實際情況修改,可用于生產(chǎn)環(huán)境。原作者是NetSeek,本人做了部分修改。

復(fù)制代碼 代碼如下:

#!/bin/sh

# desc: lsm03624 modified by www.webnginx.com

#-------------------cut begin-------------------------------------------

#welcome

cat << EOF

+--------------------------------------------------------------+

| === Welcome to Centos System init === |

+--------------http://www.linuxtone.org------------------------+

+----------------------Author:NetSeek--------------------------+

EOF

#disable ipv6

cat << EOF

+--------------------------------------------------------------+

| === Welcome to Disable IPV6 === |

+--------------------------------------------------------------+

EOF

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

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="zh_CN.UTF-8"/' /etc/sysconfig/i18n

# configure file max to 52100

echo "* soft nofile 52100

* hard nofile 52100" >> /etc/security/limits.conf

#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

cpuspeed | crond | irqbalance | microcode_ctl | mysqld | network | nginx | php-fpm | sendmail | sshd | syslog )

#這個啟動的系統(tǒng)服務(wù)根據(jù)具體的應(yīng)用情況設(shè)置,其中network、sshd、syslog是三項必須要啟動的系統(tǒng)服務(wù)!

echo "Base services, Skip!"

*)

echo "change $CURSRV to off"

chkconfig --level 235 $CURSRV off

service $CURSRV stop

esac

done

rm -rf /etc/sysctl.conf

echo "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 = 134217728

net.ipv4.ip_local_port_range = 1024 65536

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_rmem = 4096 87380 16777216

net.ipv4.tcp_wmem = 4096 65536 16777216

net.ipv4.tcp_fin_timeout = 3

net.ipv4.tcp_tw_recycle = 1

net.core.netdev_max_backlog = 30000

net.ipv4.tcp_no_metrics_save = 1

net.core.somaxconn = 262144

net.ipv4.tcp_syncookies = 0

net.ipv4.tcp_max_orphans = 262144

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

vm.swappiness = 6" >> /etc/sysctl.conf

echo "optimizited kernel configure was done!"

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:分享個簡易版Linux服務(wù)器初始化Shell腳本

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)