首頁(yè)技術(shù)文章正文

Docker stack 一鍵編排Inmp【linux云計(jì)算+運(yùn)維開(kāi)發(fā)】

更新時(shí)間:2020-04-29 來(lái)源:黑馬程序員 瀏覽量:

環(huán)境要求

1588147265481_docker01.jpg


1588147275731_docker02.jpg


1、配置nfs存儲(chǔ)卷

(1)在docker swarm集群中所有節(jié)點(diǎn)都確認(rèn)安裝nfs客戶端軟件

# yum install nfs-utils rpcbind -y

(2)在192.168.122.1 上搭建nfs,共享目錄給docker swarm集群中所有節(jié)點(diǎn)掛載

[root@nfs ~]# mkdir /opt/dockervolume

[root@nfs ~]# vim /etc/exports

/opt/dockervolume   *(rw,no_root_squash,sync)

[root@nfs ~]# systemctl restart rpcbind nfs-server
[root@nfs ~]# systemctl enble rpcbind nfs-server

(3)在docker swarm集群中所有節(jié)點(diǎn)創(chuàng)建存儲(chǔ)卷,并驗(yàn)證。

# docker volume create   --driver local --opt type=nfs --opt o=addr=192.168.122.1,rw --opt device=:/opt/dockervolume

nginx_volume

# docker volume ls |grep nginx_volume

local               nginx_volume

# docker volume inspect nginx_volume
[

    {

        "CreatedAt": "2019-06-12T13:24:09+08:00",

        "Driver": "local",

        "Labels": {}, "Mountpoint":

        "/var/lib/docker/volumes/nginx_volume/_data", "Name": "nginx_volume",

        "Options": {

            "device": ":/opt/dockervolume", "o": "addr=192.168.122.1,rw",

            注意這里的掛載參數(shù)要有

            "type": "nfs"

},

"Scope": "local"

}

2、下載鏡像

在任意能上外網(wǎng)的機(jī)器上操作

[root@nfs ~]# docker pull richarvey/nginx-php-fpm

3、準(zhǔn)備是相關(guān)配置文件

[root@nfs ~]# mkdir /root/discuz/dockerfile -p
[root@nfs ~]# cd /root/discuz/dockerfile


準(zhǔn)備nginx主配置文件

[root@nfs dockerfile]# vim nginx.conf user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log warn;

pid /var/run/nginx.pid;

events {

    use epoll;
    worker_connections 65535;

}

http {

    include    /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '

    '$status $body_bytes_sent

    "$http_referer" '

    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log

    sendfile #tcp_nopush

    /var/log/nginx/access.log on;

    on;

    main;

    keepalive_timeout 65; #gzip on;

    include /etc/nginx/conf.d/*.conf;

}

準(zhǔn)備nginx子配置文件

[root@nfs dockerfile]# vim web.conf server {

    listen 80; server_name _;

    index index.php index.html; root /var/www/html;

    location ~ \.php$ {

        fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME

        $document_root$fastcgi_script_name; include fastcgi_params;

    }

}

準(zhǔn)備時(shí)區(qū)文件

[root@nfs dockerfile]# cp /etc/localtime .

準(zhǔn)備php-fpm子配置文件

[root@nfs dockerfile]# vim php-fpm-www.conf [www]

user = nginx group = nginx

listen = 127.0.0.1:9000

pm = dynamic pm.max_children = 64

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

rlimit_files = 1024

4、準(zhǔn)備鏡像

編寫(xiě)Docker?le

[root@nfs dockerfile]# vim dockerfile FROM richarvey/nginx-php-fpm

MAINTAINER daniel@itcast.cn

RUN echo 'Asia/Shanghai' > /etc/timezone && rm -f

/etc/nginx/nginx.conf && rm -f /usr/local/etc/php- fpm.d/www.conf

COPY localtime /etc/localtime

COPY nginx.conf /etc/nginx/nginx.conf COPY web.conf /etc/nginx/conf.d/web.conf

COPY php-fpm-www.conf /usr/local/etc/php-fpm.d/www.conf

CMD /usr/sbin/nginx -c /etc/nginx/nginx.conf &&

/usr/local/sbin/php-fpm -c /usr/local/etc/php-fpm.conf

構(gòu)建鏡像

[root@nfs dockerfile]# docker build -f dockerfile -t 192.168.122.18/library/nginx-php-fpm:v1 .


上傳鏡像到harbor

[root@nfs dockerfile]# docker login 192.168.122.18

[root@nfs dockerfile]# docker push
192.168.122.18/library/nginx-php-fpm:v1


5、編排docker stack

編寫(xiě)YMAL文件

在docker swarm集群中的管理節(jié)點(diǎn)進(jìn)行操作

[root@manager ~]# cat discuz.yml
version: '3'

services:
    db:

    image: 192.168.122.18/library/mysql:5.7 environment:

        MYSQL_ROOT_PASSWORD: 123

        MYSQL_DATABASE: discuz
        MYSQL_USER: discuz_user MYSQL_PASSWORD: 123

    deploy:

        replicas: 1

    nginx-php:

        image: 192.168.122.18/library/nginx-php-fpm:v1
        depends_on:

            - db
    ports:

        - "8011:80"

     volumes:

        - "nginx_volume:/var/www/html"
    deploy:

        replicas: 1

volumes:

    nginx_volume:
        driver: local
        driver_opts:

            type: "nfs"

            o: "addr=192.168.122.1,rw"

            device: ":/opt/dockervolume"

一鍵發(fā)布stack

[root@manager ~]# docker stack deploy -c discuz2.yml discuz
Creating network discuz_default

Creating service discuz_db
Creating service discuz_nginx-php


6、拷貝discuz代碼到nfs共享

在nfs服務(wù)器上操作

[root@nfs dockerfile]# git clone
https://gitee.com/ComsenzDiscuz/DiscuzX.git

[root@nfs dockerfile]# cp DiscuzX/upload/* /opt/dockervolume/

-rf

cp: overwrite '/opt/dockervolume/index.php'? y

7, 通過(guò)瀏覽器安裝

1588147288309_docker03.jpg

1588147298560_docker04.jpg


[root@nfs dockerfile]# chmod o+w -R /opt/dockervolume/

上圖少了-R參數(shù),請(qǐng)加上

1588147306929_docker05.jpg

1588147315825_docker06.jpg

1588147324086_docker07.jpg

1588147333289_docker08.jpg


猜你喜歡:

如何安裝配置Supervisor?


分享到:
在線咨詢 我要報(bào)名
和我們?cè)诰€交談!