swarm docker-compose.yml NFS 搭建LNMP
Posted python-diy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swarm docker-compose.yml NFS 搭建LNMP相关的知识,希望对你有一定的参考价值。
列表:
172.16.0.40 (swarm-master)
172.16.0.160 (swarm-worker)
172.16.0.170 (swarm-worker)
172.16.0.30 (mariadb-master)
172.16.0.43 (mariadb-slave)
172.16.0.199 ( registry)
docker仓库搭建----registry
mkdir /registry/date && chmod -r 777 /registry/date
pull && run
docker run -d -p 5000:5000 --name registry -v /registry/date:/var/lib/registry --restart=always registry
SWARM 集群搭建:
docker 开启远程连接:
echo "OPTIONS=‘-H 0.0.0.0:2377 -H unix:///var/run/docker.sock" > /etc/default/docker && systemctl daemon-reload && systemctl restart docker
docker 添加私有仓库:
sudo mkdir -p /etc/docker && sudo tee /etc/docker/daemon.json <<-‘EOF‘ { "registry-mirrors": ["172.16.0.199:5000"] } EOF
另一种方法:
vim /lib/systemd/system/docker.service
--insecure-registry 172.16.0.199:5000
检查: docker info
开启iptables 端口 : tcp/2377 tcp/udp 4789 946 :所有节点
iptables -I INPUT -p tcp --dport 2377 ACCEPT
iptables -I INPUT -p tcp --dport 7946 ACCEPT
iptables -I INPUT -p tcp --dport 4789 ACCEPT
iptables -A INPUT -p udp --destination-port 7946 -j ACCEPT
iptables -A INPUT -p udp --destination-port 4789 ACCEPT
master 节点(40) 创建集群
docker swarm init --advertise-addr 172.16.0.40
在次查看 docker swarm join-token worker |
docker swarm join-token manager
master 节点安装nfs
yum install nfs-utils -y && echo "/data/www 172.16.0.0/24(rw,sync,no_root_squash) " > /etc/export && systemctl start nfs
worker (160,170)加入集群
各项命令查看:
docker node ls #查看node 节点
docker network ls #查看swarm-overlay 详情
docker volume ls #查看数据卷
docker network inspect (project_name) #查看项目挂载网络
docker network volume (project_name) #查看项目挂载数据卷
docker service ps (project_name) #查看各container 详情
docker-compose.yml :
version: ‘3.2‘ services: nginx: image: 172.16.0.199:5000/nginx:v1.0 ports: - 80:80 environment: NGINX_HOST: php-fpm volumes: - type: volume source: webdata target: /usr/www/html volume: nocopy: true deploy: mode: replicated replicas: 3 resources: limits: cpus: ‘0.4‘ memory: 100M reservations: cpus: ‘0.2‘ memory: 50M depends_on: - php-fpm networks: - stack_net php-fpm: image: 172.16.0.199:5000/php-fpm:v1.0 volumes: - type: volume source: webdata target: /usr/www/html volume: nocopy: true networks: - stack_net deploy: mode: replicated replicas: 2 resources: limits: cpus: ‘0.8‘ memory: 100M reservations: cpus: ‘0.5‘ memory: 50M volumes: webdata: driver: local driver_opts: type: "nfs" o: "addr=172.16.0.40,vers=4,soft,timeo=180,bg,tcp,rw" device: "172.16.0.40:/data/www" networks: stack_net: driver: overlay
mariadb: db
db 我已经导入 有关db 以后会有blog
RUN: docker stack deploy -c my-demo
docker stack rm demo #删除
docker service ps demo #查看运行状态
docker service logs ( 容器 id | name) #查看log日记
以上是关于swarm docker-compose.yml NFS 搭建LNMP的主要内容,如果未能解决你的问题,请参考以下文章
docker 中 nginx 后面的 Keycloak 导致 404 和不定式重定向