微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

liunx 设置mysql,nginx,redis为开机启动

在/usr/lib/systemd/system/ 或者 /etc/systemd/system/ 目录创建 .service  文件

/lib/systemd/system/与/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

[Install]
WantedBy=multi-user.target

[Service]
User=MysqL
Group=MysqL

Type=forking

PIDFile=/var/run/MysqLd/MysqLd.pid

# disable service start and stop timeout logic of systemd for MysqLd service.
TimeoutSec=0

# Execute pre and post scripts as root
PermissionsstartOnly=true

# Needed to create system tables
ExecStartPre=/usr/bin/MysqLd_pre_systemd

# Start main service
ExecStart=/usr/sbin/MysqLd --daemonize --pid-file=/var/run/MysqLd/MysqLd.pid $MysqLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/MysqL

# Sets open_files_limit
LimitNOFILE = 65536
LimitNPROC = 65536

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

redis.service

[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target

Nginx.service

[Unit]
Description=Nginx - high performance web server
Documentation=http://Nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/Nginx.pid
ExecStart=/usr/sbin/Nginx -c /etc/Nginx/Nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/Nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/Nginx.pid)"

[Install]
WantedBy=multi-user.target
# 开机启动
systemctl enable MysqLd

# 关闭开机启动
systemctl disable MysqLd

设置服务为开机启动

systemctl enable MysqLd
systemctl enable redis
systemctl enable Nginx

查看是否设置成功

sudo systemctl list-unit-files | grep enabled

重启测试

测试MysqL是否启动成功

netstat -na | grep 3306

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