本文共 5442 字,大约阅读时间需要 18 分钟。
linux内核高级优化脚本
可以用于hadoop生态圈环境的组件安装 linux内核调优具体的每一步的解释请参考 备注:使用与centos6和centos7两个系统版本执行[root@lb01 scripts]# pwd/opt/scripts[root@lb01 scripts]# lltotal 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[root@lb01 scripts]# cat adlinuxopt.sh #!/bin/bash#adlinuxopt scripts#author majihui #date 20190422#by Advanced linux optimization for hadoopecho "在执行此脚本之前需要先执行 initialization.sh 等待5s确认"echo "若没执行请 ctrl+c 退出执行"sleep 1echo "1S"sleep 2echo "2S"sleep 3echo "3S"sleep 4echo "4S"sleep 5echo "5S"if [ ! -d "/opt/scripts" ]; then mkdir -p /opt/scriptsfiecho "等待1s:#1/判断centos7还是centos6系统"sleep 1VERSION=`cat /etc/redhat-release|awk -F " " '{print $3}'|awk -F "." '{print $1}'`if [ "$VERSION" == "6" ];thenVERSION='6'echo "centos6"elseVERSION='7'echo "centos7"fiecho "-----------------------------华丽分隔符----------------------------------------"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.confelse echo "Linux磁盘缓存和性能 vm.dirty_background_ratio 设置成功或者之前已经设置过了"fiif [ "`egrep "vm.dirty_ratio = 10" /etc/sysctl.conf|wc -l`" == "0" ];then echo "vm.dirty_ratio = 10" >> /etc/sysctl.conf sysctl -pelse echo "Linux磁盘缓存和性能 vm.dirty_ratio设置成功或者之前已经设置过了"fiecho "-----------------------------华丽分隔符----------------------------------------"echo "#3/是否禁用ipv6"echo "等待3秒:"sleep 3cat << EOF ********************** 1.[disable ipv6] 2.[no disable ipv6] 3.[exit] pls input the num you want: **********************EOFread -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 3elif [ $a -eq 2 ];then echo "no disable ipv6"elif [ $a -eq 3 ];then exit 1else echo "Input error" exit 1fi}iffuncationecho "-----------------------------华丽分隔符----------------------------------------"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.conffiif [ "`egrep "net.core.rmem_default=256960" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.core.rmem_default=256960" >> /etc/sysctl.conffiif [ "`egrep "net.core.wmem_max=2097152" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.core.wmem_max=2097152" >> /etc/sysctl.conffiif [ "`egrep "net.core.rmem_max=2097152" /etc/sysctl.conf|wc -l`" == "0" ];then echo "net.core.rmem_max=2097152" >> /etc/sysctl.conffiif [ "`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.conffiif [ "`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 -pelse echo "socket读写缓冲区调优 设置成功或者之前已经设置过了"fiecho "-----------------------------华丽分隔符----------------------------------------"echo "#5/预读缓冲调优"DF=`df |sed -n 2p |awk '{print $1}'`blockdev --setra 8192 $DFblockdev --getra $DF
执行结果如下
[root@lb01 scripts]# sh adlinuxopt.sh 在执行此脚本之前需要先执行 initialization.sh 等待5s确认若没执行请 ctrl+c 退出执行1S2S3S4S5S等待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:1disable ipv6等待3Snet.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0kernel.sysrq = 0kernel.core_uses_pid = 1net.ipv4.tcp_syncookies = 1error: "net.bridge.bridge-nf-call-ip6tables" is an unknown keyerror: "net.bridge.bridge-nf-call-iptables" is an unknown keyerror: "net.bridge.bridge-nf-call-arptables" is an unknown keykernel.msgmnb = 65536kernel.msgmax = 65536kernel.shmmax = 68719476736kernel.shmall = 4294967296vm.swappiness = 1vm.dirty_background_ratio = 5vm.dirty_ratio = 10net.ipv6.conf.all.disable_ipv6 = 1net.core.wmem_default = 256960net.core.rmem_default = 256960net.core.wmem_max = 2097152net.core.rmem_max = 2097152net.ipv4.tcp_wmem = 8760 256960 4088000net.ipv4.tcp_rmem = 8760 256960 4088000等待3S-----------------------------华丽分隔符----------------------------------------#4/socket读写缓冲区调优socket读写缓冲区调优 设置成功或者之前已经设置过了-----------------------------华丽分隔符----------------------------------------#5/预读缓冲调优8192
参考链接为:03搭建cdh 生产环境前的Linux 优化(涉及到Linux内存参数优化)
转载于:https://blog.51cto.com/12445535/2382646