目录
- 1-环境准备
- 1-1下载redis-4.0.11.tar.gz
- 1-2gcc环境
- 2-上传解压
- 3-编译安装(需要gcc环境)
- 4-配置redis
- 5-启动Redis
- 6-开启防火墙(root)
- 7-添加开机启动脚本
- 8-设置权限
- 9-设置开机启动
- 10-测试redis服务
- 11-检查是否安装成功
- 12-创建redis命令软连接
- 13-测试redis
- 14-必要时设置防火墙
1-环境准备
1-1下载redis-4.0.11.tar.gz
可从以下路径下载:http://download.redis.io/releases/redis-4.0.11.tar.gz
1-2gcc环境
有网络连接的情况下可通过 yum install gcc来安装最新版本
2-上传解压
进入/usr/local/redis目录下,解压redis安装文件
cd /usr/local/redis
tar ‐xzvf redis‐4.0.11.tar.gz
3-编译安装(需要gcc环境)
cd /usr/local/redis/redis‐4.0.11
make
4-配置redis
在/usr/local/redis/redis‐4.0.11目录下编辑配置文件(允许外网访问)
vi redis.conf
在bind 127.0.0.1前加“#”将其注释掉
默认为保护模式,把 protected‐mode yes 改为 protected‐mode no
默认为不守护进程模式,把daemonize no 改为daemonize yes
将 requirepass foobared前的“#”去掉,修改密码为123456(我为了练习用)
将pidfile修改为/usr/local/redis/redis-4.0.11/redis_6379.pid(参照redis.sh)
5-启动Redis
cd /usr/local/redis/redis‐4.0.11/
./src/redis‐server redis.conf
6-开启防火墙(root)
#开启防火墙的某个端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
#重载防火墙
firewall-cmd --reload
7-添加开机启动脚本
编写启动脚本redis.sh ,加入如下内容:
#!/bin/sh
# chkconfig: 2345 80 90
# description: Start and Stop redis
#PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/redis-4.0.11/src/redis-server
REDIS_CLI=/usr/local/redis/redis-4.0.11/src/redis-cli
PIDFILE=/usr/local/redis/redis-4.0.11/redis_6379.pid
CONF=/usr/local/redis/redis-4.0.11/redis.conf
AUTH="123456"
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
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
8-设置权限
chmod 777 /usr/local/redis/redis.sh
9-设置开机启动
cp redis.sh /etc/init.d/redis
chkconfig ‐‐add redis
chkconfig redis on
10-测试redis服务
service redis start
service redis stop
11-检查是否安装成功
ps ‐ef | grep redis
12-创建redis命令软连接
ln ‐s /usr/local/redis/redis‐4.0.11/src/redis‐cli /usr/bin/redis
13-测试redis
14-必要时设置防火墙
vi /etc/sysconfig/iptables 添加如下内容
‐A INPUT ‐p tcp ‐m state ‐‐state NEW ‐m tcp ‐‐dport 6379 ‐j ACCEPT
启动指令:service iptables start
重启指令:service iptables restart
关闭指令:service iptables stop