centos7把编译安装的服务通过systemctl管理
nginx编译安装的目录是/usr/local/nginx
nginx配置文件是/usr/local/nginx/conf/nginx.conf
systemctl管理的服务文件在/usr/lib/systemd/system下
进入目录vim nginx.service,写下如下的代码
[Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
先pkill nginx杀死用/usr/local/nginx/sbin/nginx脚本启动的服务
再用systemctl start nginx启动服务
mysql编译安装
目录在/usr/local/mysql 配置文件在/etc/my.cnf
vim mysql.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 #启动服务的用户,主机要有mysql用户 Group=mysql ExecStart=/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf LimitNOFILE = 5000
修改过mysql.service文件需要先执行systemctl daemon-reload
再通过systemctl start mysql启动服务