wget http://download.redis.io/releases/redis-5.0.3.tar.gz tar -zxvf redis-5.0.3.tar.gz -C /usr/local/redis/
安裝 redis 到 /usr/local/redismysql
make PREFIX=/usr/local/redis install 注:若是出現錯誤 一、沒有安裝gcc,這會致使咱們沒法make成功。使用yum安裝: yum -y install gcc 二、jemalloc重載了Linux下的ANSI C的malloc和free函數。解決辦法:make時添加參數。 make MALLOC=libc
/usr/local/redis/bin/redis-server
這樣啓動的 redis 是默認形式,只能在前臺運行,關閉命令窗口就會結束 redis。redis
如今須要把 redis 改爲能夠在後臺運進sql
複製一份redis 配置文件 redis.conf 到 /usr/local/redis/bin/shell
cp redis.conf /usr/local/redis/bin/
將redis改成以守護進程方式運行vim
修改 redis 配置文件 cd /usr/local/redis/bin/ vim redis.conf 查找daemonize no 改成以守護進程方式運行 daemonize yes
啓動 redis 並指定配置文件ide
./redis-server redis.conf
開啓客戶端函數
./redis-cli
將redis_init_script拷貝到/etc/init.d目錄下並重命名爲 redisspa
cp /usr/local/redis/utils/redis_init_script /etc/init.d/redis cd /etc/init.d [root init.d]#ls bcm-agent functions hosteye mysqld netconsole network README redis 查看一下 redis 這個文件 [root init.d]# cat 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="/etc/redis/${REDISPORT}.conf" 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 -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
這個 shell 腳本中這五個參數十分重要 REDISPORT=6379 //redis的端口號 EXEC=/usr/local/bin/redis-server //redis服務位置 CLIEXEC=/usr/local/bin/redis-cli //redis 客戶位置 PIDFILE=/var/run/redis_${REDISPORT}.pid //這個文件是 redis 啓動後自動生成的,可用於檢測 redis 是否啓動。不能修改server
CONF="/etc/redis/${REDISPORT}.conf" //redis 配置文件位置進程
對比個人配置能夠看出 EXEC、CLIEXEC 和 CONF 這三個參數要修改: EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/redis/bin/redis-cli CONF=/usr/local/redis/bin/redis.conf
vim 修改並保存
[root init.d]# chkconfig --add redis [root init.d]# chkconfig bcm-agent 0:關 1:關 2:開 3:開 4:開 5:開 6:關 hosteye 0:關 1:關 2:開 3:開 4:開 5:開 6:關 mysqld 0:關 1:關 2:開 3:開 4:開 5:開 6:關 netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關 network 0:關 1:關 2:開 3:開 4:開 5:開 6:關 redis 0:關 1:關 2:開 3:開 4:開 5:開 6:關 重啓 Linux [root init.d]# reboot
查看 redis-server 進程是否存在 [root ~]# ps -ef | grep redis root 1068 1 0 15:42 ? 00:00:01 /usr/local/redis/bin/redis-server 127.0.0.1:6379 root 6770 6485 0 15:58 pts/0 00:00:00 grep --color=auto redis 關閉 redis 服務 [root ~]# service redis stop Stopping ... Redis stopped [root ~]# ps -ef | grep redis root 10114 6485 0 16:01 pts/0 00:00:00 grep --color=auto redis [root ~]#