具体安装步骤我就不说了,网上很多,一搜一大堆。大概步骤如下:
1、下载redis安装文件,解压
2、进入到解压后的文件夹目录:
[root@localhost ~]# cd redis-5.0.5/
3、执行make命令编译:
[root@localhost redis-5.0.5]# make
4、进入src文件夹安装
[root@localhost redis-5.0.5]# cd src/
[root@localhost src]# make install
这里主要记录一下过程中曾经踩到过的几个坑
1.gcc编译失败
新装的系统没有安装gcc,下载安装即可。安装gcc需要的rpm比较多,一个一个找比较麻烦,下面是总的下载链接,有需要的自取。
下载链接:gcc安装包 密码:avf0
下载完传到服务器上,解压,进入文件夹,执行命令:
rpm -Uvh *.rpm --nodeps --force
我这里是强制安装所有的了,当然,你也可以自己一个一个手动安装。
rpm -ivh lib64gmp3-4.3.1-1mdv2010.0.x86_64.rpm
rpm -ivh ppl-0.10.2-11.el6.x86_64.rpm
rpm -ivh cloog-ppl-0.15.7-1.2.el6.x86_64.rpm
rpm -ivh mpfr-2.4.1-6.el6.x86_64.rpm
rpm -ivh cpp-4.4.7-4.el6.x86_64.rpm --force
rpm -ivh kernel-headers-2.6.32-431.el6.x86_64.rpm
rpm -ivh glibc-headers-2.12-1.132.el6.x86_64.rpm --nodeps --force
rpm -ivh glibc-devel-2.12-1.132.el6.x86_64.rpm --force --nodeps
rpm -ivh gcc-4.4.7-4.el6.x86_64.rpm --force --nodeps
rpm -ivh libstdc++-devel-4.4.7-4.el6.x86_64.rpm --force --nodeps
rpm -ivh gcc-c++-4.4.7-4.el6.x86_64.rpm --force --nodep
安装完后执行gcc -v命令查看是否安装成功
[root@localhost gcc_rpm]# gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../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-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
到此,gcc就算安装完了
2、make时可能会报如下错误:
[root@localhost redis-5.0.5]# make
cd src && make all
make[1]: Entering directory `/root/redis-5.0.5/src'
LINK redis-server
cc: ../deps/hiredis/libhiredis.a: No such file or directory
cc: ../deps/lua/src/liblua.a: No such file or directory
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/root/redis-5.0.5/src'
make: *** [all] Error 2
解决办法:
进入redis文件夹,编辑src/.make-settings里的OPT,改为OPT=-O2 -march=x86-64
[root@localhost redis-5.0.5]# cd src/
[root@localhost src]# vi .make-settings
march根据系统不同自行修改,如果不对可能会报错,如果报错了,把march值改一下就行了
error: CPU you selected does not support x86-64 instruction set
3.redis启动成功,但其他机器访问redis失败
到上面为止,redis安装就算成功了,本地启动正常,本地客户端访问正常。这个时候可能会出现另一个问题:其他电脑上访问redis,连接不上?出现这种问题,可以先大概简单排查一下:
1.ping一下是否能ping通,如果ping不通,检查一下原因
2.查看防火墙情况
[root@localhost ~]# sudo systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2019-09-06 04:10:46 EDT; 1 months 3 days ago
Docs: man:firewalld(1)
Process: 4719 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 4719 (code=exited, status=0/SUCCESS)
Sep 06 01:44:31 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 06 01:44:33 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Sep 06 04:10:45 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Sep 06 04:10:46 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
可以看到防火墙已经关闭,说明不是防火墙的原因
3.查看redis.conf配置文件
[root@localhost redis-5.0.5]# vi redis.conf
....
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1
....
好像发现问题了,127.0.0.1只能被本机监听到,其他ip无法访问,改成0.0.0.0即可,注意光注释掉是没用的,它还是会默认127.0.0.1,所以还是要改一下
重新启动redis,ok,连接上了。
ps:其他问题暂时没遇到,欢迎补充