沃梦达 / IT编程 / 数据库 / 正文

在阿里云CentOS 6.8上安装Redis

在阿里云CentOS 6.8上安装Redis1、下载redis使用下面的命令下载redis:wget http://download.redis.io/releases/redis-3.2.0.tar.gz2、编译安装tar xzf redis-3.2.0.tar.gzcd redis-3.2.0makemake test但是当...

在阿里云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 PIDFILE];thenecho"PIDFILE ];then echo "PIDFILE];thenecho"desc already running…"
exit 1
fi
echo -n $"Starting $desc: "
daemon BIN/BIN/BIN/prog CONFIGRETVAL=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 progRETVAL=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"instart)start;;stop)stop;;restart)restart;;condrestart)[?e/var/lock/subsys/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 progRETVAL=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