Centos7 设置redis开机自启

Centos7 设置redis开机自启

标签(空格分隔):Linux

环境

Centos7.1
redis-3.0.6

chkconfig方式

**service和chkconfig命令的功能好像都被阉割了,而且好像已经被systemctl命令取代了**
  1. 找到redis安装包

    1458583-20190923133916120-258585442.jpg

  2. 复制redis_init_script文件到/etc/init.d/

    1458583-20190923134034208-1891034831.jpg

  3. 修改下文件内容

    1458583-20190923134046035-1705087072.jpg


    1458583-20190923134055226-880336241.jpg

  4. 设置可执行权限

    1458583-20190923134103545-2102979320.jpg

  5. 开自启

    1458583-20190923134111385-7280790.jpg

  6. 弃用[提示不能用]

    1458583-20190923134119025-1942766545.jpg

systemctl方式

  1. 新建redis.service服务文件
    vim /usr/lib/systemd/system/redis.service

    1458583-20190923134136850-1965428827.jpg

  2. 修改redis.service文件内容

    1458583-20190923134129196-879516405.jpg

  3. 创建软连接
    ln -s /usr/lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
  4. 刷新systemctl
    systemctl daemon-reload
  5. 设置开机自启动
    systemctl enable redis
    systemctl disable redis
  6. 启动redis
    systemctl start redis
    systemctl stop redis
  7. 重启
    reboot
    7.常用命令
    systemctl 查看正在运行的服务
    systemctl list-units 查看激活的单元
    systemctl --failed 查看运行失败的单元
    systemctl list-unit-files 查看所有已安装服务
    8.配置文件
    Unit]:服务的说明
    Unit]:服务的说明
    Description:描述服务
    After:依赖,当依赖的服务启动之后再启动自定义的服务

    [Service]服务运行参数的设置
    Type=forking|Simple 父进程fork,此方式必须指定PIDFile=,|主进程启动
    ExecStart为服务的具体运行命令
    ExecReload为重启命令
    ExecStop为停止命令
    PrivateTmp=True表示给服务分配独立的临时空间
    注意:启动、重启、停止命令全部要求使用绝对路径

    [Install]服务安装的相关设置,可设置为多用户

转载于:https://www.cnblogs.com/yanweifeng/p/11571871.html

相关文章

linux下开机自启: 在/etc/init.d目录下新建文件elasticsear...
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以...
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用...
ASP.NET Core应用程序发布linux在shell中运行是正常的。可一...
设置时区(CentOS 7) 先执行命令timedatectl status|grep &...
vim /etc/sysconfig/network-scripts/ifcfg-eth0 B...