更多内容请查看博主github wiki主页 https://github.com/LeroiLiu/wiki
1. 下载源码包
你可以使用下面命令安装5.0.3版本,也可以去Redis官网选择需要的版本。
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
2. 解压并进入redis目录
cd /usr/local
tar xzf /root/redis-4.0.1.tar.gz
mv redis-4.0.1 redis
cd redis
3. 编译安装
make && make install
4. 拷贝配置文件
cp redis.conf /etc/
5. 查看参数
redis-server --help
6. 查看版本信息
redis-server -v
7. 启动redis
redis-server /etc/redis.conf
8. 退出关闭
Ctrl+z
9. 设置后台运行
vim /etc/redis.conf
#修改 `daemonize no` 为 `daemonize yes`
10. 设置开机启动脚本/etc/init.d/redis
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379
EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis.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
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
注意修改权限:chmod 777 /etc/init.d/redis
11. 测试开机启动
chkconfig redis on
reboot
[root@localhost ~]# ps aux | grep redis
root 10219 0.0 0.2 50296 9728 ? Ssl 16:30 0:00 /usr/local/redis/src/redis-server 127.0.0.1:6379
root 10336 0.0 0.0 112716 980 pts/0 S+ 16:30 0:00 grep --color=auto redis
12. 基本命令
[root@localhost ~]# service redis start
[root@localhost ~]# service redis restart
[root@localhost ~]# service redis stop
13. 远程访问
在/etc/redis.conf文件中修改:
################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1
bind 0.0.0.0
注意:大约在69行左右,而不是在55行左右出添加:bind 0.0.0.0
找到90行左右修改protected-mode yes
为protected-mode no
。
OK,可以远程访问了。
注意,这是在测试阶段使用,生产环境记得修改。