Centos8安裝redis6.0.3
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