一、操作系统需求及配置

  1 # 1.1、操作系统推荐配置
  2 4C*8G*40G磁盘
  3 
  4 # 1.2、内核参数优化
  5 # 系统参数需要留有swap空间,rabbitmq 启动进程用户打开文件数至少需要5万,yum安装时rabbitmq启动,源码安装时root启动。修改方法如下:
  6 
  7 # CentOS5/6.X
  8 cat /etc/security/limits.conf
  9 
 10 * soft nofile 100000
 11 * hard nofile 100000
 12 * soft nproc 100000
 13 * hard nproc 100000
 14 * soft core 100000
 15 * hard core 100000
 16 # 在CentOS 7 / RHEL 7的系统中,使用Systemd替代了之前的SysV,因此 /etc/security/limits.conf 文件的配置作用域缩小了一些。
 17 
 18 # limits.conf这里的配置,只适用于通过PAM认证登录用户的资源限制,它对systemd的service的资源限制不生效。
 19 # 登录用户的限制,通过 /etc/security/limits.conf 和 limits.d 来配置。
 20 
 21 # CentOS7.X
 22 cat /etc/security/limits.conf
 23 * soft nofile 65536
 24 * hard nofile 65536
 25 
 26 cat /etc/security/limits.d/20-nproc.conf
 27 
 28 * soft nproc unlimited
 29 * hard nproc unlimited
 30 
 31 vi /etc/pam.d/login最后添加禁止调试文件
 32 session required /lib/security/pam_limits.so
 33 
 34 
 35 # systemd service的资源限制配置:
 36 # 需要修改两个配置文件:
 37 - /etc/security/limits.d/20-nproc.conf
 38 - /etc/systemd/system.conf
 39 
 40 # 全局的配置,放在文件 /etc/systemd/system.conf 和 /etc/systemd/user.conf。
 41 # 同时,也会加载两个对应的目录中的所有.conf文件 /etc/systemd/system.conf.d/*.conf 和 /etc/systemd/user.conf.d/*.conf
 42 # 其中,system.conf 是系统实例使用的,user.conf用户实例使用的。一般的sevice,使用system.conf中的配置即可。
 43 # systemd.conf.d/*.conf 中配置会覆盖system.conf。
 44 
 45 cat /etc/systemd/system.conf
 46 
 47 DefaultLimitNOFILE=1024000 #这里需要修改
 48 DefaultLimitNPROC=1024000  #这里也需要修改
 49 
 50 DefaultLimitCORE=infinity
 51 DefaultLimitNOFILE=655360
 52 DefaultLimitNPROC=655360
 53 
 54 sed -i '/^#DefaultLimitNOFILE=/aDefaultLimitNOFILE=655350' /etc/systemd/system.conf 
 55 sed -i '/^#DefaultLimitNPROC=/aDefaultLimitNPROC=655350' /etc/systemd/system.conf
 56 
 57 # 注意:修改了system.conf后,需要重启系统才会生效。
 58 
 59 # 针对单个Service,也可以设置,以nginx为例。
 60 # 编辑 /usr/lib/systemd/system/nginx.service 文件,或者 /usr/lib/systemd/system/nginx.service.d/my-limit.conf 文件,做如下配置:
 61 
 62 [Service]
 63 LimitCORE=infinity
 64 LimitNOFILE=100000
 65 LimitNPROC=100000
 66 
 67 # 查看一个进程的limit设置:cat /proc/YOUR-PID/limits
 68 
 69 # 注意:
 70 # /etc/security/limits.d/20-nproc.conf文件坑过,里面默认设置了非root用户的最大进程数为4096
 71 
 72 
 73 # 内核优化
 74 
 75 vi /etc/sysctl.d/99.sysctl.conf
 76 
 77 #关闭ipv6
 78 net.ipv6.conf.all.disable_ipv6 = 1
 79 net.ipv6.conf.default.disable_ipv6 = 1
 80 
 81 # 避免放大攻击
 82 net.ipv4.icmp_echo_ignore_broadcasts = 1
 83 
 84 # 开启恶意icmp错误消息保护
 85 net.ipv4.icmp_ignore_bogus_error_responses = 1
 86 
 87 #关闭路由转发
 88 net.ipv4.ip_forward = 0
 89 net.ipv4.conf.all.send_redirects = 0
 90 net.ipv4.conf.default.send_redirects = 0
 91 
 92 #开启反向路径过滤
 93 net.ipv4.conf.all.rp_filter = 1
 94 net.ipv4.conf.default.rp_filter = 1
 95 
 96 #处理无源路由的包
 97 net.ipv4.conf.all.accept_source_route = 0
 98 net.ipv4.conf.default.accept_source_route = 0
 99 
