centos安装redis——redis集群(一)

下载路径 http://www.redis.cn/download.html

centos安装redis——redis集群(一)_第1张图片

 

解压redis文件

tar -zxvf redis-5.0.5.tar.gz

 

安装gcc依赖

yum install gcc

进入redis

cd redis-5.0.5

 

安装和编译

make && make install

 

闯进redis目录

mkdir /usr/local/redis

把redis.conf 复制到/usr/local/redis 目录下

cp redis.conf /usr/local/redis

把redis脚本复制到

cp redis_init_script /etc/init.d/

添加读写权限

chmod 777 redis_init_script

 

 

vim redis_init_script 编辑脚本

-a 123456  仔细看到这段 这段是redis密码

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

#
#

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/redis.conf" #redis配置文件地址 所在

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
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -a 123456-p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

 

创建备份文件路径

mkdir /usr/local/redis/working

 

在进入redis文件下,编辑redis配置文件 找到以下参数 进行修改
cd /usr/local/redis

vim redis.conf

dir /usr/local/redis/working  #备份路径
daemonize yes    #后台进程启动
bind 0.0.0.0    #所有ip
requirepass 123456 #设置密码

进入

cd /etc/init.d/

然后设置开机自启

chkconfig redis_init_script on

启动redis

./redis_init_script start

 

启动成功

centos安装redis——redis集群(一)_第2张图片

查看进程

ps -ef|grep redis

centos安装redis——redis集群(一)_第3张图片

你可能感兴趣的:(Linux)