systemctl
CentOS7以往老版本系统服务的/etc/init.d的启动脚本的方式就此改变,在CentOS7中所有对服务的管理都集中到了systemctl当中。
systemctl是一个系统管理守护进程、工具和库的集合,用于取代以往的System V、service和chkconfig命令。
[root@localhost ~]# touch /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# cd /usr/lib/systemd/system
编辑mysqld.service文件,加入如下内容:
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/sbin/mysqld--defaults-file=/etc/my.cnf
LimitNOFILE = 5000
备注:ExecStart=/usr/sbin/mysqld(此处请对应修改为MySQL程序所在的路径)
查找mysqld路径,例如:
[root@localhost system]# which mysqld
/usr/sbin/mysqld
检查MySQL运行状态:
[root@localhost system]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g …
关闭防火墙:
[root@localhost system]# systemctl stop firewalld.service
[root@localhost system]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removedsymlink/etc/systemd/system/dbusorg.Fedoraproject.FirewallD1.service.
设置mysql的开机启动:
[root@localhost system]#systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
查看服务列表中MySQL服务状态
[root@localhost system]# systemctl list-unit-files | grep mysqld
mysqld.service enabled
取消mysql的开机自启动:
[root@localhost system]# systemctl disable mysqld
Removed symlink /etc/systemd/system/multi-user.target.wants/mysqld.service.
[root@localhost system]# systemctl list-unit-files | grep mysqld
mysqld.service disabled

本文介绍在CentOS7系统中使用systemctl命令管理MySQL服务的方法,包括创建服务文件、设置开机启动、检查服务状态及关闭防火墙等操作。
558

被折叠的 条评论
为什么被折叠?



