





Redis安装
这里介绍两种安装方式:使用docker安装Redis,以及直接在CentOS7下安装。
[root@localhost ~]# docker search redisINDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATEDdocker.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 80docker.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... 43docker.io docker.io/redislabs/redisinsight RedisInsight - The GUI for Redis 35docker.io docker.io/redislabs/rejson RedisJSON - Enhanced JSON data type proces... 32docker.io docker.io/oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Su... 31docker.io docker.io/redislabs/redis Clustered in-memory database engine compat... 31docker.io docker.io/arm32v7/redis Redis is an open source key-value store th... 25docker.io docker.io/arm64v8/redis Redis is an open source key-value store th... 19docker.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 10docker.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... 6docker.io docker.io/clearlinux/redis Redis key-value data structure server with... 3docker.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:latestTrying to pull repository docker.io/library/redis ...latest: Pulling from docker.io/library/redise5ae68f74026: Pull complete37c4354629da: Pull completeb065b1b1fa0f: Pull complete6954d19bb2e5: Pull complete6333f8baaf7c: Pull completef9772c8a44e7: Pull completeDigest: sha256:2f502d27c3e9b54295f1c591b3970340d02f8a5824402c8179dcd20d4076b796Status: Downloaded newer image for docker.io/redis:latest
查看本地镜像:
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/redis latest aea9b698d7d1 4 days ago 113 MB
运行一个redis容器,默认使用6379端口:
[root@localhost ~]# docker run -itd --name docker_redis_server -p 6379:6379 redis18352188dd9ecb617a32e3f061bf196c6271d13b98fd7d562e7f468c3204dd25
查看容器运行:
root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES18352188dd9e 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/bashroot@18352188dd9e:/data# redis-cli127.0.0.1:6379> set name zhangsanOK127.0.0.1:6379> get name"zhangsan"127.0.0.1:6379> quitroot@18352188dd9e:/data# exitexit
[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-cli127.0.0.1:6379> set name zhangsanOK127.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.confdaemonize yes
# 启动服务[root@localhost bin]# ./redis-server redis.conf# 查看服务进程[root@localhost bin]# ps -ef|grep redisroot 7954 5604 0 17:45 pts/1 00:00:00 grep --color=auto redisroot 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-serverAfter=network.target[Service]Type=forkingExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.confPrivateTmp=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数据库。
后续,我将为您介绍其他一些中间件的教程,敬请期待~~。

长按二维码关注我们吧
不要错过


文章转载自一起Go技术,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




