CentOS7环境下安装Redis

2020-07-14  本文已影响0人  梁朋举

安装Redis

1 下载redis安装包

# wget http://download.redis.io/releases/redis-6.0.0.tar.gz

2 解压压缩包

tar -zxvf redis-4.0.6.tar.gz

# tar -zxvf redis-6.0.0.tar.gz

3.编译安装

如果没有gcc包,需要先安装gcc

# yum -y install gcc
# 编译安装到指定目录下
# make PREFIX=/usr/local/redis install 
或者
# make && make install

# 编译出错时,清出编译生成的文件
make distclean
# 编译安装到指定目录下
make PREFIX=/usr/local/redis install 
# 卸载
make uninstall

4 安装常见问题

server.c:5117:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
     if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
               ^
server.c:5117:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
     if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {

解决方式:升级gcc版本
查看gcc版本是否在5.3以上,centos7.6默认安装4.8.5

gcc -v
# 升级gcc到5.3及以上,如下:
升级到gcc 9.3:
# yum -y install centos-release-scl
# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
[root@qa-11-2 redis-6.0.0]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
[root@qa-11-2 redis-6.0.0]# gcc -v
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
[root@qa-11-2 redis-6.0.0]# source /etc/profile
[root@qa-11-2 redis-6.0.0]# gcc -v
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC) 

配置启动Redis

# 默认是本机访问,注释掉后可以外网访问
bind 127.0.0.1

允许公网访问redis
将 protected-mode yes 改为 protected-mode no

设置远程连接的密码验证
将 requirepass foobared 注释去掉,foobared为密码,也可修改为别的值

#设置后台守护进程运行
daemonize no 改为 yes


指定配置文件启动

//指定配置文件启动
./redis-server /usr/local/redis/redis-6379.conf

关闭redis进程
[root@q]# ps -aux | grep redis
root     23532  0.0  0.0 162320  2524 ?        Ssl  12:38   0:00 ./redis-server *:6379
root     23622  0.0  0.0 112716   964 pts/0    S+   12:39   0:00 grep --color=auto redis
[root@q]# kill -9 23532

上一篇下一篇

猜你喜欢

热点阅读