IP | hostname |
192.168.1.1 | node1 |
項目規(guī)劃:
容器網(wǎng)段:172.16.10.0/24
NGINX:172.16.10.10
MySQL:172.16.10.20
PHP:172.16.10.20
網(wǎng)站根目錄:/www
nginx配置文件:/conf
mysql持久化目錄:/var/lib/mysql
提前準(zhǔn)備服務(wù)配置文件:
nginx
<strong>docker run -itd --name test nginx #運(yùn)行test容器 docker cp test:/etc/nginx /conf #copy主配置文件 ls /conf/ conf.d koi-win nginx.conf win-utf fastcgi_params mime.types scgi_params koi-utf modules uwsgi_params docker cp test:/usr/share/nginx/html /www #copy網(wǎng)站目錄 ls /www/ 50x.html index.html </strong>
mysql
<strong>[root@node1 ~]# docker rm -f test test [root@node1 ~]# docker run -itd --name test -e MYSQL_ROOT_PASSWORD=pwd123 mysql:5.7 6b8d73ecd541d454f121302963a85d53131286d3118a968525a24ad2315b047b [root@node1 ~]# docker exec -it test sh # mysql -uroot -ppwd123 -h127.0.0.1 .......... mysql> create database test; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | +--------------------+ 5 rows in set (0.00 sec) mysql> exit Bye # exit [root@node1 ~]# docker cp test:/var/lib/mysql /var/lib/mysql </strong>
1、配置lnmp虛擬網(wǎng)卡,網(wǎng)段172.16.10.0/24,網(wǎng)關(guān)172.16.10.254
<strong>docker network create -d bridge --subnet 172.16.10.0/24 --gateway 172.16.10.254 lnmp </strong>
2、創(chuàng)建nginx容器測試訪問
<strong>#創(chuàng)建mysql掛載數(shù)據(jù)目錄、開發(fā)端口、指定IP [root@node1 ~]# docker run -itd --name mysql -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql --network lnmp --ip 172.16.10.20 mysql:5.7 448227483a9c3141c2155d2c7b027aec263bfcfe4ebc49371b6817c17565ff81 #查看運(yùn)行狀態(tài) [root@node1 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 448227483a9c mysql:5.7 "docker-entrypoint.s…" 10 seconds ago Up 9 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql 4d1e99a06972 nginx:latest "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp nginx 6b8d73ecd541 mysql:5.7 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 3306/tcp, 33060/tcp test #測試登錄 [root@node1 ~]# yum -y install mariadb [root@node1 ~]# mysql -uroot -ppwd123 -h127.0.0.1 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.33 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]> Bye </strong>
3、運(yùn)行MySQL容器
<strong>[root@node1 www]# docker run -itd --name php-fpm -p 9000:9000 -v /www:/usr/share/nginx/html --network lnmp --ip 172.16.10.30 php:7.2-fpm ae09213d7c8c84299b1522ca474fccf7f26e27973cd02563891c37d51799b766 [root@node1 www]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ae09213d7c8c php:7.2-fpm "docker-php-entrypoi…" 7 seconds ago Up 6 seconds 0.0.0.0:9000->9000/tcp php-fpm</strong>
4、創(chuàng)建php-fpm容器
<strong>[root@node1 ~]# vim /conf/conf.d/default.conf </strong>
5、nginx和PHP的連接
5.1、添加nginx靜態(tài)的測試界面
<strong>[root@node1 ~]# echo Hello LNMP! > /www/index.html [root@node1 ~]# cat /www/index.html Hello LNMP! [root@node1 ~]# curl 192.168.1.1 Hello LNMP! </strong>
5.2、添加PHP測試頁面
<strong>[root@node1 ~]# cd /www [root@node1 www]# vim test.php [root@node1 www]# cat test.php <?php phpinfo(); ?> [root@node1 www]# docker restart nginx nginx [root@node1 www]# pwd /www [root@node1 www]# ls 50x.html index.html test.php </strong>
能夠訪問到以上兩個界面,說明nginx和php的連接,沒有問題,接下來是 php和mysql的連接。在這里我們使用一個phpMyAdmin的數(shù)據(jù)庫管理工 具。
6、測試PHP容器與Mysql容器的協(xié)調(diào)性、工具phpMyadmin
[root@node1 www]# pwd /www [root@node1 www]# unzip phpMyAdmin-4.9.0.1-all-languages.zip [root@node1 www]# mv phpMyAdmin-4.9.0.1-all-languages phpMyAdmin [root@node1 www]# rm -rf phpMyAdmin
6.1、更新nginx配置文件
[root@node1 www]# cd /conf/conf.d/ [root@node1 conf.d]# vim default.conf
內(nèi)容如下:
location /phpmyadmin { root /usr/share/nginx/html; index index.php index.html index.htm; } location ~ /phpmyadmin/(?<after_ali>(.*)\.(php|php5)?$) { root /usr/share/nginx/html; fastcgi_pass 172.16.10.30:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
測試訪問:
其實這主要是php鏡像不支持連接mysql,我們要重新寫一個。
7、解決php不關(guān)聯(lián)mysql
[root@node1 /]# cd /file/ [root@node1 file]# ls Dockerfile [root@node1 file]# cat Dockerfile FROM php:7.2-fpm RUN apt-get update && apt-get install -y \ libfreetype6-dev \ libjpeg62-turbo-dev \ libpng-dev \ && docker-php-ext-install -j$(nproc) iconv \ && docker-php-ext-configure gd --with-freetypedir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gd \ && docker-php-ext-install mysqli pdo pdo_mysql [root@node1 file]# docker build -t php_mysql .
#刪除php容器 [root@node1 /]# docker rm php-fpm -f php-fpm #運(yùn)行phpmysql容器 [root@node1 /]# docker run -itd --name phpfpm -p 9000:9000 -v /www:/usr/share/nginx/html --network lnmp --ip 172.16.10.30 phpmysql:latest c4e943880fd51f947cba64ba0006abd26a923439a3e39a0350ca2561b42b8026 [root@node1 /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c4e943880fd5 phpmysql:latest "docker-php-entrypoi…" 14 seconds ago Up 13 seconds 0.0.0.0:9000->9000/tcp phpfpm
7.1、phpmysql配置指向mysql地址
[root@node1 www]# cd /www/phpmyadmin/ [root@node1 phpmyadmin]# mv config.sample.inc.php config.inc.php [root@node1 phpmyadmin]# vim config.inc.php [root@node1 phpmyadmin]# docker restart phpfpm phpfpm
8、訪問測試
9、趁熱打鐵,在發(fā)布一個dz論壇
dz論壇鏈接地址:http://down.chinaz.com/soft/41403.htm
#上傳 [root@node1 /]# ls bin Discuz_X3.4_SC_UTF8_20210119.zip #移動到/www網(wǎng)頁目錄下 mv upload/ /www/dz chmod 777 /www/dz<br>#保證數(shù)據(jù)庫有dz庫<br>#授權(quán)一個dz庫的管理員<br>#注意安裝是IP為數(shù)據(jù)庫的IP不要寫錯<br>
到此這篇關(guān)于docker部署LNMP架構(gòu)的方法的文章就介紹到這了,更多相關(guān)docker部署LNMP架構(gòu)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
標(biāo)簽:鄭州 汕頭 開封 拉薩 晉城 三明 玉林 石嘴山
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《docker部署LNMP架構(gòu)的方法》,本文關(guān)鍵詞 docker,部署,LNMP,架構(gòu),的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。