以mariadb为例介绍如何使用systemctl命令集设置服务开机自启动

以mariadb为例介绍如何使用systemctl命令集设置服务开机自启动

一、systemd简介

systemd即为system daemon,是linux下的一种init软件,由Lennart Poettering带头开发,并在LGPL 2.1及其后续版本许可证下开源发布,开发目标是提供更优秀的框架以表示系统服务间的依赖关系,并依此实现系统初始化时服务的并行启动,同时达到降低Shell的系统开销的效果,最终代替常用的System V与BSD风格init程序。

Systemd用于Linux管理后台服务。通过配置service file可以达到开机自动启动某个服务的目的。通过systemctl等命令集可以控制某个服务是否自启动,也可以对其手动启动或停止。本文简单说明如何实现自启动,并介绍一些基本命令。

二、systemctl命令集常用命令

  1. 查看服务状态
systemctl status xxx.service
  1. 使能服务自启动
systemctl enable xxx.service  # 重启后生效
  1. 取消服务自启动
systemctl disable xxx.service  # 重启后生效
  1. 手动启动服务
systemctl start xxx.service
  1. 手动停止服务
systemctl stop xxx.service

三、以mariadb自启动为例

这里以Mariadb服务器为例,在redhat7系统上安装完毕mariadb后,希望能配置其为开机自启动。

这里我没有切换到root用户下执行,是用我自己的用户进行操作的。

查看mariadb的服务状态, 可以看到它是disable的。

[hubing@192 ~]$ systemctl status mariadb.service

使能mariadb的自启动后,再次查看其状态,可以看到已经变成enable状态

[hubing@192 ~]$ systemctl enabled mariadb.service

20221224203854

需要重启才会生效,我们重启一下,然后再次查看其状态,可以发现开机重启后,Mariadb的服务已经完成自启动,处于running状态。

20221224204347

四、更多说明

关于如何使用systemctl来管理systemd的Services和Units,可以阅读这篇tutorial:
How To Use Systemctl to Manage Systemd Services and Units

红帽官方文档对于systemd的介绍:
Chapter 10. Managing Services with systemd

猜你喜欢

转载自blog.csdn.net/hubing_hust/article/details/128431693
今日推荐