博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux内核高级优化脚本
阅读量:6227 次
发布时间:2019-06-21

本文共 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

你可能感兴趣的文章
angular state中templateUrl 路径的模板
查看>>
DAX/PowerBI系列 - 关于时间系列 - 如何用脚本生成时间维度 (Generate Date Dimension)
查看>>
记一个 dubbo中hessian2反序列化 Map 的一个问题
查看>>
POJ3461:Oulipo——题解
查看>>
小闪对话:微信长连系统的设计(一)
查看>>
Android Paint和Color类
查看>>
java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
查看>>
hibernate--多对一单向关联 (重点!!!)
查看>>
Leetcode 3 - longest-substring-without-repeating-characters
查看>>
封装HttpClient进行http请求与https请求
查看>>
Oracle EBS-SQL (SYS-15):查询表空间2.sql
查看>>
Single Number | LeetCode OJ 解题报告
查看>>
[android]实现拖动效果
查看>>
SQL2008避免出错(聚合函数+Over用法)
查看>>
C#调用SQL Server分页存储过程
查看>>
Microsoft SQL Server 2017无法连接到WMI提供程序。您没有权限或者该服务器无法访问...问题的解决方法...
查看>>
解决TortoiseGit连接Bonobo Git Server时老是需要“输入用户名与密码”的问题
查看>>
zTree的使用2
查看>>
希尔排序代码实现
查看>>
赫夫曼树及其应用
查看>>