Discuz壓縮包:
內存 | ip | 軟件 | |
---|---|---|---|
docker01 | 2G | 10.0.0.11 | docker |
docker02 | 2G | 10.0.0.12 |
1. docker01安裝
🥥yum源優化
#centos 7鏡像源 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #centos 6鏡像源 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
🍇安裝方式一:在線安裝
#安裝docker-ce wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo #將國外地址改成國內地址 sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo yum install docker-ce -y systemctl enable docker systemctl start docker #驗證 [root@docker01 yum.repos.d]# docker version Client: Docker Engine - Community Version: 19.03.5 API version: 1.40 Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:25:41 2019 OS/Arch: linux/amd64 Experimental: false
🍈方式二:離線安裝
鏈接:https://pan.baidu.com/s/1RFd5GSzFDjtjMM6uhC3l8Q
提取碼:5yes
tar xf docker_rpm.tar.gz yum localinstall docker_rpm/*.rpm -y #驗證 docker version
2.創建Discuz論壇目錄用於掛載
[root@docker01 /]# mkdir /bbs [root@docker01 bbs]# mv readme/* /bbs/ && mv upload/* /bbs/ && mv utility/* /bbs/ [root@docker01 bbs]# rm -rf Discuz_X3.3_SC_GBK.zip
1.
#將鏡像上傳到本地,查看鏡像 [root@docker01 ~]# docker ps #創建鏡像安裝軟件 [root@docker01 ~]# docker run -d -it -p 80:80 -v /bbs/:/usr/share/nginx/html centos:6.9 [root@docker01 ~]# docker ps -a --查看id號 [root@docker01 ~]# docker exec -it 052a6c61b293 /bin/bash - #更新yum源 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
報錯解決:
#問題:虛擬機無法連接外網 #解決:重啟docker systemctl restart docker [root@docker01 ~]# docker run -d -it -p 80:80 -v /bbs/:/usr/share/nginx/html centos:6.9
[root@cb5ec42c3dec /]# yum install nginx php-fpm php-mbstring php-mysql -y [root@cb5ec42c3dec /]# service nginx start # mbstring:擴展 是針對php部分函數(比如 mb_strlen() 函數)該函數就需要改擴展 # php-fpm是個中間件,在需要php解釋器來處理.php文本時會用到php-fpm # php-mysql 連接到一個 MySQL 數據庫
2. 確認程序用戶信息
🍆備注:確認PHP程序用戶信息和nginx程序保持一致
# 檢查nginx程序所使用的用戶信息 [root@oldboyedu ~]# ps -ef|grep nginx nginx 5384 5380 0 04:16 ? 00:00:00 nginx: worker process # 修改php程序所使用的用戶信息 vim /etc/php-fpm.d/www.conf user = nginx group = nginx
3. 啟動軟件程序服務
service php-fpm start # 啟動PHP服務程序 chkconfig --add php-fpm --開機自啟 ps -ef|grep php # 檢查啟動進程信息 # 檢查啟動端口信息 netstat -lntup|grep php
4. 網站結構服務配置過程
🍏nginx + php 建立關系:
[root@cb5ec42c3dec blog]# cat /etc/nginx/conf.d/default.conf # # The default server # server { listen 80 default_server; listen [::]:80 default_server; server_name _; location / { root /usr/share/nginx/html; index index.php index.html; } location ~ \.php$ { root /blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; } # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
5. 編寫測試php文件
# cat /blog/test_index.php <?php phpinfo(); ?>
6. 谷歌輸入地址驗證
http://10.0.0.11/test_index.php #顯示php安裝完成
測試網頁:
7. 授權站點目錄
[root@cb5ec42c3dec ~]# nginx -t [root@cb5ec42c3dec /]# chown -R nginx.nginx /usr/share/nginx/html/ [root@cb5ec42c3dec blog]# service nginx restart
8. 創建啟動腳本
[root@cb5ec42c3dec /]# vi /init.sh #!/bin/bash service php-fpm start nginx -g 'daemon off;'
在前期如果沒有安裝 php-mysql 模塊會出現沒有函數的錯誤,下面時模擬報錯
php-mysql:
yum install php-mysql -y service php-fpm restart
1. 下載安裝軟件程序
yum install mariadb-server mariadb -y
2. 啟動軟件服務程序
systemctl start mariadb.service # 啟動數據庫程序服務進程
systemctl enable mariadb.service
3. 數據庫創建密碼登錄
mysqladmin -uroot password "123456" mysql -uroot -p123456
4. 設置連接數據庫,進入數據庫創建
#創建以wordpress命名的數據庫 create database discuz; #創建並授權用戶信息 grant all on discuz.* to 'discuz'@'10.0.0.%' identified by '123456'; exit #關閉數據庫反向解析操作(跳過反向解析過程) # delete from mysql.user where user='discuz' and host='discuz'; --刪除表信息 #刪除時操作 # flush privileges;
1. 把制作好服務的容器,提交為鏡像
docker commit 052a6c61b293 bbs:v1 -- id唯一提前查好
🍓注:模擬端口被占用的錯誤
32405be2ec68a8e35ef60f753946a2c4af431be53e97885068b9004f39b239af docker: Error response from daemon: driver failed programming external connectivity on endpoint trusting_hypatia (145e1d6c48bcc7e07f996476969d6c7bdf84657319429ae0e3ef2f92549ff3c9): Bind for 0.0.0.0:80 failed: port is already allocated. #翻譯:綁定0.0.0.0:80失敗:端口已經分配。
2. 測試鏡像功能
#直接進入虛擬機 docker run -it -p 83:80 -v /bbs/:/usr/share/nginx/html bbs:v1
3. 測試網頁,連接數據庫直接可以使用