Systemd 教程以及碰到的一些问题

参考:

阮一峰:命令篇
阮一峰:实战篇
https://wiki.archlinux.org/index.php/Systemd_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

步骤:
 1. 写/etc/systemd/system/xxxx.service或者/use/lib/systemd/system/xxx.service
 2. systemctl daemon-reload
 3. systemctl enable xxxxxx
 4. systemctl start xxxxxx
 5. systemctl status xxxxxx
我在配置service时碰到的问题:
  1. 有时一个命令可以启动某个服务,但是将这个命令写入service时并没有启动成功
    原因:不知道
    解决:是命令中的引号的问题
  2. 如果修改了/use/lib/systemd/system/xxx.service配置文件,需要重新加载配置文件
    systemctl daemon-reload
  3. 操作系统的原因
    原因:有的操作系统是service【ubuntu】,有的是systemctl 【centos】命令
    解决:
    service是类似于一下形式
#!/bin/bash
case "\$1" in
start)
   ${install_path}/mysqld_exporter -config.my-cnf=${install_path}/.my.cnf > /var/log/mysql_exporter.log 2>&1 &
   echo \$!>/var/run/mysql_exporter.pid
   ;;
stop)
   sudo kill \`cat /var/run/mysql_exporter.pid\`
   sudo rm -f /var/run/mysql_exporter.pid
   ;;
restart)
   \$0 stop
   \$0 start
   ;;
status)
   if [ -e /var/run/mysql_exporter.pid ]; then
      echo mysql_exporter is running, pid=\`cat /var/run/mysql_exporter.pid\`
   else
      echo mysql_exporter is NOT running
      exit 1
   fi
   ;;
*)
   echo "Usage: \$0 {start|stop|status|restart}"
esac

exit 0

systemctl使用类似的形式:

[Unit]
Description=Mysql Exporter
After=network.target
[Service]
ExecStart=${install_path}/mysqld_exporter -config.my-cnf=${install_path}/.my.cnf
[Install]
WantedBy=default.target

Shell脚本安装成服务加入系统启动-service

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值