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