Kubernetes集群部署discuz

本文基於之前已經完成的k8s集群

首先克隆本項目:git clone https://github.com/donxan/k8s_lnmp_discuzx.git

下載鏡像

<code>#docker pull mysql:5.7 #docker pull richarvey/nginx-php-fpm/<code>

用dockerfile重建nginx-php-fpm鏡像

<code>cd k8s_discuz/dz_web_dockerfile/ docker build -t nginx-php:v1 ./<code>

搭建服務需要的NFS服務

安裝包

<code>#yum install rpcbind nfs-utils -y/<code>

編輯配置文件

<code># cat /etc/exports /data/k8s/ *(sync,rw,no_root_squash)/<code>

啟動服務

<code>#systemctl restart nfs #systemctl enable nfs #ystemctl restart rpcbind #systemctl enable rpcbind/<code>

創建目錄

<code>#mkdir -p /data/k8s/discuz/{db,web}/<code>

搭建MySQL服務

創建secret (設定mysql的root密碼)

<code>#kubectl create secret generic mysql-pass --from-literal=password=123456/<code>

cd /root/k8s_lnmp_discuzx/mysql

<code># mysql-dp.yaml 無需做修改/<code>

<code># mysql-pvc.yaml 無需做修改/<code>

<code># mysql-pv.yaml 更換path和NFS服務的地址/<code>

<code># mysql-svc.yaml 無需做修改/<code>

<code>執行如下的腳本即可 # cat mysql.sh #!/bin/bash kubectl delete -f mysql-svc.yaml kubectl delete -f mysql-dp.yaml kubectl delete -f mysql-pvc.yaml kubectl delete -f mysql-pv.yaml #exit; kubectl apply -f mysql-pv.yaml kubectl apply -f mysql-pvc.yaml kubectl apply -f mysql-dp.yaml kubectl apply -f mysql-svc.yaml /<code>

搭建Nginx+php-fpm服務

注意搭建步驟,在部署mysql時,不能deploy,svc一起執行,需要一步一步來操作。ngx.yaml

<code>#ngx.yaml做如下修改 1、host: dz.ethnicity.cn 2、image: nginx-php:v1 鏡像換成本地的 3、去掉如下內容 imagePullSecrets: - name: harbor-secret #web-dp.yaml做如下修改 1、image: nginx-php:v1 鏡像換成本地的 2、去掉如下內容 imagePullSecrets: - name: harbor-secret #web-pvc.yaml 無需修改 #web-pv.yaml 替換path和NFS服務地址即可 #web-svc.yaml 無需修改 #!/bin/bash kubectl delete -f web-svc.yaml kubectl delete -f web-dp.yaml kubectl delete -f web-pvc.yaml kubectl delete -f web-pv.yaml #exit; kubectl apply -f web-pv.yaml kubectl apply -f web-pvc.yaml kubectl apply -f web-dp.yaml kubectl apply -f web-svc.yaml/<code>

安裝Discuz

<code>下載dz代碼 (到NFS服務器上) cd /tmp/ git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git cd /data/k8s/discuz/web/ mv /tmp/DiscuzX/upload/* . chown -R 755 data uc_server/data/ uc_client/data/ config//<code>

設置MySQL普通用戶

<code>kubectl get svc dz-mysql //查看service的cluster-ip,我的是10.1.89.46 mysql -uroot -h10.1.89.46 -p123456 //這裡的密碼是在上面步驟中設置的那個密碼,連接需要在node上連接(還未找到master不能連接的原因) > create database dz; > grant all on dz.* to 'dz'@'%' identified by '123456';/<code>


使用安裝nginx,配置nginx反向代理(在其中一個node上yum安裝nginx)

<code># cat /etc/nginx/conf.d/dz.conf server { listen 80; server_name dz.ethnicity.cn; location / { proxy_pass http://10.1.18.31:80; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }/<code>