Share a simple Linux Server initialization Shell script

Source: Internet
Author: User

The Shell script is mainly used to initialize the new Linux server system, including:

Disable IPv6 Module
Disable SELinux
Show vim colors
Set system language Encoding
Optimize system services
Kernel Parameter optimization.
It can be modified according to your actual situation and used in the production environment. The original author is NetSeek and I have made some modifications.

Copy codeThe Code is as follows :#! /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)
# This system service is set based on specific application conditions. network, sshd, and syslog are three system services that must be started!
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! "

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.