Linux配置服务自启动和socket上限
自启动设置
通过ubuntu的serviced将该服务配置为开机自启动,同时通过serviced来控制服务的开启和关闭。
在/etc/systemd/system
文件夹下创建一个文件iccsrest.service,文件中对应的目录需要根据自己的进行更改
1 2 3 4 5 6 7 8 9 10 11 12
| [Unit] Description=iccsrest After=network.target
[Service] Type=simple ExecStart=/home/iccsrest/IccsREST/build/ICCSREST -c /home/iccsrest/IccsREST/config.json -u /home/iccsrest/IccsREST/users.json WorkingDirectory=/home/iccsrest/IccsREST Restart=on-failure
[Install] WantedBy=multi-user.target
|
随后执行下面命令:
1 2 3
| sudo systemctl daemon-reload sudo systemctl enable iccsrest sudo systemctl start iccsrest
|
之后每次开机时该服务就会自动启动并且可以通过systemctl来控制服务的启停
socket上限配置
可以通过这章节的配置增加用户上限,提高服务的性能
修改/etc/security/limits.conf文件,添加以下内容:
1 2
| * soft nofile 65535 * hard nofile 65535
|
修改/etc/sysctl.conf文件,添加以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| net.ipv4.tcp_mem = 786432 2097152 3145728 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 30 net.ipv4.ip_local_port_range = 1024 65535 net.core.rmem_max=16777216 net.core.wmem_max=16777216 net.ipv4.tcp_rmem=4096 87380 16777216 net.ipv4.tcp_wmem=4096 65536 16777216 net.ipv4.tcp_fin_timeout = 10 net.ipv4.tcp_max_tw_buckets=55000 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_window_scaling = 0 net.ipv4.tcp_sack = 0 net.core.netdev_max_backlog = 30000 net.ipv4.tcp_no_metrics_save=1 net.core.somaxconn = 262144 net.ipv4.tcp_syncookies = 0 net.ipv4.tcp_max_orphans = 262144 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = 2 fs.file-max=655350
|
执行以下命令:
1 2
| sudo /sbin/sysctl -p /etc/sysctl.conf sudo /sbin/sysctl -w net.ipv4.route.flush=1
|
再执行以下命令,如果下面命令中的两个对象不存在,请切换到root模式下创建这两个文件并进行更改:
1 2 3
| echo ulimit -HSn 65536 >> /etc/rc.local echo ulimit -HSn 65536 >>/root/.bash_profile ulimit -HSn 65536
|
然后修改/etc/systemd/system.conf和/etc/systemd/user.conf文件,均添加下面两行:
1 2
| DefaultLimitNOFILE=65535 DefaultLimitNPROC=65535
|
随后重启电脑,服务的最大负载可以显著提升。