国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Dockerfile分離構(gòu)建LNMP環(huán)境部署wordpress

2019-11-06 08:15:11
字體:
供稿:網(wǎng)友

最近忙著寫自己的項目,也把一個站點的bbs論壇打算遷移到Docker中,測試沒發(fā)現(xiàn)啥大問題。在單臺上面的架構(gòu)如下;(往后我們也是要講到compose和swarm調(diào)度的慢慢來)

face/xTtFY7ejEAHhmnECWBEsnZRRNBs6Jtec.png

1、首先我們先安裝一下docker,好多人都發(fā)現(xiàn)國內(nèi)用yum安裝有各種問題;這里我們用國內(nèi)的https://www.daocloud.io.登錄后注冊,然后點擊下載。里面有提示,我們點擊Linxu安裝然后復(fù)制代碼執(zhí)行到shell上即可。

[root@test nginx]# curl -sSL https://get.daocloud.io/docker | sh

2、安裝好之后,安裝dockhub加速器,點擊加速器,復(fù)制代碼粘貼到shell.

[root@test nginx]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://681a96df.m.daocloud.io{"registry-mirrors": ["http://681a96df.m.daocloud.io"],    "live-restore": true}Success.You need to restart docker to take effect: sudo systemctl restart docker

##執(zhí)行腳本,主要是把倉庫地址寫到daemon.json文件下。

[root@test nginx]# cat /etc/docker/daemon.json{"registry-mirrors": ["http://681a96df.m.daocloud.io"],    "live-restore": true}

3、準(zhǔn)備工作都已經(jīng)完成了,接下來我們來構(gòu)建一下dockerfile在三個目錄下,看下目錄結(jié)構(gòu):

[root@test test]# tree -L 2 --charset ASCII|-- MySQL|   |-- Dockerfile|   |-- epel-6.repo|   |-- my.cnf|   `-- startup.sh|-- nginx|   |-- Dockerfile|   |-- nginx-1.11.10|   |-- nginx-1.11.10.tar.gz|   |-- nginx.conf|   `-- nginx_default.conf`-- php-fpm    |-- Centos-6.repo    |-- Dockerfile    |-- epel-6.repo    |-- php-5.5.38    `-- php-5.5.38.tar.gz

5、看一下nginx 的 Dockerfile:

[root@test nginx]# cat Dockerfile #lnmp centos 6.0from centos:centos6MAINTAINER xiaoluo <xiaoluo@test.com>ENV APP_DIR /webadd nginx-1.11.10 /nginx-1.11.10RUN yum -y groupinstall "Development Tools" "Server Platform Deveopment"RUN yum -y install openssl-devel pcre-develRUN useradd nginx -s /sbin/nologinRUN cd /nginx-1.11.10 && ./configure --PRefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module  --with-pcre && make && make installRUN mkdir /usr/local/nginx/conf/vhostsRUN mkdir /var/log/nginxADD nginx.conf /usr/local/nginx/conf/nginx.confADD nginx_default.conf /usr/local/nginx/conf/vhosts/default.confEXPOSE 80CMD ["/usr/local/nginx/sbin/nginx"]

##nginx 相關(guān)php配置:

[root@test nginx]# cat nginx_default.conf server {    listen       80 default_server;    server_name  localhost;    #charset koi8-r;    location / {        root   /web;        index  index.php index.html index.htm;    }    # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   APP_DIR;    }    # Disable nginx log write favicon.ico    location = /favicon.ico {    log_not_found off;    access_log off;        }    # pass the PHP scripts to FastCGI server listening on port 9000    #    location ~ /.php$ {        root           /web;        fastcgi_pass   php:9000;        #fastcgi_pass  unix:/tmp/php-fpm.sock;        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include        fastcgi_params;    }}

###php:9000是通過后面的--link 容器之間互聯(lián)指定

6、開始構(gòu)建nginx鏡像:

[root@test nginx]# docker build -t lnmp/nginx:1.0 .

##查看是否生成鏡像:

[root@test nginx]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZElnmp/nginx          1.0                 5f5d4169189d        4 minutes ago       669 MB

7、開始構(gòu)建php鏡像:

[root@test php-fpm]# cat Dockerfile from centos:centos6ADD Centos-6.repo /etc/yum.repos.d/CentOS-Base.repoADD epel-6.repo /etc/yum.repos.d/epel.repoadd php-5.5.38 /php-5.5.38RUN yum -y groupinstall  "Desktop Platform Development" RUN yum -y install libmcrypt-devel bzip2-devel gcc openssl-devel php-mcrypt libmcryptRUN cd /php-5.5.38 && ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt  --with-bz2 --enable-fpm --with-gd && make && make installRUN cp /php-5.5.38/php.ini-production  /usr/local/php/etc/php.iniRUN mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confRUN useradd -M -s /sbin/nologin phpRUN sed -i -e 's/;pid = run/php-fpm.pid/pid = run/php-fpm.pid/g' -e 's/nobody/php/g' -e 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/g' /usr/local/php/etc/php-fpm.confRUN sed -i 's/;daemonize = yes/daemonize = no/g' /usr/local/php/etc/php-fpm.confEXPOSE 9000CMD ["/usr/local/php/sbin/php-fpm"]

