一、去官网下载最新稳定版
https://redis.io/
二、打开redis需要的端口
/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT #开启6379端口
/etc/rc.d/init.d/iptables save #保存配置
/etc/rc.d/init.d/iptables restart #重启服务
查看端口是否开放
/etc/init.d/iptables status
三、创建redis相关目录:
mkdir -p /opt/redis #redis安装目录
mkdir -p /opt/redis/redis-3.2.8/pid
mkdir -p /opt/redis/redis-3.2.8/logs #存放日志
mkdir -p /opt/redis/redis-3.2.8/data #存放数据文件
四、安装依赖包
yum install -y gcc-c++ tcl wget
五、解压、编译、安装redis-3.2.5:
tar -zxvf redis-3.2.8.tar.gz
cd /opt/redis/redis-3.2.5/
make
cd src
make test
六、修改配置文件中的参数目录
vim /opt/redis/redis-3.2.8/redis.conf
1、设置服务以后台daemon方式运行:
2、修改pid目录为新目录:
3、修改log目录为新目录:
4、修改数据目录为新目录
5、还有一个是bind=127.0.0.1改成服务器的IP地址。这样后端配置技能测通,如果不改,后端是侧不通的。
七、创建redis服务自启脚本
vim /etc/init.d/redis
#!/bin/sh
#chkconfig: 2345 10 90
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
PATH=/opt/redis/bin:/sbin:/usr/bin:/bin
REDISPORT=6379 # 端口
EXEC=/opt/redis/redis-3.2.8/src/redis-server # 服务程序
CLIEXEC=/opt/redis/redis-3.2.8/src/redis-cli # 命令行程序
PIDFILE=/opt/redis/pid/redis.pid
CONF=“/opt/redis/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
;;
*)
echo "Please use start or stop as first argument"
;;
esac
八、添加redis服务开机启动及权限
chmod a+x /etc/init.d/redis
chkconfig --add /etc/init.d/redis
九、启动redis服务:
service redis start
ps -ef | grep redis
netstat -anptu | grep 6379
十、测试
redis-cli
set key1 hello
get key1
quit
(责任编辑:IT) |