1.下载
下载地址
下载稳定版,并传输到服务器解压
2.编译
- 查看gcc版本
gcc -v
- 如果gcc版本低于5,先更新,否则编译会报错
sudo yum install centos-release-scl sudo yum install devtoolset-7-gcc* scl enable devtoolset-7 bash
- 编译
cd redis解压目录 make
3.修改配置文件
- 可能用到的linux命令
# 查看行号 grep -n "查找内容" ./redis.conf |cut -d ":" -f 1
- 开启AOF
# 1.查看该命令在第几行 grep -n "appendonly" ./redis.conf |cut -d ":" -f 1 # 应该在1059行 # 2.编辑配置文件 vi redis.conf # 3.显示行号 :set nu # 4.跳转到1059行 :1059 # 5.修改no 为yes即可
- 设置登录密码
# 1.查找和aof查找相同, 去掉注释 780行 requirepass 你的密码
- 开启守护
# 和前两步一样找到daemonize 并设置为yes即可 222行
4.设置开机自启动
cd /etc/init.d/
vi redis
# 将下列复制进去 -------start-------
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379
# 修改EXEC CLIEXEC CONF即可
EXEC=/usr/local/lib/redis-6.0.6/src/redis-server
CLIEXEC=/usr/local/lib/redis-6.0.6/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/lib/redis-6.0.6/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 ..."
# 如果未设置密码认证, 去掉-a 'password'即可
$CLIEXEC -a 'password' -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
# --------- end -----------
# 打开redis命令
service redis start
# 关闭redis命令
service redis stop
# 设为开机启动
chkconfig redis on
# 设为开机关闭
chkconfig redis off