Java教程

2021-10-05

本文主要是介绍2021-10-05,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

docker部署redis
小源博客 发表于 2021/10/05 17:37:45 3 0 0
一、安装docker

1、把yum源更新

[root@localhost ~]# yum update -y

2、下载docker一些依赖包

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
3、把docker官方源下载下来
[root@localhost ~]# yum-config-manager --add-repo \https://download.docker.com/linux/centos/docker-ce.repo

4、安装docker

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r && yum install docker-ce -y

5、重启 docker

[root@localhost ~]# systemctl restart docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
二、安装redis

1、查找reddis

[root@localhost ~]# docker search redis
2、安装reddis并修改配置文件重启 redis

[root@localhost ~]# docker pull redis ##pull redis
Using default tag: latest
latest: Pulling from library/redis
07aded7c29c6: Pull complete
1a5d64c027a4: Pull complete
189d72810950: Pull complete
b85aac102f7d: Pull complete
fe1bca69301e: Pull complete
fd69789c2b06: Pull complete
Digest: sha256:c98f0230b5f1831f4f5dd764c4ea8ef11d3e3a1a3593278eb952373d97c82b27
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
[root@localhost ~]# docker images ##查看镜像列表

mkdir /usr/local/docker
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 5d89766432d0 6 days ago 105MB
cd /usr/local/docker
[root@localhost ~]#
[root@localhost ~]# mkdir /usr/local/docker
[root@localhost ~]# cd /usr/local/docker
[root@localhost docker]# yum -y install wget

[root@localhost docker]#wget http://download.redis.io/redis-stable/redis.conf ##下载配置文件

[root@localhost docker]#sed -i ‘s/bind127.0.0.1/#bind127.0.0.1/g’ /usr/local/docker/redis.conf && sed -i ‘s/protected-mode yes/protected-mode no/g’ /usr/local/docker/redis.conf ##修改配置文件

[root@localhost docker]#docker run -itd --name redis-test -p 6379:6379 redis ##起一个名叫redis-test的docker

[root@localhost docker]#docker run -itd -p localhost:6379:6379 --name redis -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/data redis redis-server /etc/redis/redis.conf ##配置文件加入到docker里面

[root@localhost docker]# docker start redis ##重启docker

[root@localhost docker]# docker exec -it redis-test bash ##进入redis

root@326ac72d2228:/data# redis-cli -h 192.168.73.182 -p 6379 ##远程登陆redis
192.168.73.182:6379> ping
PONG
192.168.73.182:6379>

这篇关于2021-10-05的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!