美文网首页
搭建discuz

搭建discuz

作者: 慕知 | 来源:发表于2021-04-08 18:07 被阅读0次
    
    [root@\ k8s-m-01/opt/discuz]# for i  in n1 n2;do ssh root@$i "mkdir  -pv /opt/discuz" && scp discuz.tar.gz root@$i:/opt/discuz/ ;done
    discuz.tar.gz                                                                                    100% 8618KB  89.7MB/s   00:00    
    discuz.tar.gz                                                                                    100% 8618KB  81.3MB/s   00:00    
    [root@\ k8s-m-01/opt/discuz]# for i  in n1 n2;do ssh root@$i "tar -xf /opt/discuz/discuz.tar.gz -C /opt/discuz && chmod -R o+w /opt/discuz";done
    
    
    
    # 配置清单
    [root@\ k8s-m-01~]# vim discuz.yaml 
    apiVersion: v1
    kind: Namespace
    metadata:
      name: mysql
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: mysql-svc
      namespace: mysql
    spec:
      ports:
        - port: 3306
          targetPort: 3306
          name: mysql
          protocol: TCP
      selector:
        app: mysql
        deploy: discuz
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mysql-deployment
      namespace: mysql
    spec:
      selector:
        matchLabels:
          app: mysql
          deploy: discuz
      template:
        metadata:
          labels:
            app: mysql
            deploy: discuz
        spec:
          nodeName: k8s-n-02
          containers:
            - name: mysql
              image: mysql:5.7
              livenessProbe:
                tcpSocket:
                  port: 3306
              readinessProbe:
                tcpSocket:
                  port: 3306
              env:
                - name: MYSQL_ROOT_PASSWORD
                  value: "123456"
                - name: MYSQL_DATABASE
                  value: "discuz"
              volumeMounts:
                - mountPath: /var/lib/mysql
                  name: mysql-data
          volumes:
            - name: mysql-data
              hostPath:
                path: /opt/discuz/mysql
    ---
    kind: Namespace
    apiVersion: v1
    metadata:
      name: discuz
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: discuz-svc
      namespace: discuz
    spec:
      clusterIP: None
      ports:
        - port: 80
          targetPort: 80
          name: http
      selector:
        app: discuz
        deploy: discuz
    ---
    kind: Deployment
    apiVersion: apps/v1
    metadata:
      name: discuz-deployment
      namespace: discuz
    spec:
      selector:
        matchLabels:
          app: discuz
          deploy: discuz
      template:
        metadata:
          labels:
            app: discuz
            deploy: discuz
        spec:
          nodeName: k8s-n-01
          containers:
            - name: php
              image: alvinos/php:wordpress-v2
              livenessProbe:
                tcpSocket:
                  port: 9000
              readinessProbe:
                tcpSocket:
                  port: 9000
              volumeMounts:
                - mountPath: /usr/share/nginx/html
                  name: discuz-data
            - name: nginx
              image: alvinos/nginx:wordpress-v2
              livenessProbe:
                httpGet:
                  port: 80
                  path: /
              readinessProbe:
                httpGet:
                  port: 80
                  path: /
              volumeMounts:
                - mountPath: /usr/share/nginx/html
                  name: discuz-data
          volumes:
            - name: discuz-data
              hostPath:
                path: /opt/discuz/upload
    ---
    kind: Ingress
    apiVersion: extensions/v1beta1
    metadata:
      name: discuz-ingress
      namespace: discuz
    spec:
      tls:
        - hosts:
            - www.discuz.cluster.local.com
          secretName: discuz-secret
      rules:
        - host: www.discuz.cluster.local.com
          http:
            paths:
              - backend:
                  serviceName: discuz-svc
                  servicePort: 80
    
    
    
    
    
    
    
    
    
    
    
    
    检测一:
    [root@\ k8s-n-02~]# cd /opt/discuz/
    [root@\ k8s-n-02/opt/discuz]# ll
    total 8628
    -rw-r--rw-.  1 root    root 8825289 Apr  8 16:49 discuz.tar.gz
    drwxr-xr-x.  6 polkitd root    4096 Apr  8 17:02 mysql
    drwxr-xrwx. 12 root    root    4096 Jul 27  2017 upload
    
    
    
    
    检测二:
    
    [root@\ k8s-m-01~]# kubectl get svc -n mysql
    NAME        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
    mysql-svc   ClusterIP   10.102.131.188   <none>        3306/TCP   24s
    [root@\ k8s-m-01~]# kubectl get pods -n mysql -o wide
    
    # 查看是在指定的node02上
    NAME                                READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
    mysql-deployment-77d4559f4c-c67hp   0/1     Running   0          46s   10.244.2.27   k8s-n-02   <none>           <none>
    [root@\ k8s-m-01~]# kubectl exec -n mysql -it mysql-deployment-77d4559f4c-c67hp 
    error: you must specify at least one command for the container
    
    [root@\ k8s-m-01~]# kubectl exec -n mysql -it mysql-deployment-77d4559f4c-c67hp -- bash
    root@mysql-deployment-77d4559f4c-c67hp:/# mysql -u root -p123456
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | discuz             |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    5 rows in set (0.00 sec)
    
    
    
    
    
    
    
    
    
    # 查看容器是否启动
    [root@\ k8s-m-01~]# kubectl get pods -n mysql 
    NAME                                READY   STATUS    RESTARTS   AGE
    mysql-deployment-77d4559f4c-nlb2p   0/1     Running   0          12s
    [root@\ k8s-m-01~]# kubectl get pods -n discuz 
    NAME                                 READY   STATUS    RESTARTS   AGE
    discuz-deployment-7c74ccd676-xd7p4   2/2     Running   0          19s
    [root@\ k8s-m-01~]# kubectl get deployments.apps -n discuz 
    NAME                READY   UP-TO-DATE   AVAILABLE   AGE
    discuz-deployment   1/1     1            1           26s
    [root@\ k8s-m-01~]# kubectl get deployments.apps -n mysql 
    NAME               READY   UP-TO-DATE   AVAILABLE   AGE
    mysql-deployment   1/1     1            1           33s
    [root@\ k8s-m-01~]# kubectl get svc -n ingress-nginx 
    NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
    ingress-nginx-controller             NodePort    10.102.254.20   <none>        80:30654/TCP,443:31066/TCP   6d2h
    ingress-nginx-controller-admission   ClusterIP   10.111.163.84   <none>        443/TCP                      6d2h
    [root@\ k8s-m-01~]# kubectl get ingress -n discuz 
    NAME             CLASS    HOSTS                          ADDRESS         PORTS     AGE
    discuz-ingress   <none>   www.discuz.cluster.local.com   192.168.15.33   80, 443   62s
    
    
    
    
    
    
    
    解析hosts访问
    
    
    
    image.png

    相关文章

      网友评论

          本文标题:搭建discuz

          本文链接:https://www.haomeiwen.com/subject/qgsvkltx.html