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>


Kubernetes集群部署discuz


分享到:


相關文章: