(1).BIOS优化,阵列配置

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;">&nbsp;&nbsp; 1.1:关闭CPU节能,因为服务器品牌众多,BIOS设置不相同,主要是关闭CPU节能,如C1,DELLR730,已经智能设置,直接有个[performance](javascript:void(0);)选项,帮你关闭了CPU节能,numa特性</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;">&nbsp;&nbsp;&nbsp;1.2:果服务器是8块硬盘,建议两块做RAID1装系统,剩余6块做RAID10做数据分区,RAID1阵列缓存设置成&nbsp;WriteThrough ,RAID10设置成writeback,将有限阵列卡缓存给RAID10阵列用,如果是8块以上的盘,组建两组RAID10,两组缓存策略都是writeback,一组装系统以及存放顺序IO类型的数据,比如redolog,归档日志,mysql的binlog,一组做数据分区</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;">&nbsp;&nbsp;&nbsp;1.3:使用XFS文件系统,数据分区用XFS文件系统,挂载参数用<span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">defaults,noatime,nodiratime,nobarrier,记住根分区是不能用这个挂载参数,不然你根分区下的目录文件都没有访问时间,修改时间,只能用于数据库文件分区</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;1.4:修改IO调度策略以及关闭numa:vim /etc/grub.conf 在kernel那行最末尾加上<span style="color: rgb(255, 0, 0); background-color: inherit;">elevtor=deadline numa=off</span></span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=af13b3dc-c142-42b7-8ed6-cb7c60608af2 rd_NO_LUKS&nbsp; KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet<span style="background-color: inherit;">&nbsp;</span></span><span style="color: rgb(255, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">elevator=deadline numa=off</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(255, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">要当前生效可以这样设置</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(255, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">cat /sys/block/sda/queue/scheduler<span style="background-color: inherit;">&nbsp;</span>

echo&nbsp;deadline &gt; /sys/block/sda/queue/scheduler</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">&nbsp;</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">(2)操作系统基础优化</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">&nbsp;2.1:关闭selinux,修改资源配置</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">vim /etc/security/limits.conf</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">添加以下这段

&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; soft nofile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 65535

&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; soft nproc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 65535

&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hard nofile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 65535

&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hard nproc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 65535</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">sed -ri &#39;s/SELINUX=enforcing/SELINUX=disabled/g&#39; /etc/selinux/config</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">当前设置selinux 和资源限制,&nbsp;setenforce 0 然后在getenforce 查看是否已经禁用了selinux,设置资源限制,直接ulimit -n 65535,也可以下面这种方式,建议使用下面的方式。</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">就不用去编辑/etc/security/limits.conf这个文件了</span></span>

&nbsp;

[root@localhost ~]# cd /etc/security/limits.d/

[root@localhost limits.d]# pwd

/etc/security/limits.d

[root@CRM-mysql limits.d]# ll

-rw-r--r-- 1 root root 227 8月 24 11:39 90-nproc.conf

[root@localhost limits.d]# cp -rpf 90-nproc.conf 90-nofile.conf<span style="background-color: inherit;">&nbsp;</span>

这是已经编辑好的文件

[root@localhost limits.d]# cat 90-nofile.conf<span style="background-color: inherit;">&nbsp;</span>

# Default limit for number of user&#39;s processes to prevent

# accidental fork bombs.

# See rhbz #432903 for reasoning.

&nbsp;

* soft nofile 65535

* hard nofile 65535

root soft nofile unlimited

[root@localhost limits.d]# cat 90-nproc.conf<span style="background-color: inherit;">&nbsp;</span>

# Default limit for number of user&#39;s processes to prevent

# accidental fork bombs.

# See rhbz #432903 for reasoning.

&nbsp;

* soft nproc 65535

* hard nproc 65535

root soft nproc unlimited

#########su - &nbsp; 一下

[root@localhost limits.d]# su -

####

[root@localhost ~]# ulimit -a

core file size (blocks, -c) 0

data seg size (kbytes, -d) unlimited

scheduling priority (-e) 0

file size (blocks, -f) unlimited

pending signals (-i) 256591

max locked memory (kbytes, -l) 64

max memory size (kbytes, -m) unlimited

open files (-n) 65535

pipe size (512 bytes, -p) 8

POSIX message queues (bytes, -q) 819200

real-time priority (-r) 0

stack size (kbytes, -s) 10240

cpu time (seconds, -t) unlimited

max user processes (-u) 65535

virtual memory (kbytes, -v) unlimited

file locks (-x) unlimited

&nbsp;

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">2.2:关闭不需要的服务,只留下crond,network,rsyslog,sshd&nbsp;,sysstat,udev-post</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">2.3:内核参数调整</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">###########减少swap的使用率

vm.swappiness=5

###########默认值是3797,保证物理内存有足够空闲空间,防止突发性换页

vm.min_free_kbytes=204800

############默认是100,增大这个参数设置了虚拟内存回收directory和i-node缓冲的倾向,这个值越大。越易回收,尽量保留可用内存

vm.vfs_cache_pressure=150

######确保能持续将脏数据刷新到磁盘,避免瞬间I/O写,产生严重等待和设置MySQL中的innodb_max_dirty_pages_pct低一点原理类似</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">###当文件系统缓存脏页数量达到系统内存百分之多少时(如10%)就会触发pdflush/flush/kdmflush等后台回写进程运行,将一定缓存的脏页异步地刷入硬盘;

vm.dirty_background_ratio=10</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">##当文件系统缓存脏页数量达到系统内存百分之多少<span style="color: rgb(17, 17, 17); background-color: inherit;">时(如20%),系统会停止所有的应用层的IO写操作,等待刷完数据后恢复IO。</span></span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">vm.dirty_ratio=20

#######################减少TIME_WAIT,提高TCP效率;

net.ipv4.tcp_tw_recycle=1

net.ipv4.tcp_tw_reuse=1</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">(3)安装jemalloc内存管理器</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">jemalloc内存分配方式与系统默认安装的glic的malloc内存分配方式相比,能提高MySQL的性能,降低了系统CPU和内存资源的利用,关于这方便的压测数据,请参考:http://www.linuxeye.com/Linux/1914.html</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">编译安装很简单,tar xvf jemalloc-3.6.0.tar.bz2 &nbsp;./configure &amp;&amp; make &amp;&amp; make install</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 12px; background-color: inherit;"><span style="color: rgb(0, 0, 0); font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">已方便安装好mysql后使用,使用也很简单在[mysqld_safe] 加上malloc-lib= /usr/local/lib/libjemalloc.so</span></span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">&nbsp;(4)安装异步IO支持</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">为了提高磁盘操作性能,当前的数据库系统都采用异步IO(Asynchronous IO,AIO)的方式来处理磁盘操作。InnoDB存储引擎亦是如此。</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">在InnoDB1.1.x之前,AIO的实现通过InnoDB存储引擎中的代码来模拟实现。而从InnoDB 1.1.x开始(InnoDB Plugin不支持),</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">提供了内核级别AIO的支持,称为Native AIO。因此在编译或者运行该版本MySQL时,需要libaio库的支持,centos最小化安装默认是没有安装的,安装也简单:</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">yum install libaio-devel</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">(5)网卡绑定软中断</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">网卡软中断不平衡,集中在一个CPU核心上(mpstat 查看%soft集中,通常是cpu0),绑定软中断多个核心上,可以用两个脚本来绑定。自己喜欢用哪个都行</span>

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">vim&nbsp;set_irq_affinity.py。</span>

&nbsp;

#!/usr/bin/env python<span style="background-color: inherit;">&nbsp;</span>

import re<span style="background-color: inherit;">&nbsp;</span>

from os import system,popen<span style="background-color: inherit;">&nbsp;</span>

from os import walk as walkdir<span style="background-color: inherit;">&nbsp;</span>

from optparse import OptionParser<span style="background-color: inherit;">&nbsp;</span>

RPS_CPUS_VALUE = &#39;ffffffff&#39;<span style="background-color: inherit;">&nbsp;</span>

RPS_FLOW_VALUE = &#39;4096&#39;<span style="background-color: inherit;">&nbsp;</span>

RPS_RFS_DEFAULT = &#39;0&#39;<span style="background-color: inherit;">&nbsp;</span>

interrupts_file = &#39;/proc/interrupts&#39;<span style="background-color: inherit;">&nbsp;</span>

rps_cpus_list = []<span style="background-color: inherit;">&nbsp;</span>

rps_flow_list = []<span style="background-color: inherit;">&nbsp;</span>

#ENTRY_VALUE=32768<span style="background-color: inherit;">&nbsp;</span>

def get_device():<span style="background-color: inherit;">&nbsp;</span>

return re.findall(r&#39;([a-z]+\d+)\s+Link.*&#39;,popen(&#39;ifconfig&#39;).read())<span style="background-color: inherit;">&nbsp;</span>

def get_rfs_rps_file(net_device):<span style="background-color: inherit;">&nbsp;</span>

rps_path = &#39;/sys/class/net/&#39; + net_device + &#39;/queues/&#39;<span style="background-color: inherit;">&nbsp;</span>

for s in walkdir(rps_path):<span style="background-color: inherit;">&nbsp;</span>

if len(s[2]) == 2:<span style="background-color: inherit;">&nbsp;</span>

rps_cpus_list.append(&#39;/&#39;.join([s[0],s[2][0]]))<span style="background-color: inherit;">&nbsp;</span>

rps_flow_list.append(&#39;/&#39;.join([s[0],s[2][1]]))<span style="background-color: inherit;">&nbsp;</span>

def file_hander(TARGET,VALUE=&#39;0&#39;):<span style="background-color: inherit;">&nbsp;</span>

try:<span style="background-color: inherit;">&nbsp;</span>

f_hander = open(TARGET,&#39;w&#39;)<span style="background-color: inherit;">&nbsp;</span>

f_hander.write(VALUE)<span style="background-color: inherit;">&nbsp;</span>

finally:<span style="background-color: inherit;">&nbsp;</span>

f_hander.close()<span style="background-color: inherit;">&nbsp;</span>

def set_rfs_rps(net_device):<span style="background-color: inherit;">&nbsp;</span>

get_rfs_rps_file(net_device)<span style="background-color: inherit;">&nbsp;</span>

def set_rps_cpus_value(PATH):<span style="background-color: inherit;">&nbsp;</span>

file_hander(PATH,RPS_CPUS_VALUE)<span style="background-color: inherit;">&nbsp;</span>

def set_rps_flow_value(PATH):<span style="background-color: inherit;">&nbsp;</span>

file_hander(PATH,RPS_FLOW_VALUE)<span style="background-color: inherit;">&nbsp;</span>

map(set_rps_cpus_value,rps_cpus_list)<span style="background-color: inherit;">&nbsp;</span>

map(set_rps_flow_value,rps_flow_list)<span style="background-color: inherit;">&nbsp;</span>

def unset_rfs_rps(net_device):<span style="background-color: inherit;">&nbsp;</span>

get_rfs_rps_file(net_device)<span style="background-color: inherit;">&nbsp;</span>

def unset_rps_cpus_value(PATH):<span style="background-color: inherit;">&nbsp;</span>

file_hander(PATH,RPS_RFS_DEFAULT)<span style="background-color: inherit;">&nbsp;</span>

def unset_rps_flow_value(PATH):<span style="background-color: inherit;">&nbsp;</span>

file_hander(PATH,RPS_RFS_DEFAULT)<span style="background-color: inherit;">&nbsp;</span>

map(unset_rps_cpus_value,rps_cpus_list)<span style="background-color: inherit;">&nbsp;</span>

map(unset_rps_flow_value,rps_flow_list)<span style="background-color: inherit;">&nbsp;</span>

def set_irq_balance():<span style="background-color: inherit;">&nbsp;</span>

stop_irq_balance = &#39;service irqbalance stop&#39;<span style="background-color: inherit;">&nbsp;</span>

system(stop_irq_balance)<span style="background-color: inherit;">&nbsp;</span>

interrupts_ct = open(interrupts_file)<span style="background-color: inherit;">&nbsp;</span>

cores_nr = len(interrupts_ct.readline().split()) # 获取CPU核心数<span style="background-color: inherit;">&nbsp;</span>

irq_bit = 0<span style="background-color: inherit;">&nbsp;</span>

while True:<span style="background-color: inherit;">&nbsp;</span>

inter_line = interrupts_ct.readline()<span style="background-color: inherit;">&nbsp;</span>

if inter_line == &quot;&quot;:<span style="background-color: inherit;">&nbsp;</span>

break<span style="background-color: inherit;">&nbsp;</span>

js = inter_line.split()<span style="background-color: inherit;">&nbsp;</span>

if len(js[-1]) &gt; 5:<span style="background-color: inherit;">&nbsp;</span>

if re.match(r&#39;eth.-&#39;,js[-1][:5]):<span style="background-color: inherit;">&nbsp;</span>

irq_nr = js[0][:-1]<span style="background-color: inherit;">&nbsp;</span>

TARGET = &#39;/proc/irq/%s/smp_affinity&#39; %(irq_nr)<span style="background-color: inherit;">&nbsp;</span>

VALUE = str(re.sub(&#39;0x&#39;,&#39;&#39;,hex(1 &lt;&lt; irq_bit))) #1 &lt;&lt; irq_bit 相对于2的N次方 ,hex() 二进制转十六进制<span style="background-color: inherit;">&nbsp;</span>

file_hander(TARGET,VALUE)<span style="background-color: inherit;">&nbsp;</span>

irq_bit += 1<span style="background-color: inherit;">&nbsp;</span>

if irq_bit == cores_nr:<span style="background-color: inherit;">&nbsp;</span>

irq_bit = 0<span style="background-color: inherit;">&nbsp;</span>

def unset_irq_balance():<span style="background-color: inherit;">&nbsp;</span>

start_irq_balance = &#39;service irqbalance start&#39;<span style="background-color: inherit;">&nbsp;</span>

system(start_irq_balance)<span style="background-color: inherit;">&nbsp;</span>

def usage():<span style="background-color: inherit;">&nbsp;</span>

usage = &#39;&#39;&#39;&#39;&#39;=================================================<span style="background-color: inherit;">&nbsp;</span>

Description: irq_balance_set &amp;&amp; rfs_rps_set tools<span style="background-color: inherit;">&nbsp;</span>

Usage:<span style="background-color: inherit;">&nbsp;</span>

&lt;script&gt; -i : set irq smp_affinity<span style="background-color: inherit;">&nbsp;</span>

-I : unset irq smp_affinity<span style="background-color: inherit;">&nbsp;</span>

-r : set rfs &amp;&amp; rps<span style="background-color: inherit;">&nbsp;</span>

-R : unset rfs &amp;&amp; rps<span style="background-color: inherit;">&nbsp;</span>

&#39;&#39;&#39;<span style="background-color: inherit;">&nbsp;</span>

print usage<span style="background-color: inherit;">&nbsp;</span>

if __name__ == &#39;__main__&#39;:<span style="background-color: inherit;">&nbsp;</span>

parser = OptionParser()<span style="background-color: inherit;">&nbsp;</span>

parser.add_option(&quot;-i&quot;, action=&quot;store_true&quot;,<span style="background-color: inherit;">&nbsp;</span>

dest=&quot;irq_true&quot;,<span style="background-color: inherit;">&nbsp;</span>

default=False)<span style="background-color: inherit;">&nbsp;</span>

parser.add_option(&quot;-I&quot;, action=&quot;store_true&quot;,<span style="background-color: inherit;">&nbsp;</span>

dest=&quot;irq_false&quot;,<span style="background-color: inherit;">&nbsp;</span>

default=False)<span style="background-color: inherit;">&nbsp;</span>

parser.add_option(&quot;-r&quot;, action=&quot;store_true&quot;,<span style="background-color: inherit;">&nbsp;</span>

dest=&quot;rps_true&quot;,<span style="background-color: inherit;">&nbsp;</span>

default=False)<span style="background-color: inherit;">&nbsp;</span>

parser.add_option(&quot;-R&quot;, action=&quot;store_true&quot;,<span style="background-color: inherit;">&nbsp;</span>

dest=&quot;rps_false&quot;,<span style="background-color: inherit;">&nbsp;</span>

default=False)<span style="background-color: inherit;">&nbsp;</span>

(options, args) = parser.parse_args()<span style="background-color: inherit;">&nbsp;</span>

if options.irq_true == True:<span style="background-color: inherit;">&nbsp;</span>

set_irq_balance()<span style="background-color: inherit;">&nbsp;</span>

print &quot;irq_balance_set successfully&quot;<span style="background-color: inherit;">&nbsp;</span>

elif options.irq_false == True:<span style="background-color: inherit;">&nbsp;</span>

unset_irq_balance()<span style="background-color: inherit;">&nbsp;</span>

print &quot;unset irq balance successfully&quot;<span style="background-color: inherit;">&nbsp;</span>

elif options.rps_true == True:<span style="background-color: inherit;">&nbsp;</span>

device_list = get_device()<span style="background-color: inherit;">&nbsp;</span>

map(set_rfs_rps,device_list)<span style="background-color: inherit;">&nbsp;</span>

print &quot;rfs&amp;&amp;rps configured successfully&quot;<span style="background-color: inherit;">&nbsp;</span>

elif options.rps_false == True:<span style="background-color: inherit;">&nbsp;</span>

device_list = get_device()<span style="background-color: inherit;">&nbsp;</span>

map(unset_rfs_rps,device_list)<span style="background-color: inherit;">&nbsp;</span>

print &quot;unconfigured rfs&amp;&amp;rps successfully&quot;<span style="background-color: inherit;">&nbsp;</span>

else:<span style="background-color: inherit;">&nbsp;</span>

usage()

&nbsp;

&nbsp;

&nbsp;

<span style="font-family: &quot;Microsoft YaHei&quot;; background-color: inherit;">加入到开机启动中</span>

&nbsp;#!/bin/bash

CORE_SUM=&quot;`grep -c &#39;^processor&#39; /proc/cpuinfo`&quot;

IRQ_SUM=&quot;`echo &quot;1 2 4 8 10 20 40 80 100 200 400 800 1000 2000 4000 8000 10000 20000 40000 80000 100000 200000 400000 800000&quot;| cut -d &quot; &quot; -f -${CORE_SUM}`&quot;

IRQ_NUM=&quot;`echo ${IRQ_SUM}`&quot;

for i in `grep -E &#39;(eth[0-9]+|em[0-9]+)&#39; /proc/interrupts | awk -F &quot;:&quot; &#39;{print $1}&#39; | sed &#39;s/\ //g&#39;`; do

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -e &quot;${i}\t:`cat /proc/irq/${i}/smp_affinity`&quot;

&nbsp;<span style="background-color: inherit;">&nbsp;</span>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y=&quot;`echo ${IRQ_NUM} | awk &#39;{print $1}&#39;`&quot;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo ${y} &gt; /proc/irq/${i}/smp_affinity

#echo &quot;echo ${y} &gt; /proc/irq/${i}/smp_affinity&quot;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ "${y}" == "`echo ${IRQ_SUM} | awk '{print $NF}'`" ]; then

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IRQ_NUM=&quot;`echo ${IRQ_SUM}`&quot;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IRQ_NUM=&quot;`echo ${IRQ_NUM} | sed &#39;s/^\([0-9]\+\)\ \(.*\)/\2/g&#39;`&quot;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi

&nbsp;<span style="background-color: inherit;">&nbsp;</span>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -e &quot;----\t `cat /proc/irq/${i}/smp_affinity`&quot;

done

###### Enable RPS (Receive Packet Steering)

rfc=4096

cc=$(grep -c processor /proc/cpuinfo)

rsfe=$(echo $cc*$rfc | bc)

sysctl -w net.core.rps_sock_flow_entries=$rsfe

for fileRps in $(ls /sys/class/net/eth*/queues/rx-*/rps_cpus)

do

&nbsp;&nbsp;&nbsp; echo fff &gt; $fileRps

done

&nbsp;<span style="background-color: inherit;">&nbsp;</span>

for fileRfc in $(ls /sys/class/net/eth*/queues/rx-*/rps_flow_cnt)

do

&nbsp;&nbsp;&nbsp; echo $rfc &gt; $fileRfc

done

&nbsp;<span style="background-color: inherit;">&nbsp;</span>

tail /sys/class/net/eth*/queues/rx-*/{rps_cpus,rps_flow_cnt}

###

http://www.cnblogs.com/LMySQL/p/4673931.html