• 15.交付apollo-configservice到K8S


    1.安装数据库mariadb并配置mariadb

    [root@hdss7-11 ~]# vim /etc/yum.repos.d/mariadb.repo 
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.1.45/centos7-amd64/
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    [root@hdss7-11 ~]# vim /etc/my.cnf.d/server.cnf 
    [mysqld]
    character_set_server = utf8mb4
    collation_server = utf8mb4_general_ci
    init_connect = "SET NAMES 'utf8mb4'"
    [root@hdss7-11 ~]# vim /etc/my.cnf.d/mysql-clients.cnf 
    [mysql]
    default-character-set = utf8mb4
    [root@hdss7-11 ~]# systemctl start mariadb
    [root@hdss7-11 ~]# systemctl enable mariadb
    [root@hdss7-11 ~]# mysqladmin -uroot password
    [root@hdss7-11 ~]# mysql -uroot -p
    MariaDB [(none)]> s
    --------------
    mysql  Ver 15.1 Distrib 10.1.45-MariaDB, for Linux (x86_64) using readline 5.1
    
    Connection id:        5
    Current database:    
    Current user:        root@localhost
    SSL:            Not in use
    Current pager:        stdout
    Using outfile:        ''
    Using delimiter:    ;
    Server:            MariaDB
    Server version:        10.1.45-MariaDB MariaDB Server
    Protocol version:    10
    Connection:        Localhost via UNIX socket
    Server characterset:    utf8mb4
    Db     characterset:    utf8mb4
    Client characterset:    utf8mb4
    Conn.  characterset:    utf8mb4
    UNIX socket:        /var/lib/mysql/mysql.sock
    Uptime:            23 min 23 sec
    
    Threads: 1  Questions: 21  Slow queries: 0  Opens: 18  Flush tables: 1  Open tables: 12  Queries per second avg: 0.014
    --------------

    2.导入configdb脚本并授权

    sql下载地址:https://github.com/ctripcorp/apollo/blob/1.5.1/scripts/db/migration/configdb/V1.0.0__initialization.sql

    [root@hdss7-11 configdb]# mysql -uroot -p < /root/apolloconfig.sql 
    [root@hdss7-11 configdb]# mysql -uroot -p
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | ApolloConfigDB     |
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    4 rows in set (0.00 sec)
    
    MariaDB [(none)]> use ApolloConfigDB;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    MariaDB [ApolloConfigDB]> show tables;
    +--------------------------+
    | Tables_in_ApolloConfigDB |
    +--------------------------+
    | App                      |
    | AppNamespace             |
    | Audit                    |
    | Cluster                  |
    | Commit                   |
    | GrayReleaseRule          |
    | Instance                 |
    | InstanceConfig           |
    | Item                     |
    | Namespace                |
    | NamespaceLock            |
    | Release                  |
    | ReleaseHistory           |
    | ReleaseMessage           |
    | ServerConfig             |
    +--------------------------+
    15 rows in set (0.00 sec)
    MariaDB [ApolloConfigDB]> grant INSERT,DELETE,UPDATE,SELECT on ApolloConfigDB.* to "apollocinfig"@"10.4.7.%" identified by "admin@123";
    MariaDB [ApolloConfigDB]> select user.host from mysql.user;

    3.修改初始数据

    MariaDB [(none)]> use ApolloConfigDB;
    MariaDB [ApolloConfigDB]> update ApolloConfigDB.ServerConfig set ServerConfig.Value="http://config.fx.com/eureka" where ServerConfig.key="eureka.service.url";
    MariaDB [ApolloConfigDB]> select * from ServerConfigG
    *************************** 1. row ***************************
                           Id: 1
                          Key: eureka.service.url
                      Cluster: default
                        Value: http://config.fx.com/eureka
                      Comment: Eureka服务Url,多个service以英文逗号分隔
                    IsDeleted:  
         DataChange_CreatedBy: default
       DataChange_CreatedTime: 2020-06-22 11:34:41
    DataChange_LastModifiedBy: 
          DataChange_LastTime: 2020-06-22 13:00:16
    *************************** 2. row ***************************
                           Id: 2
                          Key: namespace.lock.switch
                      Cluster: default
                        Value: false
                      Comment: 一次发布只能有一个人修改开关
                    IsDeleted:  
         DataChange_CreatedBy: default
       DataChange_CreatedTime: 2020-06-22 11:34:41
    DataChange_LastModifiedBy: 
          DataChange_LastTime: 2020-06-22 11:34:41
    *************************** 3. row ***************************
                           Id: 3
                          Key: item.key.length.limit
                      Cluster: default
                        Value: 128
                      Comment: item key 最大长度限制
                    IsDeleted:  
         DataChange_CreatedBy: default
       DataChange_CreatedTime: 2020-06-22 11:34:41
    DataChange_LastModifiedBy: 
          DataChange_LastTime: 2020-06-22 11:34:41
    *************************** 4. row ***************************
                           Id: 4
                          Key: item.value.length.limit
                      Cluster: default
                        Value: 20000
                      Comment: item value最大长度限制
                    IsDeleted:  
         DataChange_CreatedBy: default
       DataChange_CreatedTime: 2020-06-22 11:34:41
    DataChange_LastModifiedBy: 
          DataChange_LastTime: 2020-06-22 11:34:41
    *************************** 5. row ***************************
                           Id: 5
                          Key: config-service.cache.enabled
                      Cluster: default
                        Value: false
                      Comment: ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!
                    IsDeleted:  
         DataChange_CreatedBy: default
       DataChange_CreatedTime: 2020-06-22 11:34:41
    DataChange_LastModifiedBy: 
          DataChange_LastTime: 2020-06-22 11:34:41

    4.配置DNS解析域名

    [root@hdss7-11 ~]# vim /var/named/fx.com.zone
    $ORIGIN fx.com.
    $TTL 600        ; 10 minutes
    @               IN SOA  dns.fx.com. dnsadmin.fx.com. (
                            2020061012  ; serial
                             10800      ; refresh (3 hours)
                             900        ; retry (15 minutes)
                             604800     ; expire (1 week)
                             86400      ; minimum (1 day)
                             )
                            NS      dns.fx.com.
    $TTL 60 ; 1 minute
    dns             A       10.4.7.11
    harbor          A       10.4.7.200
    k8s-yaml        A       10.4.7.200
    traefik         A       10.4.7.10
    dashboard       A       10.4.7.10
    zk1             A       10.4.7.11
    zk2             A       10.4.7.12
    zk3             A       10.4.7.21
    jenkins         A       10.4.7.10
    dubbo-monitor   A       10.4.7.10
    demo            A       10.4.7.10
    config          A       10.4.7.10
    [root@hdss7-11 ~]# systemctl restart named

    5.制作docker镜像

    apollo下载地址:https://github.com/ctripcorp/apollo/releases/download/v1.5.1/apollo-configservice-1.5.1-github.zip

    [root@hdss7-200 ~]# mkdir /data/dockerfile/apollo-configservice
    [root@hdss7-200 src]# unzip -o apollo-configservice-1.5.1-github.zip -d /data/dockerfile/
    [root@hdss7-200 src]# cd /data/dockerfile/apollo-configservice/
    [root@hdss7-200 apollo-configservice]# rm -rf apollo-configservice-1.5.1-sources.jar 
    [root@hdss7-200 config]# cd /data/dockerfile/apollo-configservice/config/
    [root@hdss7-200 config]# vim application-github.properties 
    spring.datasource.url = jdbc:mysql://mysql.fx.com:3306/ApolloConfigDB?characterEncoding=utf8
    spring.datasource.username = apolloconfig
    spring.datasource.password = admin@123
    [root@hdss7-200 scripts]# cd /data/dockerfile/apollo-configservice/scripts/
    [root@hdss7-200 scripts]# rm -rf shutdown.sh 
    [root@hdss7-200 scripts]# vim startup.sh 
    #!/bin/bash
    SERVICE_NAME=apollo-configservice
    ## Adjust log dir if necessary
    LOG_DIR=/opt/logs/apollo-config-server
    ## Adjust server port if necessary
    SERVER_PORT=8080
    APOLLO_CONFIG_SERVICE_NAME=$(hostname -i)
    SERVER_URL="http://${APOLLO_CONFIG_SERVICE_NAME}:${SERVER_PORT}"
    
    ## Adjust memory settings if necessary
    #export JAVA_OPTS="-Xms128m -Xmx6144m -Xss128k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:SurvivorRatio=8"
    
    ## Only uncomment the following when you are using server jvm
    #export JAVA_OPTS="$JAVA_OPTS -server -XX:-ReduceInitialCardMarks"
    
    ########### The following is the same for configservice, adminservice, portal ###########
    export JAVA_OPTS="$JAVA_OPTS -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+DisableExplicitGC -XX:+ScavengeBeforeFullGC -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom"
    export JAVA_OPTS="$JAVA_OPTS -Dserver.port=$SERVER_PORT -Dlogging.file=$LOG_DIR/$SERVICE_NAME.log -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/"
    
    # Find Java
    if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
        javaexe="$JAVA_HOME/bin/java"
    elif type -p java > /dev/null 2>&1; then
        javaexe=$(type -p java)
    elif [[ -x "/usr/bin/java" ]];  then
        javaexe="/usr/bin/java"
    else
        echo "Unable to find Java"
        exit 1
    fi
    
    if [[ "$javaexe" ]]; then
        version=$("$javaexe" -version 2>&1 | awk -F '"' '/version/ {print $2}')
        version=$(echo "$version" | awk -F. '{printf("%03d%03d",$1,$2);}')
        # now version is of format 009003 (9.3.x)
        if [ $version -ge 011000 ]; then
            JAVA_OPTS="$JAVA_OPTS -Xlog:gc*:$LOG_DIR/gc.log:time,level,tags -Xlog:safepoint -Xlog:gc+heap=trace"
        elif [ $version -ge 010000 ]; then
            JAVA_OPTS="$JAVA_OPTS -Xlog:gc*:$LOG_DIR/gc.log:time,level,tags -Xlog:safepoint -Xlog:gc+heap=trace"
        elif [ $version -ge 009000 ]; then
            JAVA_OPTS="$JAVA_OPTS -Xlog:gc*:$LOG_DIR/gc.log:time,level,tags -Xlog:safepoint -Xlog:gc+heap=trace"
        else
            JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
            JAVA_OPTS="$JAVA_OPTS -Xloggc:$LOG_DIR/gc.log -XX:+PrintGCDetails"
            JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:+CMSClassUnloadingEnabled  -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=5M"
        fi
    fi
    
    printf "$(date) ==== Starting ==== 
    "
    
    cd `dirname $0`/..
    chmod 755 $SERVICE_NAME".jar"
    ./$SERVICE_NAME".jar" start
    
    rc=$?;
    
    if [[ $rc != 0 ]];
    then
        echo "$(date) Failed to start $SERVICE_NAME.jar, return code: $rc"
        exit $rc;
    fi
    
    tail -f /dev/null
    [root@hdss7-200 apollo-configservice]# vim Dockerfile
    FROM harbor.fx.com/public/jre:8u112
    ENV VERSION 1.5.1
    RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&
        echo "Asia/Shanghai" > /etc/timezone && mkdir -p /apollo-adminservice/scripts
    ADD apollo-configservice-${VERSION}.jar /apollo-configservice/apollo-configservice.jar
    ADD config/ /apollo-configservice/config
    ADD scripts/ /apollo-configservice/scripts
    CMD ["/apollo-configservice/scripts/startup.sh"]
    [root@hdss7-200 apollo-configservice]# docker build . -t harbor.fx.com/infra/apollo-configservice:v1.5.1
    [root@hdss7-200 apollo-configservice]# docker push harbor.fx.com/infra/apollo-configservice:v1.5.1

    6.准备资源配置清单

    [root@hdss7-200 k8s-yaml]# mkdir /data/k8s-yaml/apollo-configservice
    [root@hdss7-200 k8s-yaml]# cd /data/k8s-yaml/apollo-configservice/

    configmap.yaml

    [root@hdss7-200 apollo-configservice]# vim configmap.yaml 
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: apollo-configservice-cm
      namespace: infra
    data:
      application-github.properties: |
        # DataSource
        spring.datasource.url = jdbc:mysql://mysql.fx.com:3306/ApolloConfigDB?characterEncoding=utf8
        spring.datasource.username = apolloconfig
        spring.datasource.password = admin@123
        eureka.service.url = http://config.fx.com/eureka
      app.properties: |
        appId=100003171

    deployment.yaml

    [root@hdss7-200 apollo-configservice]# vim deployment.yaml 
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: apollo-configservice
      namespace: infra
      labels: 
        name: apollo-configservice
    spec:
      replicas: 1
      selector:
        matchLabels: 
          name: apollo-configservice
      template:
        metadata:
          labels: 
            app: apollo-configservice 
            name: apollo-configservice
        spec:
          volumes:
          - name: configmap-volume
            configMap:
              name: apollo-configservice-cm
          containers:
          - name: apollo-configservice
            image: harbor.fx.com/infra/apollo-configservice:v1.5.1
            ports:
            - containerPort: 8080
              protocol: TCP
            volumeMounts:
            - name: configmap-volume
              mountPath: /apollo-configservice/config
          imagePullSecrets:
          - name: harbor
      strategy:
        type: RollingUpdate
        rollingUpdate: 
          maxUnavailable: 1
          maxSurge: 1
      revisionHistoryLimit: 10

    service.yaml

    [root@hdss7-200 apollo-configservice]# vim service.yaml 
    kind: Service
    apiVersion: v1
    metadata:
      name: apollo-configservice
      namespace: infra
    spec:
      ports:
      - protocol: TCP
        port: 8080
        targetPort: 8080
      selector:
        app: apollo-configservice
  • 相关阅读:
    Flink实战(七十三):FLINK-SQL使用基础(一)简介(一)入门
    Flink实战(七十二):监控(四)自定义metrics相关指标(二)
    k8s启动
    k8s containerd
    安装containerd
    k8s镜像
    crictl
    Kubernetes: Using containerd 1.1 without Docker
    docker images --digests
    ctr images pull docker.io/library/redis:latest
  • 原文地址:https://www.cnblogs.com/fxxy/p/13186456.html
Copyright © 2020-2023  润新知