安裝后系統(tǒng)配置及優(yōu)化

配置國(guó)內(nèi)源和epel源cd /etc/yum.repos.d/?
mkdir repo_bak?
mv *.repo repo_bak/?
#基礎(chǔ)源文件?
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo?
#epel源文件?
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo?
#重新生成yum緩存?
yum clean all?
yum makecache?
#升級(jí)系統(tǒng)?
yum update -y?
安裝基礎(chǔ)依賴包yum install -y htop lrzsz nmap screen man expect \?
gcc gcc-c++ autoconf automake bzip2-devel \?
openssl-devel multitail kernel-devel \?
pam-devel zlib-devel perl-devel tcp_wrappers-devel?
關(guān)閉selinuxsed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config?
setenforce 0?
#查看selinux設(shè)置?
getenforce?
關(guān)閉默認(rèn)的郵件服務(wù)#(默認(rèn)端口25)?
systemctl disable postfix?
systemctl stop postfix?
#查看系統(tǒng)默認(rèn)監(jiān)聽(tīng)的端口?
netstat -nlput |grep -v "Proto" | grep "LISTEN"?
設(shè)置系統(tǒng)環(huán)境變量#添加執(zhí)行權(quán)限?
chmod a+x /etc/rc.d/rc.local?
#設(shè)置環(huán)境變量?
cat >>/etc/profile <<EOF?
$(date +%F)alias vi='vim'?
alias grep='grep --color=auto'?
#設(shè)置300秒內(nèi)用戶無(wú)操作就字段斷開(kāi)終端?
export TMOUT=300?
#將值設(shè)置為readonly?防止用戶更改?
readonly TMOUT?
EOF?
source /etc/profile?
#vimrc設(shè)置?
cat >>/etc/vimrc <<EOF?
set tabstop=4?
set softtabstop=4?
set shiftwidth=4?
set expandtab?
EOF?
設(shè)置文件打開(kāi)描述符cat >/etc/security/limits.conf <<EOF?
##### $(date) #####?
* soft noproc 65535?
* hard noproc 65535?
* soft nofile 409600?
* hard nofile 409600?
EOF?
優(yōu)化系統(tǒng)內(nèi)核參數(shù)###優(yōu)化內(nèi)核參數(shù)###?
if [ ! -f '/etc/sysctl.conf.bak' ];then?
\cp /etc/sysctl.conf{,.bak}?
cat > /etc/sysctl.conf <<EOF?
$(date)#修改最大連接數(shù)?
net.nf_conntrack_max = 655360?
net.netfilter.nf_conntrack_tcp_timeout_established = 1200?
#套接字由本端關(guān)閉,這個(gè)參數(shù)決了它在FIN-WAIT-2狀態(tài)的時(shí)間,默認(rèn)是60秒。?
net.ipv4.tcp_fin_timeout = 2?
#socket廢棄前重試的次數(shù),重負(fù)載web服務(wù)器建議調(diào)小?
net.ipv4.tcp_orphan_retries = 1?
#表示開(kāi)啟重用。允許將TIME-WAIT sockets重新用于新的TCP連接。?
net.ipv4.tcp_tw_reuse = 1?
#表示開(kāi)啟TCP連接中TIME-WAIT sockets的快速回收。?
net.ipv4.tcp_tw_recycle = 1?
#表示開(kāi)啟SYN Cookies。當(dāng)出現(xiàn)SYN等待隊(duì)列溢出時(shí),啟用cookies來(lái)處理,可防范少量SYN***。?
net.ipv4.tcp_syncookies = 1?
#表示當(dāng)keepalive起用的時(shí)候,TCP發(fā)送keepalive消息的頻度。缺省是2小時(shí),改為10分鐘。?
net.ipv4.tcp_keepalive_time = 600?
#表示用于向外連接的端口范圍。缺省情況下很小:32768到61000,改為1024到65000。?
net.ipv4.ip_local_port_range = 1024 65000?
#加大SYN隊(duì)列長(zhǎng)度,默認(rèn)是1024.可以容納更多等待連接的網(wǎng)絡(luò)連接數(shù)。?
net.ipv4.tcp_max_syn_backlog = 262144?
#imewait的數(shù)量,默認(rèn)是180000。?
net.ipv4.tcp_max_tw_buckets = 6000?
#路由緩存刷新頻率,當(dāng)一個(gè)路由失敗后多長(zhǎng)時(shí)間跳到另一個(gè)路由,默認(rèn)是300。?
net.ipv4.route.gc_timeout = 100?
#內(nèi)核放棄連接之前發(fā)送SYN+ACK的時(shí)間?
net.ipv4.tcp_syn_retries = 1?
#內(nèi)核放棄建立連接之前發(fā)送SYN包的數(shù)量。?
net.ipv4.tcp_synack_retries = 1?
#調(diào)解系統(tǒng)同時(shí)發(fā)起的TCP連接數(shù),默認(rèn)為128.在高并發(fā)的請(qǐng)求中,默認(rèn)值可能導(dǎo)致連接超時(shí)或重傳。?
net.core.somaxconn = 262144?
#該參數(shù)決定了,網(wǎng)絡(luò)設(shè)備接收數(shù)據(jù)包的速率比內(nèi)核處理這些包的速率快時(shí),允許送到隊(duì)列的數(shù)據(jù)包的最大數(shù)目。?
net.core.netdev_max_backlog = 262144?
#設(shè)定系統(tǒng)中最多有多少個(gè)TCP套接字不被關(guān)聯(lián)到任何一個(gè)用戶文件句柄上。可防止簡(jiǎn)單DoS***。?
net.ipv4.tcp_max_orphans = 262144?
EOF?
fi?
#刷新系統(tǒng)內(nèi)核參數(shù):?
/sbin/sysctl -p
了解更多網(wǎng)絡(luò)知識(shí)關(guān)注:http://www.vecloud.com/