CentOS 7部署redis 5.0.5

Redis基于内存存储的非关系型数据库,存储速度快,支持主从复制,支持字符串(string)列表(list)集合(set)散列(hash)有序集合(zset) 五种数据类型,

一、数据库安装

1、使用yum安装
[root@test ~]# yum install redis

[root@test ~]# redis-server --version
Redis server v=3.2.12 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=7897e7d0e13773f
[root@test ~]# redis-cli --version              //可以看出使用yum安装的版本都比较旧,下面我们安装最新的5.0.5版本的redis
redis-cli 3.2.12

2、编译安装最新版本redis

[root@test ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz

[root@test ~]# tar -zxvf redis-5.0.5.tar.gz

[root@test ~]# yum install gcc -y       //gcc -v查看,如果没有需要安装

[root@test redis-5.0.5]# make MALLOC=lib

[root@test redis-5.0.5]# cd src && make all

[root@test src]# make install

[root@test src]# ./redis-server

21522:C 17 Jun 2019 15:36:52.038 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21522:C 17 Jun 2019 15:36:52.038 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=21522, just started
21522:C 17 Jun 2019 15:36:52.038 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 21522
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

出现以上界面说明安装成功

[root@test src]# ./redis-cli --version           //查询是安装的最新版本的redis
redis-cli 5.0.5
[root@test src]# ./redis-server --version
Redis server v=5.0.5 sha=00000000:0 malloc=libc bits=64 build=4db47e2324dd3c5

  二、配置启动数据库

1、第一种方法就是安装时候的./redis-server,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。

2、以后台进程方式启动redis

[root@test src]# vim /etc/redis-5.0.5/redis.conf   //默认安装好的配置文件并不在这个目录下,需要找到复制到该目录下

daemonize no 改为 daemonize yes        //以守护进程运行            

[root@test src]# ./redis-server /etc/redis-5.0.5/redis.conf
21845:C 17 Jun 2019 15:44:14.129 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21845:C 17 Jun 2019 15:44:14.129 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=21845, just started
21845:C 17 Jun 2019 15:44:14.129 # Configuration loaded

关闭redis进程
[root@test src]# ps -ef|grep redis
root     21846     1  0 15:44 ?        00:00:00 ./redis-server 127.0.0.1:6379
root     22042  6950  0 15:46 pts/1    00:00:00 grep --color=auto redis

[root@test src]# kill -9 21846

此方法启动关闭较为麻烦,且不能设置开机自启动

  三、设置系统进程启动数据库

先编辑配置文件,然后在把配置文件拷贝到/etc/redis下
[root@test ~]# vim /root/redis-5.0.5/redis.conf 

#bind 127.0.0.1           //将bind 127.0.0.1注释掉,否则数据库只有本机能够使用

daemonize yes          //将no改为yes,使数据库能够以后台守护进程运行

protected-mode no      //把保护模式的yes改为no,否则会阻止远程访问

requirepass redis         //打开注释,设置密码

[root@test ~]# cp /root/redis-5.0.5/redis.conf /etc/redis/

开机自启动,将redis的启动脚本复制一份放到/etc/init.d目录下
[root@test redis]# vim /etc/init.d/redis

CONF="/etc/redis/redis.conf"                  //将conf的变量修改下,否则读不到配置文件

[root@test init.d]# cp /root/redis-5.0.5/utils/redis_init_script /etc/init.d/redis

[root@test ~]# cd /etc/init.d

[root@test init.d]# chkconfig redis on

下面就可以用systemctl管理redis
[root@test ~]# systemctl start redis

[root@test ~]# systemctl status redis
● redis.service - LSB: Redis data structure server
   Loaded: loaded (/etc/rc.d/init.d/redis; bad; vendor preset: disabled)
   Active: active (running) since Mon 2019-06-24 11:10:48 CST; 54s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3184 ExecStop=/etc/rc.d/init.d/redis stop (code=exited, status=0/SUCCESS)
  Process: 3187 ExecStart=/etc/rc.d/init.d/redis start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/redis.service
           └─3189 /usr/local/bin/redis-server *:6379

Jun 24 11:10:48 test systemd[1]: Starting LSB: Redis data structure server...
Jun 24 11:10:48 test redis[3187]: Starting Redis server...
Jun 24 11:10:48 test redis[3187]: 3188:C 24 Jun 2019 11:10:48.203 # oO0OoO0OoO0Oo R...0Oo
Jun 24 11:10:48 test redis[3187]: 3188:C 24 Jun 2019 11:10:48.203 # Redis version=5...ted
Jun 24 11:10:48 test redis[3187]: 3188:C 24 Jun 2019 11:10:48.203 # Configuration loaded
Jun 24 11:10:48 test systemd[1]: Started LSB: Redis data structure server.
Hint: Some lines were ellipsized, use -l to show in full.

  

  

  

posted @ 2019-06-17 15:50  北方莜蓝  阅读(748)  评论(0编辑  收藏  举报