说明:将源码编译中间件注册成Linux服务一般有两种方法,我这里介绍用脚本注册的方法。
Systemctl 知识简介:
从CentOS7 开始,系统里的网络服务启动已经从传统的service改成了systemctl(一个systemd工具,主要负责控制systemd系统和服务管理器。),管理开机自启动的命令也从chkconfig改为了systemctl,由systemctl一个命令代替了CentOS7以前系统中的service和chkconfig两个命令。
系统服务的脚本也从传统的路径的/etc/init.d(/etc/rc.d/init.d/),改到了/usr/lib/systemd(除此之外还有/etc/systemd/system),需要自启动运行的程序,一般存在这个系统服务目录下,即:/usr/lib/systemd/system目录,每一个服务以“服务名.service”结尾,该文件的内容一般分为3部分:即[Unit]、[Service]和[Install]。
- 安装Redis
- 编辑Redis配置文件(Redis.conf)以我的安装为例
- 进入Redis.conf 目录 cd /usr/app/etc
- 编辑 Redis.conf vim redis.conf 目的是将daemonize 改为yes,允许redis后台 运行
- 编写脚本,添加开机启动服务
vim usr/lib/systemd/system/redis.service(有的是说在/etc/systemd/system/redis.service,最好在usr目录下创建)
- 在redis.service下编写以下内容,注意替换成自己的东西。
3.设置开机自启:[Unit] Description=Redis After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/redis_6379.pid ExecStart=/usr/app/redis/bin/redis-server /usr/app/redis/etc/redis.conf ExecStop=/usr/app/redis/bin/redis-cli shutdown PrivateTmp=true [Install] WantedBy=multi-user.target
-
systemctl daemon-reload (目的是修改完配置,重新加载)
systemctl start redis.service (开启服务)
systemctl stop redis.service (停止服务)
systemctl enable redis-server.service(设置开机自启)