linux让某程序变为服务程序以及防火墙开放某个端口

一、变为服务程序——目的让程序变为服务长期后台运行,并在程序意外停止时重启服务。

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值