一、变为服务程序——目的让程序变为服务长期后台运行,并在程序意外停止时重启服务。
1.1将程序mytest移到/usr/local/bin目录下
1.2将mytest变为服务程序
vim /etc/systemd/system/mytest.service
[Unit]
Description=mytest service
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/mytest
Restart=on-failure # or always, on-abort, etc
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable mytest
1.3启动|停止|重启|服务|查看状态
service mytest start|stop|restart|status
或
systemctl start|stop|restart|status mytest
二、防火墙开放某个端口——这样外部才能通过此端口连接进来
2.1.查看已开发端口命令:
firewall-cmd --list-all
2.2.新增防火墙开放端口:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
命令含义:
–zone #作用域
–add-port=3306/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
2.3.开放端口后需要重新加载防火墙:
firewall-cmd --reload
2.4.firewalld也作为服务了因此可以使用上面类似操作服务的命令:
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld