幸いですlog

玩转Docker
🛳️

玩转Docker

description
学习docker打包、集群、桥接等
Created
Jun 3, 2022 08:27 AM
Updated
Last updated May 5, 2023

准备

环境准备
  • 会点linux的基础
  • centos7
  • 使用xshell远程链接服务器
环境查看
#系统内核时3.10以上 [root@izm5e2qhnn7p36yrpjgvrez /]# uname -r 3.10.0-514.26.2.el7.x86_64 #系统版本 [root@izm5e2qhnn7p36yrpjgvrez /]# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
帮助文档

卸载旧

Docker 的较旧版本被调用或 。如果安装了这些组件,请卸载它们以及关联的依赖项。docker``docker-engine
$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine

使用存储库🔗

在首次安装 Docker 引擎之前,您需要设置 Docker 存储库。之后,可以从存储库安装和更新 Docker。

设置存储库

安装包(提供实用程序)并设置稳定的存储库。yum-utils``yum-config-manager
$ sudo yum install -y yum-utils #这个使用的时国外的镜像 $ sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo #阿里云 sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://q6xxwzgk.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
安装最新版本的Docker 引擎和容器,或转到下一步以安装特定版本:
#先更新 yum $ sudo yum makecache fast # docker-ce社区版 ee企业版 $ sudo yum install docker-ce docker-ce-cli containerd.io
启动 Docker。
$ sudo systemctl start docker #使用docker version 查看 $ sudo # docker version Client: Docker Engine - Community Version: 20.10.3 API version: 1.41 Go version: go1.13.15 Git commit: 48d30b5 Built: Fri Jan 29 14:34:14 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.3 API version: 1.41 (minimum version 1.12) Go version: go1.13.15 Git commit: 46229ca Built: Fri Jan 29 14:32:37 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.3 GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b runc: Version: 1.0.0-rc92 GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff docker-init: Version: 0.19.0 GitCommit: de40ad0
通过运行映像验证 Docker 引擎安装是否正确。hello-world
$ sudo docker run hello-world $ sudo # docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:95ddb6c31407e84e91a986b004aee40975cb0bda14b5949f6faac5d2deadb4b9 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. #查看 $ sudo# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 13 months ago 13.3kB

卸载 Docker

  1. 卸载 Docker 引擎、CLI 和容器包:
    1. $ sudo yum remove docker-ce docker-ce-cli containerd.io
  1. 主机上的图像、容器、卷或自定义配置文件不会自动删除。要删除所有图像、容器和卷:
    1. $ sudo rm -rf /var/lib/docker #/var/lib/docker 默认工作路径
您必须手动删除任何编辑的配置文件。
port # 查看映射端口对应的容器内部源端口 pause # 暂停容器 ps # 猎户容器列表 pull # 从docker镜像源服务器拉取指定镜像或者库镜像 push # 推送指定镜像或者库镜像至docker源服务器 restart # 重启运行的容器 rm # 移除一个或多个容器 rmi # 移除一个或多个镜像 (无容器使用该镜像才可删除,否则需要删除相关容器才可继续或 -f 强制删除) run # 创建一个新的容器并运行一个命令 save # 保存一个镜像为一个 tar 包【对应 load】 search # 在 docker hub 中搜索镜像 start # 启动容器 stop # 停止容器 tag # 给源中镜像打标签 top # 查看容器中运行的进程信息 unpause # 取消暂停容器 version # 查看 docker版本号 wait # 截取容器停止时的退出状态值

阿里云镜像加速

notion image
notion image
对Docker客户端版本大于 1.10.0 的用户
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://q6xxwzgk.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker

Docker安装Nginx

负载均衡,反向代理
notion image
#1、搜索 search $sudo # docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 14418 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1959 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 806 [OK] jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 143 linuxserver/nginx An Nginx container, brought to you by LinuxS… 141 tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 113 [OK] bitnami/nginx Bitnami nginx Docker Image #2、下载 docker pull $ sudo docker pull nginx Using default tag: latest latest: Pulling from library/nginx a076a628af6f: Pull complete 0732ab25fa22: Pull complete d7f36f6fe38f: Pull complete f72584a26f32: Pull complete 7125e4df9063: Pull complete Digest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa Status: Downloaded newer image for nginx:latest docker.io/library/nginx:latest #3、查看 $ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest f6d0b4767a6c 4 weeks ago 133MB hello-world latest bf756fb1ae65 13 months ago 13.3kB #4、运行 -d 后台运行 --name 名字 -p 暴露端口 宿主机端口:容器内端口 docker pull nginx docker run -d -p 443:443 --restart=always --network common-network -v /home/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx --name nginx01 nginx:latest $ sudo # docker run -d --name nginx01 -p 3344:80 nginx 7c7d1eda5806fb5181e9cf98fb18ac02b4bdb7473d9b7ae5569f7f3784eae30a $ sudo # curl localhost:3344 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title>
notion image

部署es+kibanna

需要限制es的 通过-e参数进行修改
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e
ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2

使用数据卷

1、使用命令来挂载 -v
notion image
notion image
notion image
docker run -it -v 主机目录,容器内目录

安装mysql

  • 创建自定义网络(用于容器通讯)
docker network create common-network
  • 查看网络
docker network ls
mysql的数据持久化问题, data
docker pull mysql
docker run -d -p 3306:3306 --restart=always --network common-network -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=sth773178 --name mysql01 mysql:latest
 
docker run -d -p 3306:3306 --restart=always -e MYSQL_ROOT_PASSWORD=123 --name mysql01 mysql:5.7
  • 查看自定义网络中各容器ip
//查看网络 docker network ls //查看网络容器 [root@iZm5e2qhnn7p36yrpjgvreZ ~]# docker network inspect common-network [ { "Name": "common-network", "Id": "7ee1b4e675e9ac7804da92c1faeeb1a9b5be11df03add931acd2eb0b90e6bb5d", "Created": "2021-02-27T21:40:14.196881403+08:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": {}, "Config": [ { "Subnet": "172.21.0.0/16", "Gateway": "172.21.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "3951a2b1a5ac3e791ae00639e2a8e1d8fb09a0a85c569200545130cbe196ca15": { "Name": "mysql01", "EndpointID": "b2db286808830e6a1629c2f0637a6e24e922f8ac60194fb43d3153f67afee7b4", "MacAddress": "02:42:ac:15:00:02", "IPv4Address": "172.21.0.2/16", "IPv6Address": "" }, "cb999031d0dcc0047d414668e18b7ca618374cbb966582ed6131b2e46719da58": { "Name": "nacos", "EndpointID": "789ef170f52fcc3999414f1fb0382307a64a1f07bc27fc1c2fa1c424b5d1d7c1", "MacAddress": "02:42:ac:15:00:03", "IPv4Address": "172.21.0.3/16", "IPv6Address": "" } }, "Options": {}, "Labels": {} } ]
  • d后台运行
  • p端口映射
  • v数据卷
  • e环境配置
  • -name
    • notion image
      notion image
docker volume ls 查看所有的卷的情况

批量删除

docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -aq)

docker网络

ip addr
notion image

network

notion image
docker network inspect id
docker network ls查看所有的
bridge:桥接模式 默认
none:不配置网络
host:和宿主机共享网络
container:容器网络连通
#我们直接启动的命令 --net bridge 两个都是我们的docker01 $ sudo docker run -d -P --name tomcat01 --net bridge tomcat #自动逸网络 #--driver bridge 默认模式 #--subnet 192.168.0.0/16 192.168.0.2-192.168.255.255 #--gateway 192.168.0.1 主机地址 $ sudo docker network create --driver bridge  --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet $ sudo docker network ls NETWORK ID     NAME     DRIVER   SCOPE 7502fa3df299   bridge   bridge   local 2049f12dcbfc   host     host     local e88579582183   mynet     bridge   local 9bc0988509ee   none     null     local
notion image
然后把容器放入自己定义的网络
[   {        "Name": "mynet",        "Id": "e885795821830784b956f9981f254b7b262348217eb7316598b54ade94a7f116",        "Created": "2021-02-12T19:16:21.013493938+08:00",        "Scope": "local",        "Driver": "bridge",        "EnableIPv6": false,        "IPAM": {            "Driver": "default",            "Options": {},            "Config": [               {                    "Subnet": "192.168.0.0/16",                    "Gateway": "192.168.0.1"               }           ]       },        "Internal": false,        "Attachable": false,        "Ingress": false,        "ConfigFrom": {            "Network": ""       },        "ConfigOnly": false,        "Containers": {            "b25d1a2adec94fcf762fae4421e68e3c7dc51f642b19fb46e4b6c63cc439854a": {                "Name": "tomcat-net-02",                "EndpointID": "2a1c8452d6a0a0754e1dbe22517f5149a2a28cde07da841dbcbb13bd861bfd84",                "MacAddress": "02:42:c0:a8:00:03",                "IPv4Address": "192.168.0.3/16",                "IPv6Address": ""           },            "c3e5a5814cd507a7da84f00e4570cfdf9a569c4458bd1854b87c101c62b66a09": {                "Name": "tomcat-net-01",                "EndpointID": "c3d57c1d7e0bb7924e8ce724455acc86c467cd233184bc8836fad639885de326",                "MacAddress": "02:42:c0:a8:00:02",                "IPv4Address": "192.168.0.2/16",                "IPv6Address": ""           }       },        "Options": {},        "Labels": {}   } ] #测试 [root@izm5e2qhnn7p36yrpjgvrez ~]# docker exec -it tomcat-net-01 ping 192.168.0.3 PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data. 64 bytes from 192.168.0.3: icmp_seq=1 ttl=64 time=0.100 ms 64 bytes from 192.168.0.3: icmp_seq=2 ttl=64 time=0.102 ms 64 bytes from 192.168.0.3: icmp_seq=3 ttl=64 time=0.070 ms 64 bytes from 192.168.0.3: icmp_seq=4 ttl=64 time=0.078 ms 64 bytes from 192.168.0.3: icmp_seq=5 ttl=64 time=0.064 ms ^C --- 192.168.0.3 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 1002ms rtt min/avg/max/mdev = 0.064/0.082/0.102/0.019 ms [root@izm5e2qhnn7p36yrpjgvrez ~]# docker exec -it tomcat-net-01 ping tomcat-net-02 PING tomcat-net-02 (192.168.0.3) 56(84) bytes of data. 64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=1 ttl=64 time=0.053 ms 64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=2 ttl=64 time=0.070 ms
好处
redis,mysql :不同的集群使用不同的网络,保证集群的安全和健康

网络连通

docker中的网络模式有哪些?就是DRIVER展示的那一列
  1. bridge 桥接模式,使用宿主机进行桥接
  1. null 就是不配置网络
  1. host 就是和宿主机共享网络
  1. container 就是容器网络链接(用的很少!局限很大)
一般都会使用桥接模式。
[root@izm5e2qhnn7p36yrpjgvrez ~]# docker network --help Usage: docker network COMMAND Manage networks Commands: connect     Connect a container to a network create     Create a network disconnect Disconnect a container from a network inspect     Display detailed information on one or more networks  ls         List networks prune       Remove all unused networks  rm         Remove one or more networks [root@izm5e2qhnn7p36yrpjgvrez ~]# docker network connect --help Usage: docker network connect [OPTIONS] NETWORK CONTAINER Connect a container to a network Options:      --alias strings           Add network-scoped alias for the container      --driver-opt strings     driver options for the network      --ip string               IPv4 address (e.g., 172.30.100.104)      --ip6 string             IPv6 address (e.g., 2001:db8::33)      --link list               Add link to another container      --link-local-ip strings   Add a link-local address for the container
测试打通tomcat01 -mynet
直接加入到那个网络加入进来
一个容器两个IP地址

部署Redis集群

notion image

搭建步骤

  • 1、下载redis镜像
docker pull redis
查看本地镜像,可以使用命令docker images
  • 2、创建虚拟网卡
创建虚拟网卡,主要是用于redis-cluster能于外界进行网络通信,一般常用桥接模式。
[root@iZm5e2qhnn7p36yrpjgvreZ /]# docker network create redis-net 603b5f8697d234f46303054d6fceb3df9ce73e74542bd95482fa629094e670a1
查看docker的网卡信息,可使用命令docker network ls
[root@iZm5e2qhnn7p36yrpjgvreZ /]# docker network ls NETWORK ID     NAME       DRIVER   SCOPE 6b9e901fe192   bridge     bridge   local 66fbb2ea3040   host       host     local 6d7a3d6948b0   none       null     local 603b5f8697d2   redis-net   bridge   local
查看dockerr网络详细信息,可使用命令docker network inspect redis-net
[root@iZm5e2qhnn7p36yrpjgvreZ /]# docker network inspect redis-net [   {        "Name": "redis-net",        "Id": "603b5f8697d234f46303054d6fceb3df9ce73e74542bd95482fa629094e670a1",        "Created": "2021-02-25T15:52:55.203842464+08:00",        "Scope": "local",        "Driver": "bridge",        "EnableIPv6": false,        "IPAM": {            "Driver": "default",            "Options": {},            "Config": [               {                    "Subnet": "172.20.0.0/16", 地址                    "Gateway": "172.20.0.1"   分配的地址               }           ]       },        "Internal": false,        "Attachable": false,        "Ingress": false,        "ConfigFrom": {            "Network": ""       },        "ConfigOnly": false,        "Containers": {},        "Options": {},        "Labels": {}   } ]
  • 3、创建redis配置文件模板
mkdir -p /home/redis-cluster cd /home/redis-cluster vim redis-cluster.tmpl
在redis-cluster.tmpl中输入以下内容
port ${PORT} protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 115.28.136.212 cluster-announce-port ${PORT} cluster-announce-bus-port 1${PORT} appendonly yes
各节点解释如下所示:
  • port:节点端口,即对外提供通信的端口
  • cluster-enabled:是否启用集群
  • cluster-config-file:集群配置文件
  • cluster-node-timeout:连接超时时间
  • cluster-announce-ip:集群各节点IP地址
  • cluster-announce-port:集群节点映射端口
  • cluster-announce-bus-port:集群总线端口
  • appendonly:持久化模式
cluster-announce-ip:这个IP需要特别注意一下,如果要对外提供访问功能,需要填写宿主机的IP,如果填写docker分配的IP(172.x.x.x),可能会导致部分集群节点在跳转时失败。
  • 4、创建节点配置文件
在redis-cluser中执行以下命令
for port in $(seq 6111 6116); \ do \ mkdir -p ./${port}/conf \ && PORT=${port} envsubst < ./redis-cluster.tmpl > ./${port}/conf/redis.conf \ && mkdir -p ./${port}/data; \ done
验证上述命令执行的结果是否正确
[root@iZm5e2qhnn7p36yrpjgvreZ redis-cluster]# tree /home/redis-cluster /home/redis-cluster ├── 6111 │   ├── conf │   │   └── redis.conf │   └── data ├── 6112 │   ├── conf │   │   └── redis.conf │   └── data ├── 6113 │   ├── conf │   │   └── redis.conf │   └── data ├── 6114 │   ├── conf │   │   └── redis.conf │   └── data ├── 6115 │   ├── conf │   │   └── redis.conf │   └── data ├── 6116 │   ├── conf │   │   └── redis.conf │   └── data └── redis-cluster.tmpl [root@iZm5e2qhnn7p36yrpjgvreZ redis-cluster]# cat /home/redis-cluster/611{1..6}/conf/redis.conf port 6111 protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 115.28.136.212 cluster-announce-port 6111 cluster-announce-bus-port 16111 appendonly yes port 6112 protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 115.28.136.212 cluster-announce-port 6112 cluster-announce-bus-port 16112 appendonly yes port 6113 protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 115.28.136.212 cluster-announce-port 6113 cluster-announce-bus-port 16113 appendonly yes port 6114 protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 115.28.136.212 cluster-announce-port 6114 cluster-announce-bus-port 16114 appendonly yes port 6115 protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 115.28.136.212 cluster-announce-port 6115 cluster-announce-bus-port 16115 appendonly yes port 6116 protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 115.28.136.212 cluster-announce-port 6116 cluster-announce-bus-port 16116 appendonly yes
  • 5、创建redis节点容器
