CentOS7下安装配置Redis
1.下载上传Redis到服务器
2.安装Redis
1.解压:
tar -zxvf redis-5.0.0.tar.gz
2.安装gcc编译环境
yum install gcc-c++
3.进入redis-5.0.5目录,进行安装
make && make install
3.配置Redis
1.在utils目录下,copy redis_init_script到/etc/init.d。将redis作为开机自启动
cp redis_init_script /etc/init.d
2.创建/usr/local/redis,用于存放配置文件
mkdir /usr/local/redis -p
3.copy redis.conf
cp redis.conf /usr/local/redis/
4.修改redis.conf
#让redis后台运行
daemonize yes
#redis工作目录
dir "/usr/local/redis/working"
#配置可以远程,绑定ip 0.0.0.0
bind 0.0.0.0
#设置密码
requirepass "aaaaaaa"
4.修改redis_init_script 文件中的redis核心配置文件
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/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 -a "wy19970302" -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
5.为redis启动脚本添加执行权限,之后运行
chmod 777 redis_init_script
./redis_init_script start
6.设置开机自启
redis_init_script 中添加以下内容
#chkconfig: 22345 10 90
#description: Srart and Stop redis
保存,进行如下操作
chkconfig redis_init_script on