redis3.2.11 安装

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

[root@hdp01 src]# tar xf redis-3.2.11.tar.gz -C /opt/
[root@hdp01 src]# cd /opt/
[root@hdp01 opt]# ll
total 8
drwxr-xr-x. 3 root root 4096 Aug  2 20:13 java
drwxrwxr-x. 6 root root 4096 Sep 21  2017 redis-3.2.11
[root@hdp01 opt]# cd redis-3.2.11/
[root@hdp01 redis-3.2.11]# make 
[root@hdp01 redis-3.2.11]# 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.11/src/redis* /usr/local/redis/bin/
[root@hdp01 redis]# ll /usr/local/redis/bin/
total 34584
-rw-r--r--. 1 root root    2276 Aug  9 14:49 redisassert.h
-rwxr-xr-x. 1 root root 5580551 Aug  9 14:49 redis-benchmark
-rw-r--r--. 1 root root   29559 Aug  9 14:49 redis-benchmark.c
-rw-r--r--. 1 root root   69616 Aug  9 14:49 redis-benchmark.o
-rwxr-xr-x. 1 root root   22177 Aug  9 14:49 redis-check-aof
-rw-r--r--. 1 root root    6328 Aug  9 14:49 redis-check-aof.c
-rw-r--r--. 1 root root   20680 Aug  9 14:49 redis-check-aof.o
-rwxr-xr-x. 1 root root 7833305 Aug  9 14:49 redis-check-rdb
-rw-r--r--. 1 root root   12789 Aug  9 14:49 redis-check-rdb.c
-rw-r--r--. 1 root root   50872 Aug  9 14:49 redis-check-rdb.o
-rwxr-xr-x. 1 root root 5709379 Aug  9 14:49 redis-cli
-rw-r--r--. 1 root root   90678 Aug  9 14:49 redis-cli.c
-rw-r--r--. 1 root root  222624 Aug  9 14:49 redis-cli.o
-rwxr-xr-x. 1 root root 7833305 Aug  9 14:49 redis-sentinel
-rwxr-xr-x. 1 root root 7833305 Aug  9 14:49 redis-server
-rwxr-xr-x. 1 root root   60852 Aug  9 14:49 redis-trib.rb
[root@hdp01 redis]# cp /opt/redis-3.2.11/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      1868  0.0  0.0 133548  7536 ?        Ssl  14:57   0:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379                    
root      1955  0.0  0.0 103328   892 pts/3    S+   14:57   0:00 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     22392  0.0  0.0 133548  7572 ?        Ssl  14:57   0:00 /usr/local/redis/bin/redis-server 127.0.0.1:6380                    
root     22398  0.0  0.0 103328   908 pts/2    S+   14:57   0:00 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:2345 80 90
# 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=123456

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 1

                done

                echo "Redis stopped"

        fi
}

function restart () {
        stop
        
        sleep 3
        
        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

 

posted @ 2019-01-29 09:38  大漠之烟  阅读(796)  评论(0编辑  收藏  举报