执行以下命令即可
for port in $(seq 6111 6116); \ do \ docker run -it -d -p ${port}:${port} -p 1${port}:1${port} \ --privileged=true -v /home/redis-cluster/${port}/conf/redis.conf:/usr/local/etc/redis/redis.conf \ --privileged=true -v /home/redis-cluster/${port}/data:/data \ --restart always --name redis-${port} --net redis-net \ --sysctl net.core.somaxconn=1024 redis redis-server /usr/local/etc/redis/redis.conf; \ done
验证容器是否创建成功
[root@iZm5e2qhnn7p36yrpjgvreZ redis-cluster]# docker ps -n 6 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 99bea3841fa3 redis "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 0.0.0.0:6116->6116/tcp, 0.0.0.0:16116->16116/tcp, 6379/tcp redis-6116 a5bc3c7e1659 redis "docker-entrypoint.s…" 10 seconds ago Up 9 seconds 0.0.0.0:6115->6115/tcp, 0.0.0.0:16115->16115/tcp, 6379/tcp redis-6115 c0342a71ce28 redis "docker-entrypoint.s…" 10 seconds ago Up 9 seconds 0.0.0.0:6114->6114/tcp, 0.0.0.0:16114->16114/tcp, 6379/tcp redis-6114 e589a0d71269 redis "docker-entrypoint.s…" 11 seconds ago Up 10 seconds 0.0.0.0:6113->6113/tcp, 0.0.0.0:16113->16113/tcp, 6379/tcp redis-6113 7895fd24740d redis "docker-entrypoint.s…" 11 seconds ago Up 10 seconds 0.0.0.0:6112->6112/tcp, 0.0.0.0:16112->16112/tcp, 6379/tcp redis-6112 8e3ee6689199 redis "docker-entrypoint.s…" 12 seconds ago Up 11 seconds 0.0.0.0:6111->6111/tcp, 0.0.0.0:16111->16111/tcp, 6379/tcp redis-6111 [root@iZm5e2qhnn7p36yrpjgvreZ redis-cluster]# docker network inspect redis-net | grep -i -E "name|ipv4address" "Name": "redis-net", "Name": "redis-6112", "IPv4Address": "172.20.0.3/16", "Name": "redis-6111", "IPv4Address": "172.20.0.2/16", "Name": "redis-6116", "IPv4Address": "172.20.0.7/16", "Name": "redis-6115", "IPv4Address": "172.20.0.6/16", "Name": "redis-6114", "IPv4Address": "172.20.0.5/16", "Name": "redis-6113", "IPv4Address": "172.20.0.4/16",
  • 6、创建redis-cluster集群
