Centos8安装redis6.0.3

Centos8安装redis6.0.3

  • redis的官网:
    • redis最新版介绍
  • 检查gcc的版本
      • 用dnf命令安装
  • 下载redis6并解压缩
      • 下载
      • 解压缩
  • 安装redis6.0.3
    • 安装redis
    • 生成配置文件
  • 创建供redis运行的目录
  • 修改redis的配置文件
  • 生成供systemd使用的service文件
  • 启动redis:
  • 测试从本地连接访问:
  • 查看已安装redis的版本

redis的官网:

官网:https://redis.io/
下载最新稳定版:https://redis.io/download

redis最新版介绍

  • redis6于5月3日正式发布,它的新增功能:
  • acl
  • 多线程io
  • cluster proxy
  • resp3协议

本文下载 redis-6.0.3.tar.gz

检查gcc的版本

###检查本地有没有安装gcc
gcc --version

[root@localhost ~]# gcc --version
-bash: gcc: command not found

如果提示找不到gcc程序,说明没有安装,

用dnf命令安装

dnf install gcc

[root@localhost ~]# dnf install gcc
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
......
Installed:
  gcc-8.3.1-4.5.el8.x86_64                               annobin-8.78-1.el8.x86_64                        
  cpp-8.3.1-4.5.el8.x86_64                               isl-0.16.1-6.el8.x86_64                          
  libmpc-1.0.2-9.el8.x86_64                              binutils-2.30-58.el8_1.2.x86_64                  
  glibc-devel-2.28-72.el8_1.1.x86_64                     glibc-headers-2.28-72.el8_1.1.x86_64             
  kernel-headers-4.18.0-147.8.1.el8_1.x86_64             libpkgconf-1.4.2-1.el8.x86_64                    
  libxcrypt-devel-4.1.1-4.el8.x86_64                     pkgconf-1.4.2-1.el8.x86_64                       
  pkgconf-m4-1.4.2-1.el8.noarch                          pkgconf-pkg-config-1.4.2-1.el8.x86_64            

Complete!
[root@localhost ~]# gcc --version

说明:gcc版本不宜过低
gcc --version

[root@localhost ~]# gcc --version
gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@localhost ~]# 

下载redis6并解压缩

下载

[root@localhost redis]# wget http://download.redis.io/releases/redis-6.0.3.tar.gz
--2020-05-23 00:47:12--  http://download.redis.io/releases/redis-6.0.3.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2210882 (2.1M) [application/x-gzip]
Saving to: ‘redis-6.0.3.tar.gz’

redis-6.0.3.tar.gz         100%[=======================================>]   2.11M  38.6KB/s    in 95s     

2020-05-23 00:48:47 (22.7 KB/s) - ‘redis-6.0.3.tar.gz’ saved [2210882/2210882]



解压缩

[root@localhost redis]# tar -zxvf redis-6.0.3.tar.gz 
[root@localhost redis]# ll
total 4
drwxrwxr-x 7 root root 4096 May 17 00:11 redis-6.0.3

安装redis6.0.3

安装redis

make PREFIX=/home/work/redis/redis-6.0.3 install
指定安装到/home/work/redis/redis-6.0.3

[root@localhost redis-6]# 
[root@localhost redis-6]# make PREFIX=/home/work/redis/redis-6.0.3 install

[root@localhost bin]# pwd
/home/work/redis/redis-6.0.3/bin
[root@localhost bin]# ll
total 45224
-rwxr-xr-x 1 root root  6318368 May 23 00:57 redis-benchmark
-rwxr-xr-x 1 root root 11123984 May 23 00:57 redis-check-aof
-rwxr-xr-x 1 root root 11123984 May 23 00:57 redis-check-rdb
-rwxr-xr-x 1 root root  6613104 May 23 00:57 redis-cli
lrwxrwxrwx 1 root root       12 May 23 00:57 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 11123984 May 23 00:57 redis-server
[root@localhost bin]# 


生成配置文件

创建安装目录

[root@localhost redis-6.0.3]# mkdir conf

把源码目录下的redis.conf复制到安装目录

[root@localhost conf]# pwd
/home/work/redis/redis-6.0.3/conf
[root@localhost conf]# cp ../redis-6/redis.conf /home/work/redis/redis-6.0.3/con
[root@localhost conf]# ll
total 84
-rw-r--r-- 1 root root 82573 May 23 01:01 redis.conf
[root@localhost conf]# 

创建供redis运行的目录

分别用来存放redis的日志和数据

  • logs:存放日志
  • data:存放快照数据
[root@localhost redis-6.0.3]# mkdir logs data
[root@localhost redis-6.0.3]# ll
total 0
drwxr-xr-x 2 root root 134 May 23 00:57 bin
drwxr-xr-x 2 root root  24 May 23 01:01 conf
drwxr-xr-x 2 root root   6 May 23 01:05 data
drwxr-xr-x 2 root root   6 May 23 01:05 logs

修改redis的配置文件

[root@centos8 conf]# vi redis.conf

配置项:

  • #bind 127.0.0.1 /绑定访问的ip,注释 表示所有IP都可链接
  • daemonize yes //使以daemon方式运行
  • logfile “/home/work/redis/redis-6.0.3/logs/redis.log” //日志保存目录
  • dir /home/work/redis/redis-6.0.3/data //数据保存目录
  • maxmemory 64MB //使用的最大内存数量
  • io-threads 1 //#io线程数

生成供systemd使用的service文件

vi /lib/systemd/system/redis.service

[root@localhost redis-6.0.3]# vi /lib/systemd/system/redis.service

[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/home/work/redis/redis-6.0.3/bin/redis-server /home/work/redis/redis-6.0.3/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
~                                                                                                          
~                           

:wq保存

重新加载service文件

[root@localhost redis-6.0.3]# systemctl daemon-reload 

启动redis:

[root@localhost system]# systemctl start redis
[root@localhost system]# systemctl restart redis
[root@localhost system]# systemctl stop redis

测试从本地连接访问:

[root@localhost bin]# systemctl start redis
[root@localhost bin]# ./redis-cli     # 直接登录本服务器默认6379端口
127.0.0.1:6379> 
127.0.0.1:6379> select 1             # 选择 redis的第几个database
OK
127.0.0.1:6379[1]> set token www.lushunde.com     # 设置key-value
OK
127.0.0.1:6379[1]> set url http://lushunde.com
OK
127.0.0.1:6379[1]> keys *               # 列出*所有的key,可以使用 keys a*
1) "token"
2) "url"
127.0.0.1:6379[1]> get tok
(nil)                                   # 没有查询到 显示nil 表示空
127.0.0.1:6379[1]> get token
"www.lushunde.com"
127.0.0.1:6379[1]> 
127.0.0.1:6379[1]> set token lushunde         # 新增和修改 相同,原来有则覆盖
OK
127.0.0.1:6379[1]> get token
"lushunde"
127.0.0.1:6379[1]> del token 	              # 删除 token
(integer) 1

127.0.0.1:6379[1]> keys *
1) "url"
127.0.0.1:6379[1]> get url
"http://lushunde.com"
127.0.0.1:6379[1]> 
127.0.0.1:6379[1]> exit            # 退出redis-cli
[root@localhost bin]# 
127.0.0.1:6379> shutdown           # 关闭redis服务
not connected> 

查看已安装redis的版本

[root@localhost bin]# ./redis-server -v
Redis server v=6.0.3 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=8bfe5b80f1de4c2e

你可能感兴趣的:(坚持学习,未来可期,#,CentOS8,Centos8,Redis)