配置为系统服务
cent6方法1:service(/etc/init.d/、/etc/rc.d/init.d/)
- cp /usr/local/mysql/support-file/mysql.service /etc/init.d/mysqld
或 自己编写脚本Vim /etc/init.d/kafka
提权:Chmod 755 /etc/init.d/mysqld
使用系统命令管理服务:
Service mysqld start|stop|status|restart|
chkconfig --add ntpd 添加服务让chkconfig得以管理该服务,前提:服务脚本必须放到/etc/init.d/目录下
设置开机自启:chkconfig ntpd on| off | reset
查看服务是否自启:chkconfig --list ntpd chkconfig --del ntpd
cent7方法2:systemctl(/usr/lib/systemd/system/xx.service、/etc/systemd/system/)
- vim /usr/lib/systemd/system/nginx.service 或mysqld.service
Unit:描述、service:服务启动命令、install:服务安装设置
注:service中必须全部是绝对路径
提权:可省
chmod +755 /usr/lib/systemd/system/nginx.service
使用系统命令管理服务:
方法3:/etc/rc.d/rc.local、/etc/rc.local
添加程序启动命令。/etc/rc.d/rc.local中写入的命令,在每次启动系统,用户登录前都会执行一次。echo "/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf" >> /etc/rc.d/rc.local
chmod +x /etc/rc.local
添加到环境变量:
1、软链
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
echo $PATH $PATH含/usr/sbin
2、配置环境变量
vim /etc/profile
添加:export PATH=$PATH:/usr/local/nginx/sbin/
source /etc/profile