linux內核高級優化腳本
阿新 • • 發佈:2019-04-22
系統版本 cal ipv gre dha cat war 內存 apr linux內核高級優化腳本
可以用於hadoop生態圈環境的組件安裝 linux內核調優
具體的每一步的解釋請參考 03搭建cdh
備註:使用與centos6和centos7兩個系統版本執行
可以用於hadoop生態圈環境的組件安裝 linux內核調優
具體的每一步的解釋請參考 03搭建cdh
備註:使用與centos6和centos7兩個系統版本執行
[[email protected] scripts]# pwd /opt/scripts [[email protected] scripts]# ll total 12 -rw-r--r-- 1 root root 3837 Apr 22 14:34 adlinuxopt.sh -rw-r--r-- 1 root root 7215 Apr 22 13:32 initialization.sh [[email protected] scripts]# cat adlinuxopt.sh #!/bin/bash #adlinuxopt scripts #author majihui #date 20190422 #by Advanced linux optimization for hadoop echo "在執行此腳本之前需要先執行 initialization.sh 等待5s確認" echo "若沒執行請 ctrl+c 退出執行" sleep 1 echo "1S" sleep 2 echo "2S" sleep 3 echo "3S" sleep 4 echo "4S" sleep 5 echo "5S" if [ ! -d "/opt/scripts" ]; then mkdir -p /opt/scripts fi echo "等待1s:#1/判斷centos7還是centos6系統" sleep 1 VERSION=`cat /etc/redhat-release|awk -F " " ‘{print $3}‘|awk -F "." ‘{print $1}‘` if [ "$VERSION" == "6" ];then VERSION=‘6‘ echo "centos6" else VERSION=‘7‘ echo "centos7" fi echo "-----------------------------華麗分隔符----------------------------------------" echo "#2/調整Linux磁盤緩存和性能" if [ "`egrep "vm.dirty_background_ratio = 5" /etc/sysctl.conf|wc -l`" == "0" ];then echo "vm.dirty_background_ratio = 5" >> /etc/sysctl.conf else echo "Linux磁盤緩存和性能 vm.dirty_background_ratio 設置成功或者之前已經設置過了" fi if [ "`egrep "vm.dirty_ratio = 10" /etc/sysctl.conf|wc -l`" == "0" ];then echo "vm.dirty_ratio = 10" >> /etc/sysctl.conf sysctl -p else echo "Linux磁盤緩存和性能 vm.dirty_ratio設置成功或者之前已經設置過了" fi echo "-----------------------------華麗分隔符----------------------------------------" echo "#3/是否禁用ipv6" echo "等待3秒:" sleep 3 cat << EOF ********************** 1.[disable ipv6] 2.[no disable ipv6] 3.[exit] pls input the num you want: ********************** EOF read -t 30 -p "pls input the num you want:" a [ -n "`echo $a|sed ‘s#[0-9]##g‘`" ] && { echo "Input error" exit 1 } iffuncation(){ if [ $a -eq 1 ];then echo "disable ipv6" echo "等待3S" sleep 3 if [ "`egrep "net.ipv6.conf.all.disable_ipv6=1" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.ipv6.conf.all.disable_ipv6=1" >> /etc/sysctl.conf fi if [ "`egrep "NETWORKING_IPV6=no" /etc/sysconfig/network|wc -l`" == "0" ];then echo "NETWORKING_IPV6=no" >> /etc/sysconfig/network fi pathnetwork=`ls /etc/sysconfig/network-scripts/ifcfg-e*` echo NETWORKING_IPV6=no >> $pathnetwork sysctl -p echo "等待3S" sleep 3 elif [ $a -eq 2 ];then echo "no disable ipv6" elif [ $a -eq 3 ];then exit 1 else echo "Input error" exit 1 fi } iffuncation echo "-----------------------------華麗分隔符----------------------------------------" echo "#4/socket讀寫緩沖區調優" if [ "`egrep "net.core.wmem_default=256960" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.core.wmem_default=256960" >> /etc/sysctl.conf fi if [ "`egrep "net.core.rmem_default=256960" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.core.rmem_default=256960" >> /etc/sysctl.conf fi if [ "`egrep "net.core.wmem_max=2097152" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.core.wmem_max=2097152" >> /etc/sysctl.conf fi if [ "`egrep "net.core.rmem_max=2097152" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.core.rmem_max=2097152" >> /etc/sysctl.conf fi if [ "`egrep "net.ipv4.tcp_wmem=8760 256960 4088000" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.ipv4.tcp_wmem=8760 256960 4088000" >> /etc/sysctl.conf fi if [ "`egrep "net.ipv4.tcp_rmem=8760 256960 4088000" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.ipv4.tcp_rmem=8760 256960 4088000" >> /etc/sysctl.conf sysctl -p else echo "socket讀寫緩沖區調優 設置成功或者之前已經設置過了" fi echo "-----------------------------華麗分隔符----------------------------------------" echo "#5/預讀緩沖調優" DF=`df |sed -n 2p |awk ‘{print $1}‘` blockdev --setra 8192 $DF blockdev --getra $DF
執行結果如下
[[email protected] scripts]# sh adlinuxopt.sh 在執行此腳本之前需要先執行 initialization.sh 等待5s確認 若沒執行請 ctrl+c 退出執行 1S 2S 3S 4S 5S 等待1s:#1/判斷centos7還是centos6系統 centos6 -----------------------------華麗分隔符---------------------------------------- #2/調整Linux磁盤緩存和性能 Linux磁盤緩存和性能 vm.dirty_background_ratio 設置成功或者之前已經設置過了 Linux磁盤緩存和性能 vm.dirty_ratio設置成功或者之前已經設置過了 -----------------------------華麗分隔符---------------------------------------- #3/是否禁用ipv6 等待3秒: ********************** 1.[disable ipv6] 2.[no disable ipv6] 3.[exit] pls input the num you want: ********************** pls input the num you want:1 disable ipv6 等待3S 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 error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key error: "net.bridge.bridge-nf-call-iptables" is an unknown key error: "net.bridge.bridge-nf-call-arptables" is an unknown key kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 vm.swappiness = 1 vm.dirty_background_ratio = 5 vm.dirty_ratio = 10 net.ipv6.conf.all.disable_ipv6 = 1 net.core.wmem_default = 256960 net.core.rmem_default = 256960 net.core.wmem_max = 2097152 net.core.rmem_max = 2097152 net.ipv4.tcp_wmem = 8760 256960 4088000 net.ipv4.tcp_rmem = 8760 256960 4088000 等待3S -----------------------------華麗分隔符---------------------------------------- #4/socket讀寫緩沖區調優 socket讀寫緩沖區調優 設置成功或者之前已經設置過了 -----------------------------華麗分隔符---------------------------------------- #5/預讀緩沖調優 8192
參考鏈接為:03搭建cdh 生產環境前的Linux 優化(涉及到Linux內存參數優化)
https://blog.51cto.com/12445535/2365948
linux內核高級優化腳本