8、開始構(gòu)建php鏡像:

[root@test php-fpm]# docker build -t lnmp/php:1.0 .

9、構(gòu)建mysql鏡像的Dockerfile:

[root@test mysql]# cat Dockerfile FROM centos:centos6  MAINTAINER xiaoluo "18878774@163.com"  RUN yum install -y mysql-server mysql  ADD ./startup.sh /opt/startup.shRUN chmod +x /opt/startup.shEXPOSE 3306CMD ["/bin/bash","/opt/startup.sh"]

##啟動腳本:

[root@test mysql]# cat startup.sh #!/bin/bashif [ ! -f /var/lib/mysql/ibdata1 ]; then        mysql_install_db        /usr/bin/mysqld_safe &        sleep 10s        mysql -e "grant all privileges on *.* to 'root'@'%' identified by '123456'; FLUSH PRIVILEGES;"        killall mysqld        sleep 10sfi/usr/bin/mysqld_safe

**正常啟動的時候,是沒有問題的;當(dāng)時當(dāng)我們用-v做持久化的時候,好像說用戶就失去對/var/lib/mysql的控制權(quán),所以啟動的時候我們要判斷初始化才可以用-v來持久化相關(guān)目錄,這個地方之前搞了好久就是掛不起來,后面原來是這個地方。

10、開始構(gòu)建mysql鏡像:

[root@test mysql]# docker build -t lnmp/mysql:1.0 .

11、下面我們開始啟動相關(guān)容器:

[root@test web]# docker run -dit --name php -v /web:/web lnmp/php:1.0[root@test web]# docker run -dit --name web -p 80:80 -v /web:/web --link php:php lnmp/nginx:1.0[root@test web]#docker run -dit --name mysql -p 3306:3306 -v /opt/data:/var/lib/mysql lnmp/mysql:1.0#####[root@test mysql]# docker psCONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES3527cddb4c50        lnmp/mysql:1.0      "/bin/bash /opt/st..."   4 seconds ago        Up 3 seconds        0.0.0.0:3306->3306/tcp   mysqlfab93953c438        lnmp/nginx:1.0      "/usr/local/nginx/..."   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp       webd5854337c10b        lnmp/php:1.0        "/usr/local/php/sb..."   3 minutes ago        Up 2 minutes        9000/tcp

              php

##可以看到我們已經(jīng)都啟動了所有的容器了。

12、接下來我們登錄一下mysql.創(chuàng)建一下Wordpress使用的數(shù)據(jù)庫

[root@test mysql]# mysql -uroot -p123456 -h 192.168.63.200MySQL [(none)]> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8; Query OK, 1 row affected (0.00 sec)

13、然后我們把wordpress代碼放到我們掛載的本地/web目錄下面:

[root@test web]# wget https://cn.wordpress.org/wordpress-4.7.2-zh_CN.tar.gz

#然后解壓出來。我們直接訪問一下當(dāng)前主機(jī)的IP地址:

face/M5APmN2r3MGkzk2fTCi5TdX5hCGcC8fd.png

直接往下走注冊即可:

face/8Zy62RkxpXHYxH4TiJAfw7CXfZ3SMfz6.png

face/pB2X87Jj4bRiCTf4NXB4zbCC56akHWzH.png

##到此在Docker 分離下安裝wordpress已經(jīng)完成,但是我們要思考一個問題,就是有沒有更好的方法統(tǒng)一編排一下這些容器呢,給容器更好的分組管理:可以留意一下docker-compose,在1.13之后更是結(jié)合棧來實現(xiàn)跨主機(jī)編排。

##還有一個就是如何給這些容器做成集群管理,保證節(jié)點的高可用。和資源監(jiān)控調(diào)度呢。可以看一下1.12之后的docker swarm,構(gòu)建集群非常簡單。

 原文地址:http://www.roncoo.com/article/detail/127431
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 临高县| 会同县| 新巴尔虎右旗| 奉化市| 闽清县| 金华市| 靖江市| 通江县| 英吉沙县| 邵武市| 阳山县| 平定县| 唐海县| 襄垣县| 双牌县| 满洲里市| 天津市| 宜君县| 万年县| 宁河县| 电白县| 汉阴县| 新民市| 故城县| 罗城| 肇东市| 庆元县| 东方市| 内乡县| 双城市| 洞口县| 新沂市| 连南| 吴忠市| 泸水县| 山东省| 射阳县| 会同县| 云南省| 建水县| 万州区|