redis3.2.11 安装
阅读原文时间:2022年06月28日阅读:1

wget http://download.redis.io/releases/redis-3.2.11.tar.gz

[root@hdp01 src]# tar xf redis-3.2..tar.gz -C /opt/
[root@hdp01 src]# cd /opt/
[root@hdp01 opt]# ll
total
drwxr-xr-x. root root Aug : java
drwxrwxr-x. root root Sep redis-3.2.
[root@hdp01 opt]# cd redis-3.2./
[root@hdp01 redis-3.2.]# make
[root@hdp01 redis-3.2.]# cd /usr/local/
[root@hdp01 local]# pwd
/usr/local
[root@hdp01 local]# mkdir redis
[root@hdp01 local]# cd redis/
[root@hdp01 redis]# mkdir bin
[root@hdp01 redis]# mkdir conf
[root@hdp01 redis]# ls
bin conf
[root@hdp01 redis]# cp /opt/redis-3.2./src/redis* /usr/local/redis/bin/
[root@hdp01 redis]# ll /usr/local/redis/bin/
total
-rw-r--r--. root root Aug : redisassert.h
-rwxr-xr-x. root root Aug : redis-benchmark
-rw-r--r--. root root Aug : redis-benchmark.c
-rw-r--r--. root root Aug : redis-benchmark.o
-rwxr-xr-x. root root Aug : redis-check-aof
-rw-r--r--. root root Aug : redis-check-aof.c
-rw-r--r--. root root Aug : redis-check-aof.o
-rwxr-xr-x. root root Aug : redis-check-rdb
-rw-r--r--. root root Aug : redis-check-rdb.c
-rw-r--r--. root root Aug : redis-check-rdb.o
-rwxr-xr-x. root root Aug : redis-cli
-rw-r--r--. root root Aug : redis-cli.c
-rw-r--r--. root root Aug : redis-cli.o
-rwxr-xr-x. root root Aug : redis-sentinel
-rwxr-xr-x. root root Aug : redis-server
-rwxr-xr-x. root root Aug : redis-trib.rb
[root@hdp01 redis]# cp /opt/redis-3.2./redis.conf /usr/local/redis/conf/mvredis.conf
[root@hdp01 redis]# ls /usr/local/redis/conf/
mvredis.conf
#####删除一些不必要的文件(我们只需要redis的可执行文件)
[root@hdp01 bin]# ls
redisassert.h redis-benchmark.o redis-check-aof.o redis-check-rdb.o redis-cli.o redis-trib.rb
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel
redis-benchmark.c redis-check-aof.c redis-check-rdb.c redis-cli.c redis-server
[root@hdp01 bin]# rm -rf *.o
[root@hdp01 bin]# rm -rf *.c
[root@hdp01 bin]# rm -rf *.h
[root@hdp01 bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb
####修改配置文件
[root@hdp01 conf]# pwd
/usr/local/redis/conf
[root@hdp01 conf]# vi mvredis.conf
daemonize no
修改为:
daemonize yes (后台程序方式运行)

pidfile /var/run/redis_6379.pid
修改为:
pidfile /usr/local/redis/redis_6379.pid
(把pidfile生成到有权限的目录下)

####启动
[root@hdp01 conf]# /usr/local/redis/bin/redis-server /usr/local/redis/conf/mvredis.conf
[root@hdp01 conf]# ps aux|grep redis
root 0.0 0.0 ? Ssl : : /usr/local/redis/bin/redis-server 127.0.0.1:
root 0.0 0.0 pts/ S+ : : grep redis

###备机启动:
[root@hdp02 conf]# /usr/local/redis/bin/redis-server /usr/local/redis/conf/mvredis.conf
[root@hdp02 conf]# ps aux|grep redis
root 0.0 0.0 ? Ssl : : /usr/local/redis/bin/redis-server 127.0.0.1:
root 0.0 0.0 pts/ S+ : : grep redis

环境变量:
vi /etc/profile
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:${REDIS_HOME}/bin

source /etc/profile

redis 启动停止重启脚本:
cat /etc/init.d/redis
#!/bin/sh

#chkconfig:

Simple Redisinit.d script conceived to work on Linux systems

as it doesuse of the /proc filesystem.

#配置redis端口号
REDISPORT=`grep "port" /usr/local/redis/conf/mvredis.conf|grep -v "^#"|awk '{print $2}'`
#配置redis启动命令路径
EXE=/usr/local/redis/bin/redis-server
#配置redis连接命令路径
CLIEXE=/usr/local/redis/bin/redis-cli
#配置redis运行PID路径
PIDFILE=/usr/local/redis/redis_6379.pid
#配置redis的配置文件路径
CONF="/usr/local/redis/conf/mvredis.conf"
#配置redis的连接认证密码
#REDISPASSWORD=

function start () {
if [ -f $PIDFILE ]

    then

            echo "$PIDFILE exists,process is already running or crashed"

    else

            echo "Starting Redisserver..."

            $EXE $CONF &

    fi  

}

function stop () {
if [ ! -f $PIDFILE ]

    then

            echo "$PIDFILE does not exist, process is not running"

    else

            PID=$(cat $PIDFILE)

            echo "Stopping ..."

$CLIEXE -p $REDISPORT -a $REDISPASSWORD shutdown

            $CLIEXE -p $REDISPORT  shutdown

            while \[ -x /proc/${PID} \]

            do

                echo "Waiting forRedis to shutdown ..."

                sleep 

            done

            echo "Redis stopped"

    fi  

}

function restart () {
stop

    sleep 

    start  

}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo -e "\e[31m Please use $0 [start|stop|restart] asfirst argument \e[0m"
;;
esac

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章