systemctl管理Redis启动、停止、开机启动
2017-03-30 17:01
351 查看
systemctl管理Redis启动、停止、开机启动
1. 创建服务
用service来管理服务的时候,是在/etc/init.d/目录中创建一个脚本文件,来管理服务的启动和停止,在systemctl中,也类似,文件目录有所不同,在
/lib/systemd/system目录下创建一个脚本文件redis.service,里面的内容如下:
[Unit] Description=Redis After=network.target [Service] ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf --daemonize no ExecStop=/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown [Install] WantedBy=multi-user.target
[Unit] 表示这是基础信息
Description 是描述
After 是在那个服务后面启动,一般是网络服务启动后启动
[Service] 表示这里是服务信息
ExecStart 是启动服务的命令
ExecStop 是停止服务的指令
[Install] 表示这是是安装相关信息
WantedBy 是以哪种方式启动:multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行。
更详细的service文件说明请访问:这里
2. 创建软链接
创建软链接是为了下一步系统初始化时自动启动服务ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
创建软链接就好比Windows下的快捷方式
ln -s 是创建软链接
ln -s 原文件 目标文件(快捷方式的决定地址)
如果创建软连接的时候出现异常,不要担心,看看
/etc/systemd/system/multi-user.target.wants/目录是否正常创建软链接为准,有时候报错只是提示一下,其实成功了。
$ ll /etc/systemd/system/multi-user.target.wants/ total 8 drwxr-xr-x 2 root root 4096 Mar 30 15:46 ./ drwxr-xr-x 13 root root 4096 Mar 13 14:18 ../ lrwxrwxrwx 1 root root 31 Nov 23 14:43 redis.service -> /lib/systemd/system/redis.service ...略...
3. 刷新配置
刚刚配置的服务需要让systemctl能识别,就必须刷新配置$ systemctl daemon-reload
如果没有权限可以使用sudo
$ sudo systemctl daemon-reload
4. 启动、重启、停止
启动redis$ systemctl start redis
重启redis
$ systemctl restart redis
停止redis
$ systemctl stop redis
5. 开机自启动
redis服务加入开机启动$ systemctl enable redis
禁止开机启动
$ systemctl disable redis
6. 查看状态
查看状态$ systemctl status redis
相关文章推荐
- systemctl管理Redis启动、停止、开机启动
- 安装redis,systemctl管理Redis启动、停止、开机启动
- 利用systemctl管理Tomcat启动、停止、重启及开机启动详解
- systemctl管理Tomcat启动、停止、重启、开机启动
- CentOS7 安装tomcat为系统服务器 Systemctl管理Tomcat,并设置开机启动
- linux搭建redis服务设置开机自启动 service命令stop、start启动停止服务
- Linux Oracle服务启动&停止脚本与开机自启动
- Ubuntu Linux下安装 Redis 并配置开机启动
- 后台管理ArcGIS Server服务的启动、停止、重启(9.3.1和10)
- 禁用开机时弹出窗口“ 服务控制管理器:在系统启动时至少一个服务或驱动程序产生错误”
- ubuntu 设置 redis 开机启动
- [ubuntu12.04] 服务管理 是否开机启动
- 管理weblogic服务的启动和停止
- ubuntu服务开机启动停止
- Update-rc.d && rc.local管理Ubuntu的开机启动
- Linux Oracle服务启动&停止脚本与开机自启动
- Fedora 17 设置开机自动启动服务使用新的服务管理工具
- [zz]管理Redhat linux开机自启动服务选项
- 开机改用nginx启动,停止apache2的开机启动
- sysv-rc-conf管理Ubuntu server开机启动服务