1、设置句柄数
1)全局分配
sysctl -w fs.file-max=2097152
sysctl -w fs.nr_open=2097152
echo 2097152 > /proc/sys/fs/nr_open
echo "fs.nr_open = 2097152" >> /etc/sysctl.conf
echo "fs.file-max = 2097152" >> /etc/sysctl.conf
sysctl -p
2)服务分配
echo "DefaultLimitNOFILE=1048576" >> /etc/systemd/system.conf
3)用户/进程分配
ulimit -n 1048576
echo "* soft nofile 1048576" >> /etc/security/limits.conf
echo "* hard nofile 1048576" >> /etc/security/limits.conf
2、设置TCP协议栈网络参数
echo "net.core.somaxconn = 32768" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 1000 65535" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog = 16384" >> /etc/sysctl.conf
echo "net.core.netdev_max_backlog=16384" >> /etc/sysctl.conf
echo "net.core.rmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.wmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.rmem_max = 16777216" >> /etc/sysctl.conf
echo "net.core.wmem_max = 16777216" >> /etc/sysctl.conf
echo "net.core.optmem_max = 16777216" >> /etc/sysctl.conf
echo "net.ipv4.tcp_rmem = 1024 4096 16777216" >> /etc/sysctl..conf
echo "net.ipv4.tcp_wmem = 1024 4096 16777216" >> /etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 15" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_tw_buckets = 1048576" >> /etc/sysctl.conf
sysctl -p
3、设置Erlang虚拟机参数
sed -ri 's#node.process_limit = 256000#node.process_limit = 2097152#g' /etc/emqttd/emq.conf
sed -ri 's#node.max_ports = 65536#node.max_ports = 1048576#g' /etc/emqttd/emq.conf
sed -ri 's#listener.tcp.external.acceptors = 16#listener.tcp.external.acceptors = 64#g' /etc/emqttd/emq.conf
sed -ri 's#listener.tcp.external.max_clients = 102400#listener.tcp.external.max_clients = 1000000#g' /etc/emqttd/emq.conf
4、修改EMQ消息服务器参数
sed -ri 's#listener.tcp.external = 127.0.0.1:1883#listener.tcp.external = 0.0.0.0:1883#g' /etc/emqttd/emq.conf
sed -ri 's#listener.tcp.external.acceptors = 16#listener.tcp.external.acceptors = 64#g' /etc/emqttd/emq.conf
sed -ri 's#listener.tcp.external.max_clients = 102400#listener.tcp.external.max_clients = 1000000#g' /etc/emqttd/emq.conf