1、进入local目录:
cd /usr/local
创建redis文件夹:
mkdir redis
2、redis是基于c语言开发的,安装c语言环境:
yum install gcc-c++
然后输入:
y
3、下载redis:
wget http://download.redis.io/releases/redis-3.0.4.tar.gz
4、移动redis压缩包到redis文件夹下:
mv redis-3.0.4.tar.gz /usr/local/redis
5、解压redis安装包:
tar -zxvf redis-3.0.4.tar.gz
6、进入到redis的解压目录,进行编译:
make
7、安装redis:
make PREFIX=/usr/local/redis install
8、进入redis解压目录,把配置文件复制到redis的bin目录下:
cp ./redis.conf /usr/local/redis/bin
9、进入bin目录:
cd /usr/local/redis/bin
“
10、启动服务:
./redis-server redis.conf
11、打开新窗口,启动客户端:
./redis-cli
12、远程访问
修改配置redis.conf文件,如下所示:
# bind 127.0.0.1
protected-mode no
requirepass password
开放端口:
iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT
连接测试:
13、设置redis开机自启动
修改redis.conf文件,执行命令:
vim redis.conf
修改文件的内容为:
daemonize yes
编写启动脚本,执行命令:
vim /etc/init.d/redis
脚本内容为:
#!/bin/bash
#
# chkconfig: 2345 10 90
# description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/bin/redis.conf"
AUTH="1234"
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 exists, process is not running."
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
sleep 2
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
设置redis权限:
chmod 755 /etc/init.d/redis
设置开启启动:
cd /etc/init.d/
chkconfig redis on
版权声明:本文为weixin_43937112原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。