logo  

运维备忘录

运维备忘录
作者: 陈安廉

摘要:软件开发进阶系列


systemd开机启动


2022-08-11 11:36:03





  1. nignx


https://www.cnblogs.com/easonchean/p/14199109.html

[Unit]
Description=nginx service
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=false


如果nginx使用原生方式启动,需要先使用原生指令停止: ./nginx -s stop

如果停止过程遇到: nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

则使用杀死端口方式停止:

ps aux | grep nginx(查看nginx进程运行状态)


killall -9 pid



启动服务:systemctl start xxx.service
关闭服务:systemctl stop xxx.service
重启服务:systemctl restart xxx.service
显示服务的状态:systemctl status xxx.service
在开机时启用服务:systemctl enable xxx.service
在开机时禁用服务:systemctl disable xxx.service
查看服务是否开机启动:systemctl is-enabled xxx.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed


2.mysql


http://www.manongjc.com/detail/28-twdpmcerqzvfaur.html


systemctl is-enabled mysqld.service


mysql安装后一般会自动默认安装systemctl 



3.redis

https://blog.csdn.net/sebeefe/article/details/124167427


[Unit]
Description=Redis Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/opt/redis/redis-7.0.4/bin/redis-server /opt/redis/redis-7.0.4/redis.conf
ExecStop=/opt/redis/redis-7.0.4/bin/redis-cli -p 6389 -a wfb147852 shutdown
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true


systemctl daemon-reload 

systemctl start redis-server.service 

systemctl enable redis-server.service



ln -s /opt/redis/redis-7.0.4/bin/redis-cli /usr/bin/redis-cli


4.zookeeper


http://t.zoukankan.com/javaite-p-8710298.html

[Unit]
Description=ZooKeeper Service
After=network.target
After=syslog.target

[Service]
Environment=ZOO_LOG_DIR=/opt/zk/apache-zookeeper-3.7.1-bin/logs
SyslogIdentifier=zookeeper

Type=forking
ExecStart=/opt/zk/apache-zookeeper-3.7.1-bin/bin/zkServer.sh start /opt/zk/apache-zookeeper-3.7.1-bin/conf/zoo.cfg
ExecStop=/opt/zk/apache-zookeeper-3.7.1-bin/bin/zkServer.sh stop /opt/zk/apache-zookeeper-3.7.1-bin/conf/zoo.cfg
ExecReload=/opt/zk/apache-zookeeper-3.7.1-bin/bin/zkServer.sh restart /opt/zk/apache-zookeeper-3.7.1-bin/conf/zoo.cfg

[Install]
WantedBy=default.target




重新加载配置信息:systemctl daemon-reload
启动zookeeper:systemctl start zookeeper.service
关掉zookeeper:systemctl stop zookeeper.service
查看进程状态及日志:systemctl status zookeeper.service
开机自启动:systemctl enable zookeeper.service
关闭自启动:systemctl disable zookeeper.service