标签:redis nosql releases linux local start
安装 Redis:
wget http://download.redis.io/releases/redis-2.8.24.tar.gz
tar xf redis-2.8.24.tar.gz
ln -s redis-2.6.14 redis #建立一个链接
cd redis
make PREFIX=/usr/local/redis install #安装到指定目录中
注意上面的最后一行,我们通过PREFIX指定了安装的目录。如果make失败,一般是你们系统中还未安装gcc,那么可以通过yum安装:
yum -y install gcc*
将redis做成一个服务
cp utils/redis_init_script /etc/rc.d/init.d/redis
vim /etc/rc.d/init.d/redis
在#!/bin/bash 下面加入以下代码:
#chkconfig: 2345 80 90
修改
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
在start)函数中修改:
$EXEC $CONF
为:
$EXEC $CONF &
保存退出
创建Redis的配置文件目录:
mkdir /etc/redis
find / -name redis.conf
grep "REDISPORT=" /etc/rc.d/init.d/redis
cp /soft/redis-2.8.24/redis.conf /etc/redis/6379.conf
chkconfig --add redis
将Redis的命令所在目录添加到系统参数PATH中
修改profile文件:
vi /etc/profile
在最后加入:
export PATH=
"$PATH:/usr/local/redis/bin"
启动Redis:
/usr/local/redis/bin/redis-server /etc/redis/6379.conf &
这样就可以直接调用redis-cli的命令了,如下所示:
$ redis-cli
redis 127.0.0.1:6379> auth superman
OK
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379>
至此,redis 就成功安装了。
如果在执行redis-cli中报错:
[root@Redis redis]# redis-cli
127.0.0.1:6379> auth superman
(error) ERR Client sent AUTH, but no password is set
原因是redis没有设置验证口令!
解决方法:
设置Redis密码:
vim /etc/redis/redis.conf
# requirepass foobared
修改为:
requirepass auth密码
将redis写成服务脚本
vim /etc/init.d/redis
#!/bin/sh
#
# Author: Zlyang
# Date : 2016-6-14
#
# chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#REDISPORT=6379
#EXEC=/usr/local/bin/redis-server
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PID=`ps -ef|grep 6379|grep -Ev "grep" |awk ‘{print $2}‘`
PID_NUM=`ps -ef|grep 6379|grep -Ev "grep" |awk ‘{print $2}‘|wc -l`
#PIDFILE=/var/run/redis_${REDISPORT}.pid
#CONF="/etc/redis/${REDISPORT}.conf"
CONF="/etc/redis/redis.conf"
function start()
{
if [ "$PID_NUM" != 0 ]
then
echo "Redis service is already running ..."
else
echo "Starting Redis server..."
$EXEC $CONF 2>&1 > /dev/null &
sleep 1
if [ `ps -ef|grep 6379|grep -Ev "grep" |awk ‘{print $2}‘|wc -l` != 0 ]
then
echo -e "Start Redis service.............................. [\E[1;32m OK \E[0m]"
fi
fi
}
function stop()
{
if [ $PID_NUM == 0 ]
then
echo "Redis service is not running !"
else
echo "Waiting for Redis to stop ..."
kill -9 $PID
sleep 1
echo -e "Stop Redis service............................... [\E[1;32m OK \E[0m]"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
if [ "$PID_NUM" != 0 ]
then
echo "Redis service is already running ..."
else
echo "Redis service is stoped !"
fi
;;
restart)
if [ "$PID_NUM" != 0 ]
then
stop
sleep 1
echo "Starting Redis server..."
$EXEC $CONF 2>&1 > /dev/null &
sleep 1
if [ `ps -ef|grep 6379|grep -Ev "grep" |awk ‘{print $2}‘|wc -l` != 0 ]
then
echo -e "Start Redis service.............................. [\E[1;32m OK \E[0m]"
fi
else
start
fi
;;
*)
echo -e "\E[1;35m Usage: /etc/init.d/redos {start|stop|status|restart|}\E[0m"
;;
esac
保存退出:
将redis添加为服务:
chkconfig --add redis
chkconfig redis on
本文出自 “Elephant” 博客,请务必保留此出处http://zlyang.blog.51cto.com/1196234/1834700
标签:redis nosql releases linux local start
原文地址:http://zlyang.blog.51cto.com/1196234/1834700