1, 配置nfs存儲卷
1,在docker swarm集群中所有節點都確認安裝nfs客戶端軟件
# yum install nfs-utils rpcbind -y
2, 在192.168.122.1 上搭建nfs,共享目錄給docker swarm集群中所有節點掛載
[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集群中所有節點創建存儲卷,并驗證
# 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",
注意這里的掛載參數要有
"type": "nfs"
},
"Scope": "local"
}
# docker volume ls |grep nginx_volume
local nginx_volume
# docker volume create --driver local --opt type=nfs --opt o=addr=192.168.122.1,rw --opt device=:/opt/dockervolume
nginx_volume
在任意能上外網的機器上操作
[root@nfs ~]# docker pull richarvey/nginx-php-fpm
[root@nfs ~]# mkdir /root/discuz/dockerfile -p
[root@nfs ~]# cd /root/discuz/dockerfile
準備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;
}
準備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;
}
}
準備時區文件
[root@nfs dockerfile]# cp /etc/localtime .
準備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
編寫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
構建鏡像
[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
編寫YMAL文件
在docker swarm集群中的管理節點進行操作
[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"
一鍵發布stack
[root@manager ~]# docker stack deploy -c discuz2.yml discuz
Creating network discuz_default
Creating service discuz_db
Creating service discuz_nginx-php
在nfs服務器上操作
[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
[root@nfs dockerfile]# chmod o+w -R /opt/dockervolume/
上圖少了-R參數,請加上
、了解Linux軟件的安裝方式
2、掌握更新yum源
3、掌握YUM軟件安裝方式
4、了解LAMP環境以及AMP的關系
5、了解阿里云ECS的創建過程
6、能夠yum方式搭建lamp環境
7、能夠實現Discuz!論壇部署
8、能夠購買域名與解析域名
? 學員小白,目前剛入職了一家電子商務公司。主要負責大型商城系統維護,公司主營母嬰用品,如奶瓶、奶嘴、童裝等等,最近,很多客服發現一個問題:很多寶媽會在評論區互相咨詢產品相關信息。
? 于是公司決定針對這一需求,要求運維為公司迅速上線一款論壇系統,方便寶媽交流產品、育兒心得等等。
? 滿足功能,并且省錢
Discuz! = Apache + PHP + MySQL
在CentOS系統中,軟件管理方式通常有三種方式:rpm安裝、yum安裝以及編譯安裝。
編譯安裝,從過程上來講比較麻煩,包需要用戶自行下載,下載的是源碼包,需要進行編譯操作,編譯好了才能進行安裝,這個過程對于剛接觸Linux的人來說比較麻煩,而且還容易出錯。好處在于是源碼包,對于有需要自定義模塊的用戶來說非常方便。(就業班會著重講解)
? Yum(全稱為 Yellow dog Updater, Modified)是一個在Fedora和RedHat以及CentOS中的Shell前端軟件包管理器。
? 基于rpm包管理,能夠從指定的服務器(yum源)自動下載RPM包并且安裝,可以==自動處理依賴性關系==,并且==一次安裝所有依賴的軟件包==,無須繁瑣地一次次下載、安裝。
yum配置文件位置
#cd /etc/yum.repos.d/
#ll
-rw-r--r--. 1 root root 1991 Mar 28 2017 CentOS-Base.repo 網絡yum源配置文件 -rw-r--r--. 1 root root 647 Mar 28 2017 CentOS-Debuginfo.repo 內核相關的更新包 -rw-r--r--. 1 root root 289 Mar 28 2017 CentOS-fasttrack.repo 快速通道 -rw-r--r--. 1 root root 630 Mar 28 2017 CentOS-Media.repo 本地yum源配置文件 -rw-r--r--. 1 root root 7989 Mar 28 2017 CentOS-Vault.repo 最近版本加入老本的YUM配置
? 使用阿里yum源代替系統默認的yum源
① 備份默認源
#cd /etc/yum.repos.d/
#mv CentOS-Base.repo CentOS-Base.repo.bak
② 下載新CentOS-Base.repo
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
含義:使用阿里云的yum源代替默認的yum源,下載軟件更快
③ 清除所有緩存
#yum clean all
④ 重新生成緩存
#yum makecache
http://mirrors.aliyun.com/repo/選擇不同centos版本的yum源
語法:# yum search 關鍵詞
語法:# yum [-y] install 關鍵詞
語法:# yum [-y] remove 關鍵詞
語法:#yum [-y] update [包的關鍵詞]
特別注意:包的關鍵詞如果不寫,則表示更新整個系統(全局更新,也包含內核)
LAMP:==L==inux + ==A==pache + ==M==ySQL + ==P==HP LAMP 架構(組合)
LNMP:Linux + Nginx + MySQL + php-fpm LNMP 架構(組合)
LNMPA:Linux + Nginx(80) + MySQL + PHP + Apache Nginx 代理方式
Apache:Apache是世界使用排名第一的Web服務器軟件。
PHP:一種專門用于Web開發的編程語言。
MySQL:MySQL是一個關系型數據庫管理系統,主要用于永久存儲項目數據。
? 要想部署一個互聯網上可以訪問到的環境,必須先具備以下內容 :
服務器(IP、帳號密碼、終端)、相應的軟件、域名(備案、解析)、代碼等。
阿里云官網:https://www.aliyun.com/
步驟1:鼠標移動到屏幕右上角的頭像,在彈出菜單中選擇實名認證
步驟2:在認證頁面,需選擇個人實名認證
步驟3:選擇支付寶授權認證
步驟4:勾選同意,點擊提交
步驟5:支付寶掃描二維碼,手機上選擇確認登錄
步驟6:填寫相關信息,點擊確認
#systemctl stop firewalld
#setenforce 0
臨時關閉
#getenforce
查看當前是否關閉了selinux
#vim /etc/selinux/config
編輯selinux配置文件,永久關閉
使用rpm命令
使用rpm命令
使用rpm命令
建議使用一臺新裝的Linux,因為卸載如果有殘留,也容易給后續搭建帶來未知的問題。
① 使用yum命令安裝httpd軟件包
② 配置/etc/httpd/conf/httpd.conf文件
搜索ServerName,在下面添加一行:
ServerName Localhost:80
#vim /etc/httpd/conf/httpd.conf
ServerName localhost:80
問題:保存退出用什么命令?
答:
③ 使用systemctl命令重啟httpd服務,使用netstat -ntlp命令,查看是否有80端口監聽
④ 設置httpd服務開機啟動
⑤ 查看本機的IP地址,阿里云服務器從控制臺可以看到
⑥在瀏覽器中,輸入本機IP地址,如下圖所示:
注意:自己的服務器在設置時,一定要管理防火墻與SELinux,避免產生異常
① 關閉防火墻 命令:# service iptables stop
② 關系SELinux 命令:# setenforce 0
由于yum源上默認沒有mysql-server。所以必須去官網下載后在安裝
#wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
含義:下載myslq的yum源
#rpm -ivh mysql-community-release-el7-5.noarch.rpm
含義:安裝mysql的yum源存儲庫包
#yum -y install mysql-community-server
#systemctl restart mysqld.service
#netstat -ntlp
? 默認情況下,數據庫沒有密碼,也沒有任何數據,必須要初始化
#mysql_secure_installation
含義:mysql自己帶的初始化程序
設置超級管理員root密碼,注:默認為空,直接回車即可
移除匿名賬戶:
不禁用root遠程連接:
不移除默認數據庫(測試用例):
重新加載權限:Y
提示已完成,感謝使用MySQL
? 默認已經開機啟動,這里可以跳過
#mysql -uroot -p
含義:-u是參數,后面跟用戶名,沒有空格
-p表示密碼
看到mysql>表示已經連接到mysql
myslq> show databases;
含義:顯示所有數據庫
注意:命令結尾要有“;”
mysql>下輸入exit,退出mysql,回到#提示符
① 使用yum命令安裝php、
#yum -y install php
#systemctl restart httpd
② 重啟httpd服務
? 更改php配置一定要重啟httpd服務
③ 測試LAMP環境是否可以使用
第一步:使用cd命令進入/var/www/html目錄
第二步:使用vim命令創建index.php文件
第三步:編寫php代碼
代碼示例:
#cd /var/www/html/
#vim index.php
<?php
echo 'hello world';
?>
第四步:在瀏覽器,輸入公網IP,如下圖所示:
Discuz!是一套開源的社區論壇軟件系統。
下載地址:https://gitee.com/ComsenzDiscuz/DiscuzX
1)把ComsenzDiscuz-DiscuzX-master.zip文件通過MobaXterm上傳到ECS服務器的/usr/local目錄
2)安裝unzip命令并且解壓縮論壇代碼
#yum -y install unzip
#unzip ComsenzDiscuz-DiscuzX-master.zip
含義:解壓縮ComsenzDiscuz-DiscuzX-master.zip文件
#ll
解壓縮后,得到DiscuzX目錄,其中upload文件夾下是真正的網站代碼文件
3)將網站代碼拷貝到/var/www/html下
示例代碼:
#cp -r /usr/local/DiscuzX/upload/* /var/www/html/
#cd /var/www/html/
#ll
? 首先查看Discuz!源代碼文件是否已經上傳完成,必須完成后,才可以進行Discuz!論壇安裝。
看到下面的頁面表示訪問成功,點擊我同意
如上圖所示,系統提示很多文件沒有可寫權限,設置如下:
#chmod -R a+w /var/www/html/
重新刷新,如下圖所示:
如上圖所示:以上結果代表系統缺少php-mysqli擴展,安裝后即可解決。
① 使用yum命令安裝php-mysqli擴展
#yum -y install php-mysqli
② 重啟httpd服務
重新刷新網頁,如下圖所示:
? 開始安裝頁面已經沒有任何報錯,點擊下一步,進入設置運行環境頁面
進入論壇首頁,如下圖所示:
到此,關于LAMP環境配置與開源Discuz!項目實戰就全部搞定了!
? 我們現在訪問論壇是通過IP地址實現的,但是IP地址比較復雜,更重要的是不方便用戶記憶。
1)登錄阿里云控制臺
https://account.aliyun.com/
2)登錄后選擇阿里云首頁右上角的控制臺,鼠標移動到左上角會出現如下菜單,選擇域名
3)點擊域名注冊:
輸入一個想注冊的域名名稱,例如ityunweiketangyanshi
如下圖所示:
加入清單,立即結算:
配置域名持有者,學習環境直接選擇個人即可:
現在國家要求實名制,所以還要創建信息模板,點擊創建信息模板
點擊頁面右上角,創建新信息模板
添加完個人信息后,回到訂單頁面刷新,重新選擇個人,會看到自己添加的信息模板,還要認證郵箱,就是往你注冊的郵箱里發一封郵件,需要登錄郵箱,點擊驗證鏈接,最終完成信息登記
看到如下頁面:
勾選:我已閱讀,理解并接受,然后單擊立即購買,支付,如下圖所示:
① 點擊控制臺,右側菜單選擇域名,進入域名管理頁面
點擊解析按鈕
② 添加A記錄
將http://www.ketangyanshi.com 指向公網IP
點擊確定,完成設置。幾分鐘后就可以通過域名訪問剛剛搭建的網站了。
注意:由于國家要求,域名解析需要首先實名制認證,所以目前我這個域名無法實際使用,我還沒有完成實名制認證
近用 Discuz 搭建了個網站——(www.91kaiye.cn),用到了門戶功能,不得不說Discuz 的功能還是非常強大的,但在使用過程中發現在發表文章時添加了圖片卻不能像 WordPress 這樣自動添加 alt 標簽,經過一番研究,初步解決了這個問題,目前還沒有 Bug,等待長時間驗證,方法如下:
在實施本方法之前請先備份網站數據,以防不測;這次修改需要修改兩個文件,分別是:
static/image/editor/editor_function.js
template/default/home/spacecp_blog.htm
同時增加一個文件為:
static/image/editor/editor_function.js–復制一份,重命名為:bgeditor_function.js
下面開始修改:editor_function.js
查找代碼:
function insertImage(image, url, width, height) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
修改為:
function insertImage(image, url, width, height, subject) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
subject = $('title').value;
var html = '<p><a href="' + url + '" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
再修改剛剛建立的bgeditor_function.js
同樣查找代碼:
function insertImage(image, url, width, height) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
修改為:
function insertImage(image, url, width, height, subject) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
var html = '<p><a href="' + url + '" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
再編輯:template/default/home/spacecp_blog.htm
查找:editor_function.js
替換為:bgeditor_function.js
編輯完畢保存,把文件上傳到原來位置,增加的bgeditor_function.js與editor_function.js一塊放在同一目錄。后臺發布一片文章,輸入文章標題,上傳圖片,進入源代碼模式,看看圖片是不是有了 alt 標簽?
效果如圖:
*請認真填寫需求信息,我們會在24小時內與您取得聯系。