进入一个容器节点
docker exec -it redis-6111 bash
在进入容器后,执行以下命令:
入容器后,执行以下命令:
cd /usr/local/bin/ redis-cli --cluster create 115.28.136.212:6111 115.28.136.212:6112 115.28.136.212:6113 115.28.136.212:6114 115.28.136.212:6115 115.28.136.212:6116 --cluster-replicas 1
出现选择提示信息,输入yes,结果如下所示
root@8e3ee6689199:/usr/local/bin# redis-cli --cluster create 115.28.136.212:6111 115.28.136.212:6112 115.28.136.212:6113 115.28.136.212:6114 115.28.136.212:6115 115.28.136.212:6116 --cluster-replicas 1 >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 115.28.136.212:6115 to 115.28.136.212:6111 Adding replica 115.28.136.212:6116 to 115.28.136.212:6112 Adding replica 115.28.136.212:6114 to 115.28.136.212:6113 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: e4e8c0422362b2c3a7d72a6cdb985b9bfd9727cb 115.28.136.212:6111 slots:[0-5460] (5461 slots) master M: e4d076b642616d253cde60c9962122221a248966 115.28.136.212:6112 slots:[5461-10922] (5462 slots) master M: 5c7f2f38f7fa22570ffd2caeb52df241f51fc018 115.28.136.212:6113 slots:[10923-16383] (5461 slots) master S: a0938517e0300322ba7dd861c2b71a8426d11903 115.28.136.212:6114 replicates e4d076b642616d253cde60c9962122221a248966 S: 695d133e8bfc07c41c9738c4e40997175024f905 115.28.136.212:6115 replicates 5c7f2f38f7fa22570ffd2caeb52df241f51fc018 S: a95425ed9d8face6c961b196fa515d3ea264637c 115.28.136.212:6116 replicates e4e8c0422362b2c3a7d72a6cdb985b9bfd9727cb Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join >>> Performing Cluster Check (using node 115.28.136.212:6111) M: e4e8c0422362b2c3a7d72a6cdb985b9bfd9727cb 115.28.136.212:6111 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: a0938517e0300322ba7dd861c2b71a8426d11903 115.28.136.212:6114 slots: (0 slots) slave replicates e4d076b642616d253cde60c9962122221a248966 M: 5c7f2f38f7fa22570ffd2caeb52df241f51fc018 115.28.136.212:6113 slots:[10923-16383] (5461 slots) master 1 additional replica(s) M: e4d076b642616d253cde60c9962122221a248966 115.28.136.212:6112 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: 695d133e8bfc07c41c9738c4e40997175024f905 115.28.136.212:6115 slots: (0 slots) slave replicates 5c7f2f38f7fa22570ffd2caeb52df241f51fc018 S: a95425ed9d8face6c961b196fa515d3ea264637c 115.28.136.212:6116 slots: (0 slots) slave replicates e4e8c0422362b2c3a7d72a6cdb985b9bfd9727cb [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
  • 连接redis-cluster,并添加数据到redis
在节点6111中输入以下命令
redis-cli -c -h 115.28.136.212 -p 6111 115.28.136.212:6113> set ss asd -> Redirected to slot [5118] located at 115.28.136.212:6111 OK 115.28.136.212:6111> get ss "asd" 115.28.136.212:6111>
notion image

springboot集成

docker build -t clover . 安装

防火墙

systemctl start firewalld 启动
systemctl status firewalld 查看状态
systemctl stop firewalld 停止
firewall-cmd --permanent --zone=public --add-port=16371/tcp 查看指定端口
ip addr 查看网络

命令

docker ps // 查看所有正在运行容器 docker stop containerId // containerId 是容器的ID docker ps -a // 查看所有容器 docker ps -a -q // 查看所有容器ID docker start $(docker ps -a -q) // start启动所有停止的容器 docker stop $(docker ps -a -q) // stop停止所有容器 docker rm $(docker ps -a -q) // remove删除所有容器

docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.28.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose #备用地址 curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 423 100 423 0 0 148 0 0:00:02 0:00:02 --:--:-- 148 100 16.7M 100 16.7M 0 0 3979k 0 0:00:04 0:00:04 --:--:-- 17.4M
notion image
2、授权
sudo chmod +x /usr/local/bin/docker-compose [root@iZm5e2qhnn7p36yrpjgvreZ ~]# docker-compose version docker-compose version 1.25.5, build 8a1c60f6 docker-py version: 4.1.0 CPython version: 3.7.5 OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019 [root@iZm5e2qhnn7p36yrpjgvreZ ~]#
docker-compose常用命令
docker-compose -h # 查看帮助 docker-compose up # 创建并运行所有容器 docker-compose up -d # 创建并后台运行所有容器 docker-compose -f docker-compose.yml up -d # 指定模板 docker-compose down # 停止并删除容器、网络、卷、镜像。 docker-compose logs # 查看容器输出日志 docker-compose pull # 拉取依赖镜像 dokcer-compose config # 检查配置 dokcer-compose config -q # 检查配置,有问题才有输出 docker-compose restart # 重启服务 docker-compose start # 启动服务 docker-compose stop # 停止服务

