CentOS7安装Redis教程

一、Redis编译环境

执行sudo yum install gcc-c++,执行过程中有两个地方选择y,不用其余操作。

[root@172 ~]# yum install gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.......

Total download size: 54 M
# 第一处选择
Is this ok [y/d/N]: y
Downloading packages:

.......
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# 第二处选择
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded

.......
Complete!

二、下载源码

  建立目录/home/redis,进入目录执行 
  ` wget http://download.redis.io/releases/redis-3.2.11.tar.gz    `
[root@172 redis]# wget http://download.redis.io/releases/redis-3.2.11.tar.gz
--2017-12-13 06:30:49--  http://download.redis.io/releases/redis-3.2.11.tar.gz
Connecting to ----:----... connected.
Proxy request sent, awaiting response... 200 OK
Length: 1550452 (1.5M) [application/x-gzip]
Saving to: ‘redis-3.2.11.tar.gz’

100%[============================>] 1,550,452   51.7KB/s   in 16s  

2017-12-13 06:31:06 (95.6 KB/s) - ‘redis-3.2.11.tar.gz’ saved [1550452/1550452]

三、编译源码

# 解压源码
tar -xzvf redis-3.2.11.tar.gz 

# 进入Redis源码目录
cd redis-3.2.11/

# 编译Redis(编译完成后,会在src下产生redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-rdb、redis-sentinel共6个可执行的文件)
make MALLOC=libc
--------------------- 

四、安装Redis

# 进入src目录
cd src/

# 执行安装命令
[root@172 src]# make install
Hint: It's a good idea to run 'make test' ;)
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
# 安装tcl8.5(此步可忽略,为执行make test准备)
yum install tcl

# 执行make test(此步可忽略)
[root@172 src]# make test
\o/ All tests passed without errors!

Cleanup: may take some time... OK
--------------------- 

五、Redis自动启动

设置Redis开机自动启动

# 进入Redis的util目录
cd /home/redis/redis-3.2.11/utils

# 执行./install_server.sh(执行过程中全部Enter,使用默认配置,如果想修改,可依次自行修改)
[root@172 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

# 查看Redis进程
[root@172 utils]# ps -ef|grep redis
root     10280     1  0 08:15 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
--------------------- 

六、Redis开启远程访问

# 查找Redis配置(注意不是安装目录下的redis.conf)
# 打开第五步设计的Redis配置,默认为:/etc/redis/6379.conf
# 修改配置文件如下几项,其它保持不变
daemonize yes
#bind 127.0.0.1 (注释,不限制IP)
protected-mode no

# 重启服务
[root@172 redis-3.2.11]# service redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...

# 关闭防火墙(生产禁止直接关闭,应设置对应规则,此处不延伸)
# 停止firewall
systemctl stop firewalld.service

# 禁止firewall开机启动
systemctl disable firewalld.service
--------------------- 

七、远程访问Redis

Redist配置好后可通过客户端和程序进行访问,本人通过Redis Desktop Manager进行访问。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_36151928/article/details/83793833
今日推荐