一、安装redis
官网地址: https://redis.io/
Redis中文网:https://www.redis.net.cn/
# 1、在线下载
# wget http://download.redis.io/releases/redis-4.0.8.tar.gz
# 2、解压
# tar xzf redis-4.0.8.tar.gz
# 3、编译
# cd redis-4.0.8
# make
编译可能遇到的问题及解决方法
...
make[3]: gcc: Command not found
...
/bin/sh: cc: command not found
原因:安装redis所需的依赖包缺少
# yum -y install gcc gcc-c++ libstdc++-devel
# make MALLOC=libc
安装成功后测试:make test
[root@localhost redis-4.0.8]# make test
cd src && make test
make[1]: Entering directory `/opt/redis-4.0.8/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/opt/redis-4.0.8/src'
make: *** [test] Error 2
下载 tcl 8.5 以上版本
# wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
# tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
# cd /usr/local/tcl8.6.1/unix/
# ./configure
# make
# make install
然后再次测试:
make test
如下图测试通过
clipboard.png
二、修改配置文件
# 修改配置文件redis.conf,将daemonize no 改成 daemonize yes,让服务在后台启动。
# vim redis.conf
daemonize yes
三、启动redis
# redis-server redis.conf
测试: redis-cli命令进入控制台,ping命令验证连通性,返回pong,说明连接成功。
[root@localhost redis-4.0.8]# redis-cli
127.0.0.1:6379> ping
PONG
退出实例
127.0.0.1:6379> shutdown
not connected> exit
[root@localhost redis-4.0.8]#
四、设置开机自启
vim /etc/rc.local
添加下面的内容:(意思就是开机的时候调用这行命令,启动redis) (目录为安装redis的目录)
/opt/redis-4.0.8/redis-server /opt/redis-4.0.8/redis.conf
五、停止和卸载
停止redis
# pkill redis
卸载redis
# rm -rf /opt/redis-4.0.8/ 删除安装目录
网友评论