CentOS-6.5系統基礎最佳化篇,附帶最佳化指令碼

來源:互聯網
上載者:User

標籤:系統最佳化指令碼   centos-6.5最佳化   

最佳化內容:

(1.設定history記錄

(2.添加普通使用者,設定sudo許可權

(3.禁止root遠端使用者登入

(4.修改遠程連接埠

(5.精簡開機啟動伺服器

(6.關閉selinux

(7.配置iptables

(8.修改最大串連數 ulimit

(9.禁止使用Ctrl+Alt+Del快速鍵重啟伺服器

(10.修改預設DNS

(11.安裝必要軟體,更新yum源 [epel源] 

(12.更新核心和軟體到最新版本

(13.最佳化核心參數 [根據實際情況調整]

(14.去除上次登入的資訊

(15.關閉開機顯示核心資訊


1.設定history記錄

echo ‘export HISTFILE=$HOME/.bash_historyexport HISTSIZE=2000export HISTFILESIZE=2000export HISTTIMEFORMAT="%F %T `whoami` "export PROMPT_COMMAND="history -a; history -c; history -r;"shopt -s histappendtypeset -r PROMPT_COMMANDtypeset -r HISTTIMEFORMAT ‘ > /etc/profile.d/history.shsource /etc/profile

2.添加普通使用者,設定sudo許可權

username=‘dyt‘password=‘dyt2015‘useradd $username ; echo $password | passwd --stdin $usernamesed -i "98 a$username    ALL=(ALL)       NOPASSWD: ALL" /etc/sudoers

3.禁止root遠端使用者登入

sed -i ‘s/#PermitRootLogin yes/PermitRootLogin no/‘ /etc/ssh/sshd_config

4.修改遠程連接埠

sed -i ‘s/#Port 22/Port 9527/‘ /etc/ssh/sshd_config/etc/init.d/sshd restart

5.精簡開機啟動伺服器

for server in `chkconfig --list|egrep -v ‘crond|network|rsyslog|sshd|iptables‘|awk ‘{print $1}‘`;do chkconfig $server off; done

6.關閉selinux

sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/configsetenforce 0

7.配置iptables

/etc/init.d/iptables restartiptables -Fiptables -Xiptables -Ziptables -A INPUT -p icmp -j ACCEPTiptables -A INPUT -i lo -j ACCEPT#允許某個IP段遠端存取sshiptables -A INPUT -p tcp -m tcp --dport 9527 -s 192.168.64.0/24 -j ACCEPT#開啟80連接埠iptables -A INPUT -P tcp -m tcp --dropt 80 -j ACCEPT#允許某個IP的所有請求iptables -A INPUT -p all -s 124.43.56.90/30 -j ACCEPTiptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPTiptables -P INPUT DROPiptables -P OUTPUT ACCEPTiptables -P FORWARD DROP/etc/init.d/iptables save/etc/init.d/iptables restart

8.修改最大串連數 ulimit

#方法有很多,未必就這一種echo ‘*  -  noproc  65535‘ >> /etc/security/limits.confecho ‘*  -  nofile  65535‘ >> /etc/security/limits.conf

9.禁止使用Ctrl+Alt+Del快速鍵重啟伺服器

sed -i "s/start on control-alt-delete/#start on control-alt-delete/g" /etc/init/control-alt-delete.conf

10.修改預設DNS

echo "nameserver 8.8.8.8" > /etc/resolv.confecho "nameserver 8.8.4.4" >> /etc/resolv.conf

11.安裝必要軟體,更新yum源 [epel源] 

#根據個人公司情況,這裡只列舉了自己常用的軟體和yum源,根據實際情況更改yum源yum -y install gcc gcc-c++ openssl-devel openssh-clients wget make lrzsz unzip zip xz ntpdate lsof telnet epel-release vim tree kernel-devel kernel

12.更新核心和軟體到最新版本

 yum -y upgrade

13.最佳化核心參數 [根據實際情況調整]

echo -e "net.core.somaxconn = 262144" >> /etc/sysctl.confecho -e "net.core.netdev_max_backlog = 262144" >> /etc/sysctl.confecho -e "net.core.wmem_default = 8388608" >> /etc/sysctl.confecho -e "net.core.rmem_default = 8388608" >> /etc/sysctl.confecho -e "net.core.rmem_max = 16777216" >> /etc/sysctl.confecho -e "net.core.wmem_max = 16777216" >> /etc/sysctl.confecho -e "net.ipv4.route.gc_timeout = 20" >> /etc/sysctl.confecho -e "net.ipv4.ip_local_port_range = 1024 65535" >> /etc/sysctl.confecho -e "net.ipv4.tcp_retries2 = 5" >> /etc/sysctl.confecho -e "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.confecho -e "net.ipv4.tcp_syn_retries = 1" >> /etc/sysctl.confecho -e "net.ipv4.tcp_synack_retries = 1" >> /etc/sysctl.confecho -e "net.ipv4.tcp_timestamps = 0" >> /etc/sysctl.confecho -e "net.ipv4.tcp_tw_recycle = 1" >> /etc/sysctl.confecho -e "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.confecho -e "net.ipv4.tcp_keepalive_time = 120" >> /etc/sysctl.confecho -e "net.ipv4.tcp_keepalive_probes = 3" >> /etc/sysctl.confecho -e "net.ipv4.tcp_keepalive_intvl = 15" >> /etc/sysctl.confecho -e "net.ipv4.tcp_max_tw_buckets = 36000" >> /etc/sysctl.confecho -e "net.ipv4.tcp_max_orphans = 3276800" >> /etc/sysctl.confecho -e "net.ipv4.tcp_max_syn_backlog = 262144" >> /etc/sysctl.confecho -e "net.ipv4.tcp_wmem = 8192 131072 16777216" >> /etc/sysctl.confecho -e "net.ipv4.tcp_rmem = 32768 131072 16777216" >> /etc/sysctl.confecho -e "net.ipv4.tcp_mem = 94500000 915000000 927000000" >> /etc/sysctl.confecho -e "net.ipv4.tcp_slow_start_after_idle = 0" >> /etc/sysctl.confecho -e "vm.swappiness = 0" >> /etc/sysctl.confecho -e "kernel.panic = 5" >> /etc/sysctl.confecho -e "kernel.panic_on_oops = 1" >> /etc/sysctl.conf  echo -e "kernel.core_pipe_limit = 0" >> /etc/sysctl.conf#iptables 防火牆echo -e "net.nf_conntrack_max = 25000000" >> /etc/sysctl.confecho -e "net.netfilter.nf_conntrack_max = 25000000" >> /etc/sysctl.confecho -e "net.netfilter.nf_conntrack_tcp_timeout_established = 180" >> /etc/sysctl.confecho -e "net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120" >> /etc/sysctl.confecho -e "net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60" >> /etc/sysctl.confecho -e "net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120" >> /etc/sysctl.confo

15.去除上次登入的資訊

touch ~/.hushlogin

本文出自 “ˉ、穎濤┃﹎” 部落格,請務必保留此出處http://hypocritical.blog.51cto.com/3388028/1675289

CentOS-6.5系統基礎最佳化篇,附帶最佳化指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.