1. 下载Redis源码(tar.gz),并上传到Linux
2. 解压缩包:tar zxvf redis-3.2.1.tar.gz
3. 进入解压缩后的文件夹:cd redis-3.2.1
4. 进入目录,执行make编译[root@test3 redis-3.2.1]# make
编译源码:make
(1)若出现如下提示,则说明未安装gcc,
使用命令安装gcc:yum install gcc
[root@localhost redis-3.2.1]# make
cd src && make all
make[1]: Entering directory `/root/redis-2.8.17/src‘
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/root/redis-2.8.17/src‘
make: *** [all] Error 2
执行[root@test3 src]# yum install gcc
看到Complete!
表示gcc安装成功
(2)若出现如下提示,则将make改为make MALLOC=libc,推测是因为编译库的问题。
[root@localhost redis-3.2.1]# make
cd src && make all
make[1]: Entering directory `/root/redis-2.8.17/src‘
CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-2.8.17/src‘
make: *** [all] Error 2
执行[root@test3 redis-3.2.1]# cd src && make MALLOC=libc
看到Hint: It's a good idea to run 'make test' ;)
表示make成功
注意:make命令执行完成编译后,会在src目录下生成6个可执行文件,分别是
redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-rdb、redis-sentinel。
新版本 redis-check-dump改成redis-check-rdb
5. 安装编译后的文件:make install
安装Redis,执行make install。会将make编译生成的6个可执行文件拷贝到/usr/local/bin目录下;
[root@test3 redis-3.2.1]# make install
cd src && make install
make[1]: Entering directory `/usr/local/redis-3.2.1/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/usr/local/redis-3.2.1/src'
执行./utils/install_server.sh配置Redis配置之后Redis能随系统启动。执行期间会让你选择端口,文件名称等,我都选默认。
[root@test3 redis-3.2.1]# ./utils/install_server.sh
看到
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
表示redis server安装成功。
6,查看开机启动列表
[root@test3 redis-3.2.1]# chkconfig --list
netconsole
0:off 1:off 2:off 3:off 4:off 5:off 6:off
network
0:off 1:off 2:on 3:on 4:on 5:on 6:off
redis_6379
0:off 1:off 2:on 3:on 4:on 5:on 6:off
7,Redis服务查看、开启、关闭
通过ps -ef|grep redis命令查看Redis进程
[root@localhost redis-3.2.1]# ps -ef|grep redis
root 12831 1 0 10:21 ? 00:00:01 /usr/local/bin/redis-server 127.0.0.1:6379
root 13100 4090 0 10:29 pts/0 00:00:00 grep --color=auto redis
8, 关闭Redis服务操作通过/etc/init.d/redis_6379 stop命令,也可通过(service redis_6379 stop)
[root@test3 redis-3.2.1]# service redis_6379 stop
[root@test3 redis-3.2.1]# ps -ef|grep redis
root 12035 10255 0 22:23 pts/0 00:00:00 grep --color=auto redis
9,开启Redis服务操作通过/etc/init.d/redis_6379 start命令,也可通过(service redis_6379 start)
[root@test3 redis-3.2.1]# service redis_6379 start
[root@test3 redis-3.2.1]# ps -ef|grep redis
root 12048 1 0 22:23 ? 00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
root 12052 10255 0 22:23 pts/0 00:00:00 grep --color=auto redis
也可以用redis-server命令启动
# src/redis-server
10、Redis测试
Cli Executable : /usr/local/bin/redis-cli
进入到上面选择的redis-cli的安装目录
[root@test3 /]# cd usr/local/bin
[root@test3 bin]# redis-cli
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> set testkey 2
OK
127.0.0.1:6379> get testkey
"2"
至此以上,表示redis成功安装,可以正常使用。
备注:过程中可能需要做如下准备
1. /etc/redis/6379.conf
注释6379.conf 文件中的:bind 127.0.0.1(在一段文字之前打#号为注释)
改完之后记得一定要重启redis服务
2. /etc/sysconfig/iptables-config
文件末尾加一句:-A INPUT -m state –state NEW -m tcp -p tcp –dport 6379 -j ACCEPT
3. CentOS的6379端口没有开启
原因:由于linux防火墙默认开启,redis的服务端口6379并不在开放规则之内,所有需要将此端口开放访问或者关闭防火墙。
输入systemctl start firewalld.service
输入firewall-cmd --query-port=6379/tcp,如果返回结果为no,那么证明6379端口确实没有开启。
输入firewall-cmd --add-port=6379/tcp,将6379端口开启,返回success。
然后再执行上一条命令,返回yes,证明端口已经成功开启。
Centos7安装redis-3.2.1
猜你喜欢
转载自lanyan-lan.iteye.com/blog/2393832
今日推荐
周排行