配置nacos

Clone 项目
git clone https://github.com/nacos-group/nacos-docker.git cd nacos-docker
如果希望使用MySQL8
docker-compose -f example/standalone-mysql-8.yaml up -d -d表示后台 version: "2" services: nacos: image: nacos/nacos-server:1.4.0 container_name: nacos environment: - MODE=standalone #单列模式 - SPRING_DATASOURCE_PLATFORM=mysql #数据库 - MYSQL_SERVICE_HOST=172.21.0.2 #docker网络里的ip - MYSQL_MASTER_SERVICE_PORT=3306 #端口 - MYSQL_SERVICE_USER=root #用户 - MYSQL_SERVICE_PASSWORD=sth773178 #密码 - MYSQL_SERVICE_DB_NAME=nacos_config #数据库 - JVM_XMS=512m # 指定应用程序可用的最小堆大小 - JVM_MMS=320m env_file: - ../env/nacos-standlone-mysql.env volumes: - ./standalone-logs/:/home/nacos/logs - ./init.d/custom.properties:/home/nacos/init.d/custom.properties ports: - "8848:8848" restart: always networks: #配置和mysql容器互通的网络common-network default: external: name: common-network
notion image

安装tomcat

拉去镜像
docker pull tomcat
启动tomcat
docker run -d --name clover-tomcat \ -p 8080:8080 \ --restart=always --network common-network \ -v /home/tomcat/webapps:/usr/local/tomcat/webapps \ tomcat:latest #在network中的地址           "Name": "clover-tomcat",                "EndpointID": "48d13338d453d8929632bcfe023cb624a5ad2b0f0234c391a29cbd4ddc5347d8",                "MacAddress": "02:42:ac:15:00:04",                "IPv4Address": "172.21.0.4/16",                "IPv6Address": ""           },
注意还需要在webapps下创建ROOT文件夹然后把需要的资源放入

安装nginx同时配置https

拉去镜像
docker pull nginx
拷贝nginx镜像中的文件到宿主机
docker run --name tmp-nginx -d nginx:latest mkdir -p /home/nginx docker cp tmp-nginx:/etc/nginx/conf.d /home/nginx/ docker cp tmp-nginx:/usr/share/nginx/html /home/nginx/ docker stop tmp-nginx docker rm tmp-nginx
启动nginx服务
docker run --name clover-nginx -d \ -p 80:80 -p 443:443 \ --restart=always --network common-network \ -v /home/nginx/conf.d:/etc/nginx/conf.d:ro \ -v /home/nginx/ssl:/etc/nginx/ssl:ro \ -v /home/nginx/html:/usr/share/nginx/html:ro \ nginx:latest
以上命令:
  • 命名容器为vk-nginx,后台运行
  • 映射宿主机80、443端口到容器的80、443端口
  • 挂载宿主机目录/home/nginx/conf.d到容器目录/etc/nginx/conf.d
  • 挂载宿主机目录/home/nginx/ssl到容器目录/etc/nginx/ssl
  • 挂载宿主机目录/home/nginx/html到容器目录/usr/share/nginx/html
配置https
server { listen 80; server_name www.clover-blog.xyz; return 301 https://$server_name$request_uri; } server { # SSL configuration listen 443 ssl; listen [::]:443 ssl; server_name www.clover-blog.xyz; ssl_certificate /etc/nginx/ssl/5397881_clover-blog.xyz.pem; ssl_certificate_key /etc/nginx/ssl/5397881_clover-blog.xyz.key; ssl_session_timeout 5m; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM; ssl_prefer_server_ciphers on; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; root /usr/share/nginx/html/voidking/; index index.html; } }
重启nginx
docker restart clover-nginx
查看是否启动成功
docker ps docker logs clover-nginx
 

曾经也有 个和你一样的人来过这里。

「姿や形は問題ではなく、「魂」が問題です。」

Vercel Logo

「健全なる魂は健全なる精神と健全なる肉体に宿る。」

「あなたの魂、受け取りました。」

VercelVercel

Clover © 2022 幸いです 全著作権所有.