centos7下开机默认不执行原来配置启动命令的/etc/rc.local文件,建议使用systemctl管理自启动服务,如果要使用/etc/rc.local进行自启动,需要给文件/etc/rc.d/rc.local添加可执行权限。
systemctl常用命令如下:
1.列出所有启动项命令
systemctl list-unit-files
开启的和未开启的。开启的会绿色显示为enabled。
2.使用grep过滤一下开启的grep enabled
systemctl list-unit-files | grep enabled
3.查看某个.service服务的状态信息
systemctl status mysqld.service
4.查看某个服务是否设置开机启动:
systemctl is-enabled mysqld.service
5.启用和禁用服务开机启动:
systemctl enable mysqld.service
systemctl disable mysqld.service
6.启动、停止、重启一个服务:
systemctl start mysqld.service
systemctl stop mysqld.service
systemctl restart mysqld.service
7.查看启动失败的服务列表:
systemctl --failed
将MYSQL8服务加入开机自启动,创建文件/etc/systemd/system/mysqld.service 示例如下:
# cat /etc/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
[Service]
User=mysql
Group=mysql
PIDFile=/run/nginx.pid
#修改成mysql的启动文件及配置文件路径
ExecStart=/opt/mysql8/bin/mysqld --defaults-file=/etc/my.cnf
[Install]
WantedBy=multi-user.target
保存成功后加入开机自启动,并使用reload加载刚刚配置的服务。systemctl enable mysqld
systemctl daemon-reload
使用journalctl查看日志
journalctl -f -u mysqld.service
systemctl也可以支持启动多个mysql实例,只需要在服务命名时进行区分。例如将服务名mysqld.service 可以写成mysql8.0.service 和mysql5.7.service ,并进行相应的启动文件命令修改即可。
- systemctl Centos7 Centos mysql8 mysqlsystemctl centos7 centos mysql8 centos7 centos mysql8 mysql centos7 centos mysql8 linux centos7 centos mysql8问题 centos7方式centos mysql8 大小centos7 centos mysql8 xtrabackup步骤centos7 mysql8 systemctl centos7 centos mysql 密码centos7 centos mysql8 centos7图文centos mysql8