暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

CentOS7之Redis安装指南

一起Go技术 2021-12-07
1083

声明:这是一个系列,系列中,我将为您介绍一些常用中间件安装最佳实践



在本文中,我将为您介绍,如何CentOS7下安装Redis5。


Redis安装


这里介绍两种安装方式:使用docker安装Redis,以及直接在CentOS7下安装。


1. 使用Docker方式安装

搜索redis镜像:
[root@localhost ~]# docker search redis
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/redis Redis is an open source key-value store th... 10269 [OK]
docker.io docker.io/sameersbn/redis 83 [OK]
docker.io docker.io/grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2 80
docker.io docker.io/rediscommander/redis-commander Alpine image for redis-commander - Redis m... 71 [OK]
docker.io docker.io/redislabs/redisearch Redis With the RedisSearch module pre-load... 43
docker.io docker.io/redislabs/redisinsight RedisInsight - The GUI for Redis 35
docker.io docker.io/redislabs/rejson RedisJSON - Enhanced JSON data type proces... 32
docker.io docker.io/oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Su... 31
docker.io docker.io/redislabs/redis Clustered in-memory database engine compat... 31
docker.io docker.io/arm32v7/redis Redis is an open source key-value store th... 25
docker.io docker.io/arm64v8/redis Redis is an open source key-value store th... 19
docker.io docker.io/redislabs/redisgraph A graph database module for Redis 17 [OK]
docker.io docker.io/redislabs/rebloom A probablistic datatypes module for Redis 16 [OK]
docker.io docker.io/redislabs/redismod An automated build of redismod - latest Re... 15 [OK]
docker.io docker.io/webhippie/redis Docker image for redis 11 [OK]
docker.io docker.io/insready/redis-stat Docker image for the real-time Redis monit... 10 [OK]
docker.io docker.io/redislabs/redistimeseries A time series database module for Redis 10
docker.io docker.io/s7anley/redis-sentinel-docker Redis Sentinel 10 [OK]
docker.io docker.io/goodsmileduck/redis-cli redis-cli on alpine 9 [OK]
docker.io docker.io/centos/redis-32-centos7 Redis in-memory data structure store, used... 6
docker.io docker.io/clearlinux/redis Redis key-value data structure server with... 3
docker.io docker.io/runnable/redis-stunnel stunnel to redis provided by linking conta... 1 [OK]
docker.io docker.io/tiredofit/redis Redis Server w/ Zabbix monitoring and S6 O... 1 [OK]
docker.io docker.io/wodby/redis Redis container image with orchestration 1 [OK]
docker.io docker.io/xetamus/redis-resource forked redis-resource 0 [OK]

使用docker拉取官方最新的redis镜像:

[root@localhost ~]# docker pull redis:latest
Trying to pull repository docker.io/library/redis ...
latest: Pulling from docker.io/library/redis
e5ae68f74026: Pull complete
37c4354629da: Pull complete
b065b1b1fa0f: Pull complete
6954d19bb2e5: Pull complete
6333f8baaf7c: Pull complete
f9772c8a44e7: Pull complete
Digest: sha256:2f502d27c3e9b54295f1c591b3970340d02f8a5824402c8179dcd20d4076b796
Status: Downloaded newer image for docker.io/redis:latest

查看本地镜像:

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/redis latest aea9b698d7d1 4 days ago 113 MB

运行一个redis容器,默认使用6379端口:

[root@localhost ~]# docker run -itd --name docker_redis_server -p 6379:6379 redis
18352188dd9ecb617a32e3f061bf196c6271d13b98fd7d562e7f468c3204dd25

查看容器运行:

root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
18352188dd9e redis "docker-entrypoint..." 6 seconds ago Up 5 seconds 0.0.0.0:6378->6378/tcp docker_redis_server

测试使用redis:

[root@localhost ~]# docker exec -it docker_redis_server /bin/bash
root@18352188dd9e:/data# redis-cli
127.0.0.1:6379> set name zhangsan
OK
127.0.0.1:6379> get name
"zhangsan"
127.0.0.1:6379> quit
root@18352188dd9e:/data# exit
exit
■ ■■■

2. 直接安装

下载、解压安装包:
[root@localhost ~]# yum install -y gcc 
[root@localhost ~]# wget https://download.redis.io/releases/redis-5.0.4.tar.gz
[root@localhost ~]# tar -zxvf redis-5.0.4.tar.gz

进入解压目录中,编译,安装:

[root@localhost ~]# cd redis-5.0.4
[root@localhost ~]# make
[root@localhost ~]# make install PREFIX=/usr/local/redis

至此,到这里安装完成,启动即可。下面启动它:

[root@localhost ~]# cd /usr/local/redis/bin/
[root@localhost bin]# ./redis-server

上面这种启动方式是在前台启动了。

创建一个redis客户端的软链接,测试一下:

[root@localhost bin]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli
[root@localhost ~]# redis-cli
127.0.0.1:6379> set name zhangsan
OK
127.0.0.1:6379> get name
"zhangsan"

前台启动一旦窗口关闭,就终止了。下面通过后台启动它:

# 拷贝一个配置文件
[root@localhost bin]# cp /usr/local/redis-5.0.4/redis.conf /usr/local/redis/bin/
# 编辑配置文件,把daemonize no改为daemonize yes
[root@localhost bin]# vim redis.conf
daemonize yes
# 启动服务
[root@localhost bin]# ./redis-server redis.conf
# 查看服务进程
[root@localhost bin]# ps -ef|grep redis
root 7954 5604 0 17:45 pts/1 00:00:00 grep --color=auto redis
root 21755 1 0 Aug30 ? 02:23:05 /usr/local/redis/bin/redis-server *:6379
现在,将它设置成开启启动:
# 编辑一个redis.service文件,添加下面内容
[root@localhost bin]# vim /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target


[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true


[Install]
WantedBy=multi-user.target


# 让文件生效
[root@localhost bin]# systemctl daemon-reload
# 启动服务
[root@localhost bin]# systemctl start redis.service
# 开机启动
[root@localhost bin]# systemctl enable redis.service
■ ■■■


总结


本文主要为您介绍了,如何在CentOS7中安装Redis数据库。


绍其他一些中间件的~~




  end 
👇👇👇👇👇👇

长按二维码关注我们吧


不要错过



因为你的分享、点赞、在看
我足足的精气神儿!
文章转载自一起Go技术,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论