[CentOS7]redis设置开机启动,设置密码

简介

上篇文章介绍了如何安装redis,但每次重启服务器之后redis不会自启,这里将介绍如何进行自启设置,以及如何设置redis的密码,进行密码验证登陆。

上篇文章: Centos7安装Redis

步骤

1、设置redis.conf中daemonize为yes,确保后台进行开启。

2、编写开机自启动脚本

vi /etc/init.d/redis

3、将下面脚本添加redis文件中:

#!/bin/bash# chkconfig: 2345 10 90
# description: Start and Stop redis   

PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli   

PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis-5.0.0/redis.conf"
AUTH="1234"  

case "$1" in
        start)
                if [ -f $PIDFILE ]
                then
                        echo "$PIDFILE exists, process is already running or crashed."
                else
                        echo "Starting Redis server..."
                        $EXEC $CONF
                fi
                if [ "$?"="0" ]
                then
                        echo "Redis is running..."
                fi
                ;;
        stop)
                if [ ! -f $PIDFILE ]
                then
                        echo "$PIDFILE exists, process is not running."
                else
                        PID=$(cat $PIDFILE)
                        echo "Stopping..."
                       $REDIS_CLI -p $REDISPORT  SHUTDOWN
                        sleep 2
                       while [ -x $PIDFILE ]
                       do
                                echo "Waiting for Redis to shutdown..."
                               sleep 1
                        done
                        echo "Redis stopped"
                fi
                ;;
        restart|force-reload)
                ${0} stop
                ${0} start
                ;;
        *)
               echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
                exit 1
esac

4、设置权限

chmod 755 /etc/init.d/redis

5、启动测试

/etc/init.d/redis start

6、设置开机自启动

chkconfig redis on

7、重启服务器测试

reboot

8、设置密码

vi /etc/redis/6379.conf

修改为:

requirepass root  #注意行前空格去掉

9、重启redis

b.开启Redis服务操作通过/etc/init.d/redis_6379 start命令,也可通过(service redis_6379 start)
c.关闭Redis服务操作通过/etc/init.d/redis_6379 stop命令,也可通过(service redis_6379 stop)

原文地址:https://www.cnblogs.com/wolf-sun/p/9969028.html

时间: 2024-10-11 10:33:29

[CentOS7]redis设置开机启动,设置密码的相关文章

Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动

Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ©Copyright 蕃薯耀 2017年7月21日 http://www.cnblogs.com/fanshuyao/ Linux Redis安装,Linux如何安

Centos7 redis设置开机自启动

配置redis 1.设置redis.conf中daemonize为yes,requirepass为你的redis密码,bind注释掉禁用本机访问绑定,确保守护进程开启,也就是在后台可以运行. vi /opt/redis/redis.conf 2.复制redis配置文件(启动脚本需要用到配置文件内容,所以要复制) mkdir /etc/redis cp /usr/local/redis/redis.conf /etc/redis/6379.conf 3.设置redis.conf中daemonize

centos7 teamviewer设置开机启动

1.sudo systemctl enable teamviewerd.service 2.sudo systemctl start teamviewerd.service 3.sudo systemctl status teamviewerd.service

CentOS7 安装 Redis 并设置开机启动

阅读目录 1.下载 2.解压 3.编译 4.创建redis目录 5.复制主要配置文件到新文件夹 6.开启后台运行 7.创建redis命令软连接 8.添加开机启动服务 9.设置开机启动 10.检查是否安装成功 11.连接登录 12.永久设置Redis密码 13.临时设置Redis密码 14.登陆有密码的Redis 15.先登陆后验证 16.开启后台运行 回到顶部 1.下载 https://redis.io/download cd /usr/local/src wget -c http://down

centos7安装redis并设置开机启动

1.首先redis安装 tar xzf redis-3.0.0.tar.gz cd redis-3.0.0/makemake install PREFIX=/usr/local/redis 创建存储redis的目录并复制文件 mkdir -p /usr/local/rediscd src/cp ./redis-server /usr/local/redis/cp ./redis-cli /usr/local/redis/cd ..cp redis.conf /usr/local/redis/ 后

CenterOS中安装Redis及开机启动设置

Redis安装 从官方下载最新Redis进行安装,官网地址:http://redis.io/download $ wget http://download.redis.io/releases/redis-3.2.3.tar.gz $ tar xzf redis-3.2.3.tar.gz $ cd redis-3.2.3 $ make $ make install Redis启动 RedisServer /path/to/redis.conf Redis关闭(默认port为6379) RedisC

centos7安装docker并设置开机启动

版本要求:查看内核版本,需大于3.10 [[email protected] ~]# uname -r 3.10.0-327.10.1.el7.x86_64 更新内核:如果是生产机器务必慎重更新内核,避免出现不必要的问题. sudo yum update 安装docker [[email protected] ~]# curl -sSL https://get.docker.com/ | sh + sh -c 'sleep 3; yum -y -q install docker-engine'

centos7设置开机启动命令

1.设置开机启动 systemctl enable xxx.service   如:systemctl enable nginx.service 2.设置禁止开机启动 systemctl disable xxx.service 如:systemctl disable nginx.service 3.查看服务状态信息 systemctl status xxx.service 如:systemctl status nginx.service 4.仅显示活动状态 systemctl is-active

centos7之添加开机启动服务/脚本

一.添加开机启动脚本 #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parall