- 配置hosts文件
[root@MYSQL local]# vim /etc/hosts
-----------------------------------------------------------------------------
127.0.0.1 REDISB
192.168.40.8 REDISB
2.编译安装
[root@MYSQL src]# cd /usr/local/src/
[root@MYSQL src]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz
[root@MYSQL src]# tar -zxvf redis-5.0.7.tar.gz
[root@MYSQL src]# cd redis-5.0.7
[root@MYSQL src]# make && make install
#编译源程序
#创建目录存放redis命令和配置文件
[root@localhost redis-5.0.7]# mkdir -p /usr/local/redis/bin
[root@localhost redis-5.0.7]# mkdir -p /usr/local/redis/run
[root@localhost redis-5.0.7]# mkdir -p /usr/local/redis/log
[root@localhost redis-5.0.7]# mkdir -p /usr/local/redis/data/6379
[root@localhost redis-5.0.7]# mkdir -p /usr/local/redis/conf
[root@localhost redis-5.0.7]# chown -R root:root /usr/local/redis
[root@localhost redis-5.0.7]# mv redis.conf /usr/local/redis/conf/redis_6379.conf
[root@localhost redis-5.0.7]# cd /usr/local/redis/conf/
#将 127.0.0.1 替换成 192.168.40.8
[root@localhost redis-5.0.7]# sed -i 's/127.0.0.1/192.168.40.8/g' redis_6379.conf
#编辑redis_6379.conf文件
[root@localhost redis-5.0.7]# vim redis_6379.conf
----------------------------------------------------------------
pidfile /usr/local/redis/run/redis_6379.pid
logfile /usr/local/redis/log/redis_6379.log
dir /usr/local/redis/data/6379
------------------------------------------------------------------
[root@MYSQL src]# cd /usr/local/src/redis-5.0.7/src
[root@localhost src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server redis-sentinel redis-trib.rb /usr/local/redis/bin
- 启动redis服务
[root@localhost ~]# /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis_6379.conf
如上,启动redis服务需要指定配置文件的,后台启动的话需要修改redis.conf文件,daemonize no ---- >daemonize yes。redis服务端默认链接端口是6379,
最好也将IP绑定为本机192.168.40.8。
4.验证是否启动成功
[root@localhost ~]# ps -ef | grep redis
#或者
[root@localhost ~]# netstat -tunpl | grep 6379
客户端连接
[root@localhost ~]# /usr/local/redis/bin/redis-cli -h 192.168.40.8 -p 6379
192.168.40.8:6379> info
# Server
redis_version:4.0.9
redis_git_sha1:00000000
...
- 停止redis服务
[root@localhost ~]# /usr/local/redis/bin/redis-cli shutdown
or
/usr/local/redis/bin/redis-cli -h 192.168.40.8 -p 6379 shutdown
#或者
[root@localhost ~]# pkill redis-server
- 创建开机启动
[root@localhost ~]#vim /etc/init.d/redis_6379
-------------------------------------------------------------------------------------------------------------
#!/bin/sh
#Configurations injected by install_server below....
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/usr/local/redis/run/redis_6379.pid
CONF="/usr/local/redis/conf/redis_6379.conf"
REDISPORT="6379"
REDISIP=192.168.40.8
###############
# SysV Init Information
# chkconfig: 345 58 74
# description: redis_6379 is the redis daemon.
### BEGIN INIT INFO
# Provides: redis_6379
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: start and stop redis_6379
# Description: Redis daemon
### END INIT INFO
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 -h $REDISIP -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
status)
PID=$(cat $PIDFILE)
if [ ! -x /proc/${PID} ]
then
echo 'Redis is not running'
else
echo "Redis is running ($PID)"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Please use start, stop, restart or status as first argument"
;;
esac
-------------------------------------------------------------------------------------------------------------
#修改服务权限:
shell> chmod +x /etc/init.d/redis_6379
#启动redis:
shell> service redis_6379 start
#如果成功启动redis,redis log会有以下记录:
cat /usr/local/redis/log/redis_6379.log
#Stop redis
shell> service redis_6379 stop
#设定服务在开启服务器时自动启动:
shell> chkconfig --add redis_6379
shell> chkconfig redis_6379 on
#如不需要开机启动 则
shell> chkconfig --del redis_6379