安装前的准备
安装redis之前,首先检查一下自己Linux是否有安装gcc和tcl依赖
安装gcc和tcl:
[root@localhost ~]# yum install -y wget gcc make tcl
安装过程很慢,很慢,很慢,真特么的慢!
- 下载
[root@localhost ~]# wget http://download.redis.io/redis-stable.tar.gz
- 建立一个文件夹
[root@localhost ~]# mkdir /usr/redis
- 解压到建立的文件夹
[root@localhost ~]# tar–zxvf redis-stable.tar.gz /usr/redis
- 进入加压后的redis文件夹
[root@localhost ~]# cd /usr/redis/redis-3.0.2
- 编译并且安装redis
Ps:make test不建议运行,同上,真特么慢,一般不需要测试
[root@localhost ~]# make
[root@localhost ~]# make test
[root@localhost ~]# make install
- 配置redis
拷贝配置文件到etc下
[root@Developer redis-3.0.2]# cp redis.conf /etc/
在启动项中创建新的空文件
[root@Developer redis-3.0.2]# touch /etc/init.d/redis
给上面的空文件赋权
[root@Developer redis-3.0.2]# chmod 755 /etc/init.d/redis
编辑新创建的空文件
[root@Developer redis-3.0.2]# vim /etc/init.d/redis
复制下面文件粘贴即可
#!/bin/bash
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/etc/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
if [ -e $PIDFILE ];then
echo "$desc already running...."
exit 1
fi
echo -n $"Starting $desc: "
daemon $BIN/$prog $CONFIG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stop $desc: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
修改配置文件
[root@Developer redis-3.0.2]# vim /etc/redis.conf
找到下面配置并进行修改
daemonize yes
logfile "/var/log/redis.log"
dir /data
- 运行redis
[root@Developer redis-3.0.2]# /etc/init.d/redis start
- 设置跟随系统启动
[root@Developer redis-3.0.2]# chkconfig redis on
- 尝试存取数值
[root@Developer redis-3.0.2]# redis-cli
127.0.0.1:6379> set testinfo test1234
OK
127.0.0.1:6379> get testinfo
"test1234"
127.0.0.1:6379> quit
网友评论