centos 安装 redis
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos 安装 redis相关的知识,希望对你有一定的参考价值。
Centos 安装 redis
redis安装:
1.#下载redies安装包
wget http://download.redis.io/releases/redis-3.2.0.tar.gz tar -xf redis-3.2.0.tar.gz
2.#编译安装 ,如果出现make报错,就是缺少gcc,yum install gcc-c++
cd redis-3.2.0
make
3.#添加相关文件及命令
mkdir /usr/local/redis/bin/ -p
cd src
cp redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server redis-sentinel /usr/local/redis/bin/
cd ..
cp redis.conf /etc/
4.#添加启动脚本
echo ‘#chkconfig: 2345 10 90
#description: Start and Stop redis
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/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
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
‘ > /etc/init.d/redis
添加执行权限:
chmod +x /etc/init.d/redis
5.#设置开机自启动
chkconfig --add redis
chkconfig redis on
6.#创建redis状态日志
mkdir /var/log/redis/
touch /var/log/redis/redis.log
6.设置环境变量:
echo “export PATH=$PATH:/usr/local/redis/bin” >> /root/.bash_profile
source /root/.bash_profile
7.启动服务后台运行:
redis-server /etc/redis.conf &
最后注意要进去/etc/redis.conf配置文件修改你的端口,不然会被黑客利用,成为挖矿肉鸡,这种挖矿木马,主要消耗你的cpu资源
本文出自 “Linux修仙之路” 博客,请务必保留此出处http://8999a.blog.51cto.com/11385098/1964378
以上是关于centos 安装 redis的主要内容,如果未能解决你的问题,请参考以下文章