Linux环境下redis安装教程
-
下载地址:
http://redis.cn/
-
将下载好的 redis 安装包移动至Linux服务器下的 /opt 目录下;
-
进入 /opt 目录执行命令:
tar -zxvf redis-6.0.6.tar.gz
解压安装包; -
依次执行命令安装环境:
yum install gcc-c++ make make install
如在安装过程中遇到 server.c:5307:31
: 错误:struct redisServer
没有名为server_xxx
的成员 此错误,可参考如下方案解决:
1、安装gcc套装:
yum install cpp
yum install binutils
yum install glibc
yum install glibc-kernheaders
yum install glibc-common
yum install glibc-devel
yum install gcc
yum install make
2、升级gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
3、设置永久升级:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
-
redis 的默认安装路径是
/usr/local/bin
, 执行:cd /usr/local/bin
;进入 bin 目录后创建一个目录用来存放 redis.conf 文件,执行mkdir rconfig
创建目录 rconfig ,进入 rconfig 目录,执行cp /opt/redis-6.0.6/redis.conf redis.conf
,将 /opt/redis-6.0.6 目录下的配置文件 redis.conf 复制存放到新建的 rconfig 目录下,作为 redis 的配置文件 ; -
redis 默认不是后台启动,修改配置文件, 执行下列命令
1. 执行 vi redis.conf
2. 执行 /daemonize (搜索 daemonize 配置),找到下面代码块位置
################################# GENERAL #####################################
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no
将 daemonize 的默认值 no 改为 yes
################################# GENERAL #####################################
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
3.保存并推出
-
启动 redis
执行: cd /usr/local/bin 执行: redis-server rconfig/redis.conf
-
使用 redis-cli 进行连接测试
执行: redis-cli -p 6379 127.0.0.1:6379> ping PONG 127.0.0.1:6379> set aa 111 OK 127.0.0.1:6379> get aa "111"
-
查看 redis 进程是否开启
[root@localhost bin]# ps -ef|grep redis
root 112398 1 0 17:31 ? 00:00:00 redis-server 127.0.0.1:6379
root 112443 110951 0 17:34 pts/1 00:00:00 grep --color=auto redis
- 关闭 redis 服务
127.0.0.1:6379> shutdown
not connected> exit
- 再次查看进程是否存在
[root@localhost bin]# ps -ef|grep redis
root 112489 110951 0 17:39 pts/1 00:00:00 grep --color=auto redis
此处可看到redis进程已被杀死