1、下载redis安装包
wget http://download.redis.io/releases/redis-7.2.4.tar.gz
也可以提前下载好然后上传到服务器上
2、解压
我这里是解压到/usr/local文件夹下的
[root@localhost local]# tar -zxvf redis-7.2.4.tar.gz -C /usr/local/
[root@localhost local]# ls
bin etc games include lib lib64 libexec nginx redis-7.2.4 redis-7.2.4.tar.gz sbin share src VMOptimizationTools VMOptimizationTools_2.72.0 VMOptimizationToolsLinuxTemp VMOptimizationToolsVmconfigTemp
[root@localhost local]#
3、查看是否安装过gcc
3.1查看gcc版本
[root@localhost local]# 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.2 没有安装的执行
[root@localhost local]# yum install gcc-c++
4、编译
进入解压后的redis-7.2.4文件夹下 执行make
[root@localhost local]# cd redis-7.2.4
[root@localhost redis-7.2.4]# make
执行结束之后再执行下面命令
[root@localhost redis-7.2.4]# make install PREFIX=/usr/local/redis-7.2.4
这里多了一个关键字 PREFIX= 这个关键字的作用是编译的时候用于指定程序存放的路径,如果不指定默认在编译到/usr/local/bin目录下
5、修改redis.conf文件
[root@localhost redis-7.2.4]# vi redis.conf
设置端口
port 6379
如果是bind 127.0.0.1 只能本服务器访问 也可以改成bind 0.0.0.0表示任意ip可以访 问 按需设定
我这里是注释掉
#bind 127.0.0.1 -::1
daemonize no改为 yes以守护进程方式运行 即以后台运行方式去启动
daemonize yes
设置 密码 按需设定 我这里默认不设置密码
# requirepass foobared
远程保护 yes表示开启 no表示关闭 按需配置
说明 当 bind未指定ip(即注释掉) requirepass未设置密码(即注释掉) protected-mode yes才会生效 否则设置yes或no都无影响 由于bind和requirepass都被我注释掉所以这里我设置为no不然无法远程访问
protected-mode no
6、启动
进入到redis-7.2.4目录下
[root@localhost redis-7.2.4]# ./bin/redis-server redis.conf
查看是否启动成功
[root@localhost redis-7.2.4]# ps -ef|grep redis
root 82907 1 0 17:16 ? 00:00:00 ./bin/redis-server *:6379
root 84008 20843 0 17:16 pts/0 00:00:00 grep --color=auto redis
或者 执行下面命令 判断是否启动成功
[root@localhost redis-7.2.4]# ./bin/redis-cli -p 6379
127.0.0.1:6379>
如果显示和上面一样恭喜你安装启动成功
7、开放端口
[root@localhost redis-7.2.4]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
防火墙重新加载
[root@localhost redis-7.2.4]# firewall-cmd --reload
查看对外开放端口
[root@localhost redis-7.2.4]# firewall-cmd --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports: 8080/tcp 80/tcp 8088/tcp 8081/tcp 8090/tcp 3306/tcp 6379/tcp 22/tcp 8888/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
接下来就可以连接使用了