天翼云Linux(CentOS7.6)安装redis6.0全过程

247 阅读4分钟

天翼云 安装redis6.0

1. 安装GCC

先查看是否安装GCC,我的是4.8.5,所以更新了一下

gcc -v

#如果没有的话安装一个 安装完成之后查看版本,新安装的一般不用更新的
yum install -y gcc 

更新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

#修改环境变量
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile

再次查看GCC版本 在这里插入图片描述

2.下载redis

#我选择下载到/root/opt/app/software/redis目录下
cd /root/opt/app/software/redis
#下载
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
#解压
tar -zxvf redis-6.0.6.tar.gz

在这里插入图片描述

3. 切换到redis目录下,执行编译

cd redis-6.0.6
//进行编译
make

ok 给老子报错,我已经做好解决错误的准备了 首先 这里一般不会报关于gcc的错误,我们上面已经更新版本了;

3.1.错误内容:jemalloc/jemalloc.h: No such file or directory

针对这个错误,我们可以在README.md 文件中看到解释。

---------

Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.

To force compiling against libc malloc, use:

    % make MALLOC=libc

To compile against jemalloc on Mac OS X systems, use:

    % make MALLOC=jemalloc

Verbose build
-------------

解决办法

网上很多办法都是这样解决的,(我用的也是这个,就自己玩玩,没那么较真)

make MALLOC=libc

有的大佬说的是这样

#清理上次编译残留文件,重新编译
make distclean  && make

 网上的解决办法虽然最后也是可以成功安装好 redis ,但是是有一些隐患的,首先我们要知道redis 需要使用内存分配器的, make MALLOC=jemalloc 就是指定内存分配器为 jemalloc ,make MALLOC=libc 就是指定内存分配器为 libc ,这个是有安全隐患的,jemalloc 内存分配器在实践中处理内存碎片是要比libc 好的,而且在README.md 文档也说明到了,jemalloc内存分配器也是包含在源码包里面的,可以在deps 目录下看到 jemalloc 目录。

3.2.报错信息:

在这里插入图片描述 这个报错直接给我干蒙了,网上关于这个装redis报错误解决办法很少, 还有大哥说这个问题的根源还是在于linux内核的头文件没有装好, 不过我这个是买的云服务器应该不会吧

解决办法

CentOS 7执行这个命令,然后就好了.... 不过我不知道这个是因为啥

yum install kernel-headers -y

然后接着make MALLOC=libc

3.3.报错信息

cc: error: ../deps/hiredis/libhiredis.a: No such file or directory
cc: error: ../deps/lua/src/liblua.a: No such file or directory
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/root/opt/app/software/redis/redis-6.0.1.src'
make: *** [all] Error 2

解决办法

进入源码包目录下的deps目录中执行
make lua hiredis linenoise

然后接着make MALLOC=libc

3.4. 报错信息

在这里插入图片描述

解决办法

其实这个问题的解决办法跟第一个有点像吧

sudo make distclean
sudo make

然后接着make MALLOC=libc

3.5.报错信息

[exception]: Executing test client: NOREPLICAS Not enough good slaves to write..NOREPLICAS Not enough good slaves to write.
……
Killing still running Redis server 6339Killing still running Redis server 6386Killing still running Redis server 6319Killing still running Redis server 6346Killing still running Redis server 6374Killing still running Redis server 6391I/O error reading reply
……

解决办法

vim tests/integration/replication-2.tcl

也就是修改redis-6.0.1下面的这个tests下面的文件 在这里插入图片描述 找到after 1000 改为after 10000 然后 make test就ok了

3.6.最后的最后 终于绿了

在这里插入图片描述 我这一生,失败透顶,民国三年等不到一场雨,这一生,等不到一句我爱你 但是我等到它绿了呀 在这里插入图片描述

4 指定安装目录

我是还装在这个目录下面

 make install

5.启动服务

进入src目录下执行

./redis-server 

a在这里插入图片描述 哎 跑得起来,ok,修改redis.conf

5.修改redis.conf

在这里插入图片描述

#修改为no,远程可以访问
protected-mode no
#修改端口号为6379
port 6379
#修改为yes 后台运行
daemonize yes

修改完成后吧这个文件复制到src目录下, 进入src目录下执行

./redis-server 

6.天翼云上放开端口号,保证可以访问到

在这里插入图片描述新建安全组 在这里插入图片描述 配置规则--》快速添加规则--》勾选Redis即可确定 在这里插入图片描述 这些操作完成之后,windows打开cmd 可以通过telnet +ip+端口号去访问一下

#例如
telnet 192.168.0.66 6379

ok 齐活 在这里插入图片描述