简易版Linux服务器初始化Shell脚本

系统 Linux
该Shell脚本主要用于新安装Linux服务器系统的初始化工作,包括关闭IPv6模块,关闭SELinux,让vim显示颜色,设置系统语言编码,优化系统服务,内核参数优化等。可以根据自己的实际情况修改,可用于生产环境,可以配合其他的安全脚本、优化脚本一起使用。

该Shell脚本主要用于新安装Linux服务器系统的初始化工作,具体包括:

  1. 关闭IPv6模块
  2. 关闭SELinux
  3. 让vim显示颜色
  4. 设置系统语言编码
  5. 优化系统服务
  6. 内核参数优化等。

可以根据自己的实际情况修改,可用于生产环境。原作者是NetSeek,本人做了部分修改。

#!/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 )
#这个启动的系统服务根据具体的应用情况设置,其中network、sshd、syslog是三项必须要启动的系统服务!
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!"

编者按:这个脚本可以配合其他的安全脚本、优化脚本一起使用。

原文:http://www.linuxde.net/2011/12/3273.html

【编辑推荐】

  1. Linux服务器安全初始化Shell脚本
  2. 快速解决CentOS安装后的初始化问题
  3. 保护你的Web服务器 iptables防火墙脚本全解读
责任编辑:yangsai 来源: Linuxde.net
相关推荐

2011-07-06 14:16:25

Linux服务器Shell脚本

2011-08-10 13:36:30

Servlet

2023-11-06 18:48:31

LinuxShell

2011-06-17 15:29:44

C#对象初始化器集合初始化器

2010-04-27 17:51:37

2021-07-12 15:50:55

Go 语言netstat命令

2023-12-29 08:31:49

Spring框架模块

2018-08-15 08:45:38

2011-08-24 14:26:08

Lua游戏脚本

2010-10-09 09:18:59

Shell脚本

2022-02-11 13:44:56

fiber架构React

2009-08-27 10:31:39

C#对象初始化器

2020-02-03 14:45:50

LinuxWeb前端

2011-03-31 16:46:10

LinuxMySQL

2023-11-12 23:08:17

C++初始化

2017-01-13 08:37:57

PythonAlphaGoMuGo

2009-08-26 15:28:52

C#对象集合初始化器

2010-02-24 15:41:19

Linux Light

2022-10-20 11:49:49

JS动画帧,CSS

2024-08-14 17:02:22

Docker容器
点赞
收藏

51CTO技术栈公众号