在阿里云CentOS 6.8上安装Redis

在阿里云CentOS 6.8上安装Redis

1、下载redis
使用下面的命令下载redis:
wget http://download.redis.io/releases/redis-3.2.0.tar.gz

2、编译安装
tar xzf redis-3.2.0.tar.gz
cd redis-3.2.0
make
make test
但是当执行 make test命令时,出现了错误。
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
原因是没有安装tcl
3、安装tcl
执行下面的命令安装tcl:
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz #
sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
sudo ./configure
sudo make
sudo make install
4、安装完毕之后,接着执行下面的命令:
make test
cd src
make install PREFIX=/usr/local/redis
5、复制配置文件到安装目录下
  cd …/
  mkdir /usr/local/redis/etc
  cp redis.conf /usr/local/redis/etc
6、配置redis为后台启动
  vi /usr/local/redis/etc/redis.conf //将daemonize no 改成daemonize yes
7、新建init启动文件
vim /etc/init.d/redis
内容如下:

#!/bin/sh
#redis Startup script for Redis Server

#chkconfig: - 80 12
#description: Redis is an open source, advanced key-value store.

#processname: redis-server
#config: /etc/redis.conf
#pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/redis.conf"
PIDFILE="/var/run/redis.pid"
###Read configuration
[ -r “KaTeX parse error: Expected 'EOF', got '&' at position 14: SYSCONFIG" ] &̲& source "SYSCONFIG”
RETVAL=0
prog=“redis-server”
desc=“Redis Server”
start() {
if [ -e P I D F I L E ] ; t h e n e c h o " PIDFILE ];then echo " PIDFILE];thenecho"desc already running…"
exit 1
fi
echo -n $"Starting $desc: "
daemon B I N / BIN/ BIN/prog C O N F I G R E T V A L = CONFIG RETVAL= CONFIGRETVAL=?
echo
[ KaTeX parse error: Expected 'EOF', got '&' at position 16: RETVAL -eq 0 ] &̲& touch /var/lo…prog
return $RETVAL
}
stop() {
echo -n $"Stop $desc: "
killproc p r o g R E T V A L = prog RETVAL= progRETVAL=?
echo
[ KaTeX parse error: Expected 'EOF', got '&' at position 16: RETVAL -eq 0 ] &̲& rm -f /var/lo…prog $PIDFILE
return $RETVAL
}
restart() {
stop
start
}
case " 1 " i n s t a r t ) s t a r t ; ; s t o p ) s t o p ; ; r e s t a r t ) r e s t a r t ; ; c o n d r e s t a r t ) [ − e / v a r / l o c k / s u b s y s / 1" in start) start ;; stop) stop ;; restart) restart ;; condrestart) [ -e /var/lock/subsys/ 1"instart)start;;stop)stop;;restart)restart;;condrestart)[e/var/lock/subsys/prog ] && restart
RETVAL=$?
;;
status)
status p r o g R E T V A L = prog RETVAL= progRETVAL=?
;;
*)
echo $“Usage: $0 {start|stop|restart|condrestart|status}”
RETVAL=1
esac
exit $RETVAL

8、修改权限
chmod +x /etc/init.d/redis
修改环境变量,为了便于redis-cli等的执行

9、vim /etc/profile
在/etc/profile文件中添加redis相关命令的执行路径/usr/local/redis/bin:
export PATH=/usr/local/redis/bin:$PATH
然后更新生效
source /etc/profile
10、设定开机启动服务
sudo chkconfig redis on
并查看设置是否生效
chkconfig --list redis
出现了下面的问题:
[root@qingguan redis-3.2.0]# sudo chkconfig redis on
service redis does not support chkconfig
[root@qingguan redis-3.2.0]# chkconfig --list redis
service redis does not support chkconfig
问题解决办法如下:

必须把下面两行注释放在/etc/init.d/redis文件靠前的注释中:

#chkconfig: 2345 90 10
#description: Redis is a persistent key-value database
上面的注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。

11、启动或关闭服务
启动:
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf

验证如下:
ps axuf | grep redis

你可能感兴趣的:(在阿里云CentOS 6.8上安装Redis)