centos中如何把进程以service自启动

目录

1.linux的服务可以通过systemctl来启动/停止, 一般.service这样的配置文件来实现一个进程包装为服务。

2. .service文件一般放在/usr/lib/systemd/system目录,也可能在/etc/systemd/system目录

3. .service文件定义了一个服务,分为[Unit],[Service],[Install]三个小节, 看看参考

4. 比如我们看下/usr/lib/systemd/system的etcd.service的内容

5. 在/etc/下创建/etc/etcd/, 然后创建配置/etc/etcd/etcd.conf文件

6. 配置etcd开机启动并运行

7. 防火墙打开进程的端口号, 比如打开etcd的2379等

调试和离线文件可参考:https://blog.csdn.net/muzizongheng/article/details/105067876


1.linux的服务可以通过systemctl来启动/停止, 一般.service这样的配置文件来实现一个进程包装为服务。

2. .service文件一般放在/usr/lib/systemd/system目录,也可能在/etc/systemd/system目录

3. .service文件定义了一个服务,分为[Unit],[Service],[Install]三个小节, 看看参考

https://blog.csdn.net/Mr_Yang__/article/details/84133783

 

4. 比如我们看下/usr/lib/systemd/system的etcd.service的内容

[Unit]

Description=Etcd Server

After=network.target

[Service]

Type=simple

WorkingDirectory=/var/lib/etcd/

EnvironmentFile=/etc/etcd/etcd.conf

ExecStart=/usr/local/bin/etcd

[Install]

WantedBy=multi-user.target

 

5. 在/etc/下创建/etc/etcd/, 然后创建配置/etc/etcd/etcd.conf文件

 

ETCD_NAME=etcd server

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"

ETCD_ADVERTISE_CLIENT_URLS="http://10.6.119.106:2379,http://10.6.119.106:4001,http://127.0.0.1:2379,http://127.0.0.1:4001"

 

6. 配置etcd开机启动并运行

systemctl daemon-reload

systemctl enable etcd.service

systemctl start etcd.service

 

7. 防火墙打开进程的端口号, 比如打开etcd的2379等

firewall-cmd --zone=public --add-port=2379/tcp --permanent

firewall-cmd --zone=public --add-port=4001/tcp --permanent

 

调试和离线文件可参考:https://blog.csdn.net/muzizongheng/article/details/105067876

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章