centos7安装redis6
1、下载redis6
# 创建安装目录并进入
mkdir /data/env
cd /data/env
# 下载redis
wget https://download.redis.io/releases/redis-6.2.4.tar.gz
2、解压redis-6.2.4.tar.gz
tar xf redis-6.2.4.tar.gz
3、安装redis
# 安装依赖
yum install -y gcc-c++ autoconf automaker
# 创建安装目录
mkdir /data/env/redis
# 进入redis解压目录
cd redis-6.2.4
# 编译
make
# 编译安装
make PREFIX=/data/env/redis/ install
# 复制配置文件
cp redis.conf /data/env/redis/bin/
# 编辑配置文件
vim /data/env/redis/bin/redis.conf
编辑内容如下:
修改 daemonize 属性为 yes
找到bind 127.0.0.1并注释掉
修改 protected-mode 属性值为no
4、启动redis
# 前台启动
./data/env/redis/bin/redis-server
# 后台启动
cd /data/env/redis/bin
./redis-server ./redis.conf
5、停止redis
ps -ef | grep redis
kill pid
6、redis配置密码
在redis.conf文件中,找到requirepass,取消注释,保存并退出
# 连接redis
./redis-cli
# 设置密码
config set requirepass password
7、配置启动文件
复制启动配置文件(在redis安装包内)
cp redis-6.2.4/utils/redis_init_script /etc/init.d/redis
配置文件
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379
EXEC=/data/env/redis/bin/redis-server
CLIEXEC=/data/env/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/data/env/redis/bin/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
使用方式
# 启动
/etc/init.d/redis start
# 停止
/etc/init.d/redis stop
配置开机启动撒
chkconfig --add redis
评论
登录后才能发表评论 登录/注册
0评论