100 #关闭sysrq功能
101 kernel.sysrq = 0
102 
103 #core文件名中添加pid作为扩展名
104 kernel.core_uses_pid = 1
105 
106 # 开启SYN洪水攻击保护
107 net.ipv4.tcp_syncookies = 1
108 
109 #修改消息队列长度
110 kernel.msgmnb = 65536
111 kernel.msgmax = 65536
112 
113 #设置最大内存共享段大小bytes
114 kernel.shmmax = 68719476736
115 kernel.shmall = 4294967296
116 
117 #timewait的数量,默认180000
118 net.ipv4.tcp_max_tw_buckets = 6000
119 net.ipv4.tcp_sack = 1
120 net.ipv4.tcp_window_scaling = 1
121 net.ipv4.tcp_rmem = 4096 87380 4194304
122 net.ipv4.tcp_wmem = 4096 16384 4194304
123 net.core.wmem_default = 8388608
124 net.core.rmem_default = 8388608
125 net.core.rmem_max = 16777216
126 net.core.wmem_max = 16777216
127 
128 #每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目
129 net.core.netdev_max_backlog = 262144
130 
131 #限制仅仅是为了防止简单的DoS 攻击
132 net.ipv4.tcp_max_orphans = 3276800
133 
134 #未收到客户端确认信息的连接请求的最大值
135 net.ipv4.tcp_max_syn_backlog = 262144
136 net.ipv4.tcp_timestamps = 0
137 
138 #内核放弃建立连接之前发送SYNACK 包的数量
139 net.ipv4.tcp_synack_retries = 1
140 
141 #内核放弃建立连接之前发送SYN 包的数量
142 net.ipv4.tcp_syn_retries = 2
143 
144 #启用timewait 快速回收
145 net.ipv4.tcp_tw_recycle = 1
146 
147 #开启重用。允许将TIME-WAIT sockets 重新用于新的TCP 连接
148 net.ipv4.tcp_tw_reuse = 1
149 net.ipv4.tcp_mem = 94500000 915000000 927000000
150 net.ipv4.tcp_fin_timeout = 1
151 
152 #当keepalive 起用的时候,TCP 发送keepalive 消息的频度。缺省是2 小时
153 net.ipv4.tcp_keepalive_time = 30
154 
155 #允许系统打开的端口范围
156 net.ipv4.ip_local_port_range = 1024 65000
157 
158 #修改防火墙表大小,默认65536
159 #net.netfilter.nf_conntrack_max=655350
160 #net.netfilter.nf_conntrack_tcp_timeout_established=1200
161 
162 # 确保无人能修改路由表
163 net.ipv4.conf.all.accept_redirects = 0
164 net.ipv4.conf.default.accept_redirects = 0
165 net.ipv4.conf.all.secure_redirects = 0
166 net.ipv4.conf.default.secure_redirects = 0
167 vm.max_map_count=655360
操作系统配置修改

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-01-05
  • 2022-12-23
  • 2021-07-30
  • 2021-11-11
猜你喜欢
  • 2021-11-12
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
相关资源
相似解决方案