【学习笔记】Redis-搭建 centos7 安装redis 6.0.3

centos7 安装redis 6.0.3

一、简介

centos7 + Redis6.0.3

环境采用VMware16 pro创建centos7虚拟机进行搭建

[root@root bin]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

二、依赖安装

1、gcc依赖安装

[root@root ~]# yum -y install  gcc   gcc-c++ make  tcl  #测试需要依赖tcl

2、redis编译安装需要gcc5.3以上,可以用gcc -v 命令查看当前版本号

[root@root ~]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 

3、使用下面的命令升级到gcc9.3:

[root@root ~]# yum -y install centos-release-scl
[root@root ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@root ~]# scl enable devtoolset-9 bash
[root@root ~]# echo -e "\nsource /opt/rh/devtoolset-9/enable" >>/etc/profile ##长期使用gcc
[root@root ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)   
##可看到版本已升级到9.3

三、redis安装

1、redis这边选用了6.0.3版本,下载连接: http://download.redis.io/releases/redis-6.0.3.tar.gz

2、下载到本地后,通过SFTP工具上传到服务器/usr/local,也可以通过linux直接下载

wget http://download.redis.io/releases/redis-6.0.3.tar.gz
[root@root ~]# cd /usr/local
[root@root local]# ll
总用量 2160
drwxr-xr-x. 2 root root       6 4月  11 2018 bin
drwxr-xr-x. 2 root root       6 4月  11 2018 etc
drwxr-xr-x. 2 root root       6 4月  11 2018 games
drwxr-xr-x. 2 root root       6 4月  11 2018 include
drwxr-xr-x. 2 root root       6 4月  11 2018 lib
drwxr-xr-x. 2 root root       6 4月  11 2018 lib64
drwxr-xr-x. 2 root root       6 4月  11 2018 libexec
-rw-r--r--. 1 root root 2210882 3月  29 15:03 redis-6.0.3.tar.gz
drwxr-xr-x. 2 root root       6 4月  11 2018 sbin
drwxr-xr-x. 5 root root      49 3月  29 14:02 share
drwxr-xr-x. 2 root root       6 4月  11 2018 src

5、编译安装

[root@root ~]# cd /usr/local
[root@root local]# tar xf redis-6.0.3.tar.gz     ##解压
[root@root local]# mv redis-6.0.3 redis     ##重命名
[root@root redis]# cd redis/
[root@root redis]# make   ##编译
......
[root@root redis]#make install #安装,将redis的命令安装到/usr/local/bin/目录

6、如果编译出错先执行make distclean(删除之前生成的编译文件),解决错误后再编译

[root@root redis]# make distclean
[root@root redis]# make

7、编译测试

[root@root redis]# make test
......##一般需要几分钟,执行后可以放着不管它

执行make test错误:You need tcl 8.5 or newer in order to run the Redis test 安装它

[root@root redis]# yum install tcl

编译测试错误:内存不够。因为是虚拟机,只给了1G的内存,增加内存就可以解决,或者多执行几遍make test

!!! WARNING The following tests failed:

*** [err]: pending querybuf: check size of pending_querybuf after set a big value in tests/unit/pendingquerybuf.tcl
the used_memory of replica is much larger than master. Master:43877728 Replica:77432128
Cleanup: may take some time... OK
make[1]: *** [test] 错误 1
make[1]: 离开目录“/usr/local/redis/src”
make: *** [test] 错误 2

编译测试成功
编译成功

四、修改Redis配置

创建日志目录和指定数据目录

[root@root bin]# mkdir /var/log/redis
[root@root bin]# mkdir /usr/local/redis/data

进入到安装的目录/usr/local/redis下 修改redis.conf 配置文件

[root@root redis]# vim redis.conf

1、#daemonize no >> daemonize yes 取消注释,改为yes,开启后台运行,默认是前台运行
2、bind 127.0.0.1 >> #bind 127.0.0.1 把这一行注释,监听所有IP
3、# requirpass >> requirepass redis 取消注释并设置密码
4、dir ./ >> dir /usr/local/redis/data 修改本参数,指定数据目录
5、logfile “” >> logfile /var/log/redis/redis_6379.log 修改本参数,指定日志目录,如果

五、Redis启动

1、脚本启动

[root@root bin]# cd /usr/local/bin
[root@root bin]# ./redis-server /usr/local/redis/redis.conf

2、也可以将redis加入到系统服务中

[root@root redis]# vim /lib/systemd/system/redis.service  ##编写脚本

[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

使用systemctl命令

[root@root bin]# systemctl daemon-reload  ##重载服务
[root@root bin]# systemctl enable redis  ##开机自启
[root@root bin]# systemctl start redis  ##启动
[root@root bin]# systemctl restart redis  ##重启
[root@root bin]# systemctl stop redis  ##停止
[root@root bin]# systemctl status redis  ##查看状态
[root@root bin]# systemctl disable redis  ##关闭开机启动

六、远程连接Redis

1、开放redis对应端口,通常是6379,可以根据个人情况进行配置,而开放端口就需要配置防火墙

[root@root redis]# systemctl status firewalld  #查看防火墙状态
[root@root redis]# service firewalld stop  #关闭防火墙
[root@root redis]# service firewalld start  #开启防火墙
[root@root redis]# firewall-cmd --zone=public --add-port=6379/tcp --permanent  #单独开6379端口
[root@root redis]# firewall-cmd --reload #刷新防火墙

2、由于上面的配置(#bind 127.0.0.1)已经开启了所有IP的监听,因此可以直接连接,比如这边使用RedisDesktopManager进行连接测试
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值