一,源码安装
wget http://download.redis.io/releases/redis-4.0.1.tar.gz
tar xzf redis-4.0.1.tar.gz
cd redis-4.0.1
make
报错:cd src && make all make[1]: Entering directory `/usr/local/src/redis-4.0.1/src' CC Makefile.dep make[1]: Leaving directory `/usr/local/src/redis-4.0.1/src' make[1]: Entering directory `/usr/local/src/redis-4.0.1/src' CC adlist.o /bin/sh: cc: command not found make[1]: *** [adlist.o] 错误 127 make[1]: Leaving directory `/usr/local/src/redis-4.0.1/src' make: *** [all] 错误 2 [root@localhost redis-4.0.1]# 根据提示安装gcc yum -y install gcc gcc-c++ libstdc++-devel 继续make ,还是报错! cc: ../deps/hiredis/libhiredis.a:没有那个文件或目录 cc: ../deps/lua/src/liblua.a:没有那个文件或目录 make[1]: *** [redis-server] 错误 1 make[1]: Leaving directory `/usr/local/src/redis-4.0.1/src' make: *** [all] 错误 2 解决: cd deps make hiredis lua 退出来继续make cd .. make 报错: cc: ../deps/linenoise/linenoise.o:没有那个文件或目录 make[1]: *** [redis-cli] 错误 1 解决: cd deps make linenoise 再次make,成功。
make PREFIX=/usr/local/redis/ install
编辑配置文件:mkdir /usr/local/redis/etc
vi /usr/local/redis/etc/redis.conf
aemonize yes pidfile /usr/local/redis/var/redis.pid port 6379 timeout 300 loglevel debug logfile /usr/local/redis/var/redis.log databases 16 save 900 1 save 300 10 save 60 10000 rdbcompression yes dbfilename dump.rdb dir /usr/local/redis/var/ appendonly no appendfsync always #下面是redis.conf的主 要配置参数的意义: #daemonize:是否以后台daemon方式运行 #pidfile:pid文件位置 #port:监听的端口号 #timeout:请求超时时间 #loglevel:log信息级别 #logfile:log文件位置 #databases:开启数据库的数量 #save * *:保存快照的频率,第一个*表示多长时间,第三个*表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。可设置多个条件。 #rdbcompression:是否使用压缩 #dbfilename:数据快照文件名(只是文件名,不包括目录) #dir:数据快照的保存目录(这个是目录) #appendonly:是否开启appendonlylog,开启的话每次写操作会记一条log,这会提高数据抗风险能力,但影响效率。 #appendfsync:appendonlylog如何同步到磁盘(三个选项,分别是每次写都强制调用fsync、每秒启用一次fsync、不调用fsync等待系统自己同步) ~
useradd redis -s /sbin/nologin
mkdir /usr/local/redis/var
chmod 777 /usr/local/redis/var
vi /etc/init.d/redis
#!/bin/sh # # redis init file for starting up the redis daemon # # chkconfig: - 20 80 # description: Starts and stops the redis daemon. # Source function library. . /etc/rc.d/init.d/functions name="redis-server" basedir="/usr/local/redis" exec="$basedir/bin/$name" pidfile="$basedir/var/redis.pid" REDIS_CONFIG="$basedir/etc/redis.conf" [ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis lockfile=/var/lock/subsys/redis start() { [ -f $REDIS_CONFIG ] || exit 6 [ -x $exec ] || exit 5 echo -n $"Starting $name: " daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG" retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $name: " killproc -p $pidfile $name retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { stop start } reload() { false } rh_status() { status -p $pidfile $name } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 restart ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" exit 2 esac exit $?
chmod 755 /etc/init.d/redis
chkconfig add redis
chkconfig on redis
service redis start