跳至主要內容

Rancher添加集群及部署常见应用

xw大约 6 分钟运维其他

添加Agent

  • 创建项目集群

image.png

  • 进入到选择集群的类型,这里选择自定义就可以

image.png

  • 进入到添加集群-Custom页面

  • 点击下一步

image.png

  • 添加Linux主机节点

    • 需要安装Docker,命令如下

        # 1.先安装yml
        yum install -y yum-utils device-mapper-persistent-data lvm2
        
        # 2.设置阿里云镜像
        sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
        
        #3. 安装docker
        yum -y install docker-ce-20.10.10-3.el7
        
        #4. 查看docker版本
        docker -v
        
        #5. 启动docker
        systemctl start docker
        
        #6. 查看docker 启动状态
        systemctl status docker
      
  • 终端中运行复制下来的命令

  • 稍等一会儿,可查看添加的集群状态

常见应用部署

Mysql

镜像:mysql:8.0
环境变量:
MYSQL_ROOT_PASSWORD=123456

路径映射
/home/data/mysql/data
/var/lib/mysql:rw
/etc/localtime
/etc/localtime:ro

在创建 Docker 容器时,加上 “-v /etc/localtime:/etc/localtime:ro” 参数
让容器使用宿主机的时间,容器时间与宿主机时间同步,:ro 指定该 volume 为只读

Nacos

镜像:nacos/nacos-server:2.0.2
端口:8848:8848

环境变量:
JVM_XMN=128m
JVM_XMS=128m
JVM_XMX=128m
MODE=standalone
MYSQL_SERVICE_DB_NAME=nacos_config
MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false
MYSQL_SERVICE_HOST=112.74.107.230
MYSQL_SERVICE_PASSWORD=xdclass.net168
MYSQL_SERVICE_PORT=3306
MYSQL_SERVICE_USER=root
NACOS_AUTH_ENABLE=true
SPRING_DATASOURCE_PLATFORM=mysql

挂载目录:
宿主机:/home/data/nacos/logs  容器:/home/nacos/logs

-Xms:初始堆大小
-Xmx:最大堆大小
-Xmn:新生代大小

xxl-job

镜像:xuxueli/xxl-job-admin:2.2.0
端口:8080:8080
环境变量:
PARAMS=--spring.datasource.url=jdbc:mysql://118.195.246.204:30006/xxl_job?Unicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai \
--spring.datasource.username=root \
--spring.datasource.password=123456 \
--xxl.job.accessToken=xdclass.net

Redis

镜像:redis:6.2.4
端口:6379:6379

数据卷:
/mydata/redis/data
/data

入口命令
redis-server --requirepass 123456

ClickHouse

镜像:clickhouse/clickhouse-server:22.1.4.30
端口:8123:8123 9000:9000 9009:9009

## 环境变量
nofile=262144
privileged=true
ulimit=262144


1.log卷
clickhouse-log
/mydata/docker/clickhouse/log
/var/log/clickhouse-server

2.data卷
clickhouse-data
/mydata/docker/clickhouse/data
/var/lib/clickhouse

Zookeeper

镜像:wurstmeister/zookeeper
端口:2181:2181

Kafka

镜像:wurstmeister/kafka:2.13-2.7.0
端口:9092:9092

环境变量:
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://120.25.217.15:9092
KAFKA_BROKER_ID=0
KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
KAFKA_ZOOKEEPER_CONNECT=172.31.101.8:2181
KAFKA_PORT=9092

ElasticSearch7.x

  • 在rancher主界面->资源->映射配置

    elasticsearch.yml
    
    cluster.name: "docker-cluster"
    network.host: 0.0.0.0
    ## 开启认证
    xpack.security.enabled: true
    xpack.license.self_generated.type: basic
    xpack.security.transport.ssl.enabled: true
    
    
  • 导入yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        deployment.kubernetes.io/revision: "2"
        field.cattle.io/creatorId: user-z8b4c
        field.cattle.io/publicEndpoints: '[{"addresses":["172.18.123.236"],"port":9200,"protocol":"TCP","serviceName":"default:es7-nodeport","allNodes":true},{"addresses":["172.18.123.236"],"port":9300,"protocol":"TCP","serviceName":"default:es7-nodeport","allNodes":true}]'
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{"deployment.kubernetes.io/revision":"1","field.cattle.io/creatorId":"user-z8b4c","field.cattle.io/publicEndpoints":"[{\"addresses\":[\"172.18.123.236\"],\"port\":9200,\"protocol\":\"TCP\",\"serviceName\":\"default:es7-nodeport\",\"allNodes\":true},{\"addresses\":[\"172.18.123.236\"],\"port\":9300,\"protocol\":\"TCP\",\"serviceName\":\"default:es7-nodeport\",\"allNodes\":true}]"},"creationTimestamp":null,"generation":1,"labels":{"cattle.io/creator":"norman","workload.user.cattle.io/workloadselector":"deployment-default-es7"},"managedFields":[{"apiVersion":"apps/v1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:field.cattle.io/creatorId":{},"f:field.cattle.io/publicEndpoints":{},"f:kubectl.kubernetes.io/last-applied-configuration":{}},"f:labels":{".":{},"f:cattle.io/creator":{},"f:workload.user.cattle.io/workloadselector":{}}},"f:spec":{"f:progressDeadlineSeconds":{},"f:replicas":{},"f:revisionHistoryLimit":{},"f:selector":{},"f:strategy":{"f:rollingUpdate":{".":{},"f:maxSurge":{},"f:maxUnavailable":{}},"f:type":{}},"f:template":{"f:metadata":{"f:annotations":{".":{},"f:cattle.io/timestamp":{},"f:field.cattle.io/ports":{},"f:workload.cattle.io/state":{}},"f:labels":{".":{},"f:workload.user.cattle.io/workloadselector":{}}},"f:spec":{"f:containers":{"k:{\"name\":\"es7\"}":{".":{},"f:env":{".":{},"k:{\"name\":\"ES_JAVA_OPTS\"}":{".":{},"f:name":{},"f:value":{}},"k:{\"name\":\"discovery.type\"}":{".":{},"f:name":{},"f:value":{}}},"f:image":{},"f:imagePullPolicy":{},"f:name":{},"f:ports":{".":{},"k:{\"containerPort\":9200,\"protocol\":\"TCP\"}":{".":{},"f:containerPort":{},"f:name":{},"f:protocol":{}},"k:{\"containerPort\":9300,\"protocol\":\"TCP\"}":{".":{},"f:containerPort":{},"f:name":{},"f:protocol":{}}},"f:resources":{},"f:securityContext":{".":{},"f:allowPrivilegeEscalation":{},"f:capabilities":{},"f:privileged":{},"f:readOnlyRootFilesystem":{},"f:runAsNonRoot":{}},"f:stdin":{},"f:terminationMessagePath":{},"f:terminationMessagePolicy":{},"f:tty":{},"f:volumeMounts":{".":{},"k:{\"mountPath\":\"/usr/share/elasticsearch/config/elasticsearch.yml\"}":{".":{},"f:mountPath":{},"f:name":{},"f:subPath":{}},"k:{\"mountPath\":\"/usr/share/elasticsearch/data\"}":{".":{},"f:mountPath":{},"f:name":{}},"k:{\"mountPath\":\"/usr/share/elasticsearch/plugins\"}":{".":{},"f:mountPath":{},"f:name":{}}}}},"f:dnsPolicy":{},"f:nodeName":{},"f:restartPolicy":{},"f:schedulerName":{},"f:securityContext":{},"f:terminationGracePeriodSeconds":{},"f:volumes":{".":{},"k:{\"name\":\"es-data\"}":{".":{},"f:hostPath":{".":{},"f:path":{},"f:type":{}},"f:name":{}},"k:{\"name\":\"es-plugins\"}":{".":{},"f:hostPath":{".":{},"f:path":{},"f:type":{}},"f:name":{}},"k:{\"name\":\"xd-es\"}":{".":{},"f:configMap":{".":{},"f:defaultMode":{},"f:name":{},"f:optional":{}},"f:name":{}}}}}}},"manager":"kubectl-client-side-apply","operation":"Update","time":"2022-04-12T06:20:23Z"},{"apiVersion":"apps/v1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{"f:deployment.kubernetes.io/revision":{}}},"f:status":{"f:availableReplicas":{},"f:conditions":{".":{},"k:{\"type\":\"Available\"}":{".":{},"f:lastTransitionTime":{},"f:lastUpdateTime":{},"f:message":{},"f:reason":{},"f:status":{},"f:type":{}},"k:{\"type\":\"Progressing\"}":{".":{},"f:lastTransitionTime":{},"f:lastUpdateTime":{},"f:message":{},"f:reason":{},"f:status":{},"f:type":{}}},"f:observedGeneration":{},"f:readyReplicas":{},"f:replicas":{},"f:updatedReplicas":{}}},"manager":"kube-controller-manager","operation":"Update","time":"2022-04-12T06:20:27Z"}],"name":"es7","namespace":"default"},"spec":{"progressDeadlineSeconds":600,"replicas":1,"revisionHistoryLimit":10,"selector":{"matchLabels":{"workload.user.cattle.io/workloadselector":"deployment-default-es7"}},"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":0},"type":"RollingUpdate"},"template":{"metadata":{"annotations":{"cattle.io/timestamp":"2022-04-12T05:19:04Z","field.cattle.io/ports":"[[{\"containerPort\":9200,\"dnsName\":\"es7-nodeport\",\"hostPort\":0,\"kind\":\"NodePort\",\"name\":\"9200tcp92001\",\"protocol\":\"TCP\",\"sourcePort\":9200},{\"containerPort\":9300,\"dnsName\":\"es7-nodeport\",\"hostPort\":0,\"kind\":\"NodePort\",\"name\":\"9300tcp93001\",\"protocol\":\"TCP\",\"sourcePort\":9300}]]","workload.cattle.io/state":"{\"\":\"c-fh95p:m-90a323cc4bdc\",\"aXp3ejkwcGVndTlidWR4NXRrNHJ1eno=\":\"c-fh95p:m-90a323cc4bdc\",\"aXp3ejlmM3B2azRreDVoYW5yc2xxaHo=\":\"c-9kkcj:m-173ea115b6eb\"}"},"creationTimestamp":null,"labels":{"workload.user.cattle.io/workloadselector":"deployment-default-es7"}},"spec":{"containers":[{"env":[{"name":"ES_JAVA_OPTS","value":"-Xms128m -Xmx128m"},{"name":"discovery.type","value":"single-node"}],"image":"elasticsearch:7.6.2","imagePullPolicy":"Always","name":"es7","ports":[{"containerPort":9200,"name":"9200tcp92001","protocol":"TCP"},{"containerPort":9300,"name":"9300tcp93001","protocol":"TCP"}],"resources":{},"securityContext":{"allowPrivilegeEscalation":false,"capabilities":{},"privileged":false,"readOnlyRootFilesystem":false,"runAsNonRoot":false},"stdin":true,"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","tty":true,"volumeMounts":[{"mountPath":"/usr/share/elasticsearch/config/elasticsearch.yml","name":"xd-es","subPath":"elasticsearch.yml"},{"mountPath":"/usr/share/elasticsearch/data","name":"es-data"},{"mountPath":"/usr/share/elasticsearch/plugins","name":"es-plugins"}]}],"dnsPolicy":"ClusterFirst","nodeName":"izwz9f3pvk4kx5hanrslqhz","restartPolicy":"Always","schedulerName":"default-scheduler","securityContext":{},"terminationGracePeriodSeconds":30,"volumes":[{"configMap":{"defaultMode":511,"name":"elasticsearch.yml","optional":false},"name":"xd-es"},{"hostPath":{"path":"/mydata/es/data","type":"DirectoryOrCreate"},"name":"es-data"},{"hostPath":{"path":"/mydata/es/plugins","type":"DirectoryOrCreate"},"name":"es-plugins"}]}}},"status":{}}
      creationTimestamp: null
      generation: 1
      labels:
        cattle.io/creator: norman
        workload.user.cattle.io/workloadselector: deployment-default-es7
      managedFields:
      - apiVersion: apps/v1
        fieldsType: FieldsV1
        fieldsV1:
          f:metadata:
            f:annotations:
              .: {}
              f:field.cattle.io/creatorId: {}
              f:field.cattle.io/publicEndpoints: {}
              f:kubectl.kubernetes.io/last-applied-configuration: {}
            f:labels:
              .: {}
              f:cattle.io/creator: {}
              f:workload.user.cattle.io/workloadselector: {}
          f:spec:
            f:progressDeadlineSeconds: {}
            f:replicas: {}
            f:revisionHistoryLimit: {}
            f:selector: {}
            f:strategy:
    

date: 2022-02-11
.: {}
f:maxSurge: {}
f:maxUnavailable: {}
f:type: {}
f:template:
f:metadata:
f:annotations:
.: {}
f:workload.cattle.io/state: {}
f:labels:
.: {}
f:workload.user.cattle.io/workloadselector: {}
f:spec:
f:containers:
k:{"name":"es7"}:
.: {}
f:env:
.: {}
k:{"name":"ES_JAVA_OPTS"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"discovery.type"}:
.: {}
f:name: {}
f:value: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:ports:
.: {}
k:{"containerPort":9200,"protocol":"TCP"}:
.: {}
f:containerPort: {}
f:name: {}
f:protocol: {}
k:{"containerPort":9300,"protocol":"TCP"}:
.: {}
f:containerPort: {}
f:name: {}
f:protocol: {}
f:resources: {}
f:securityContext:
.: {}
f:allowPrivilegeEscalation: {}
f:privileged: {}
f:readOnlyRootFilesystem: {}
f:runAsNonRoot: {}
f:stdin: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:tty: {}
f:volumeMounts:
.: {}
k:{"mountPath":"/usr/share/elasticsearch/config/elasticsearch.yml"}:
.: {}
f:mountPath: {}
f:name: {}
f:subPath: {}
k:{"mountPath":"/usr/share/elasticsearch/data"}:
.: {}
f:mountPath: {}
f:name: {}
k:{"mountPath":"/usr/share/elasticsearch/plugins"}:
.: {}
f:mountPath: {}
f:name: {}
f:dnsPolicy: {}
f:nodeName: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:terminationGracePeriodSeconds: {}
f:volumes:
.: {}
k:{"name":"es-data"}:
.: {}
f:hostPath:
.: {}
f:path: {}
f:type: {}
f:name: {}
k:{"name":"es-plugins"}:
.: {}
f:hostPath:
.: {}
f:path: {}
f:type: {}
f:name: {}
k:{"name":"xd-es"}:
.: {}
f:configMap:
.: {}
f:defaultMode: {}
f:name: {}
f:optional: {}
f:name: {}
manager: kubectl-client-side-apply
operation: Update
time: "2022-04-12T10:04:00Z"
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:spec:
f:template:
f:metadata:
f:annotations:
f:cattle.io/timestamp: {}
f:field.cattle.io/ports: {}
f:field.cattle.io/publicEndpoints: {}
manager: rancher
operation: Update
time: "2022-04-12T10:05:12Z"
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
f:deployment.kubernetes.io/revision: {}
f:status:
f:availableReplicas: {}
f:conditions:
.: {}
k:{"type":"Available"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
k:{"type":"Progressing"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
f:observedGeneration: {}
f:readyReplicas: {}
f:replicas: {}
f:updatedReplicas: {}
manager: kube-controller-manager
operation: Update
time: "2022-04-12T10:05:19Z"
name: es7
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
workload.user.cattle.io/workloadselector:open in new window deployment-default-es7
strategy:
date: 2022-02-11
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
cattle.io/timestamp:open in new window "2022-04-12T10:05:12Z"
field.cattle.io/ports:open in new window '[[{"containerPort":9200,"dnsName":"es7-nodeport","kind":"NodePort","name":"9200tcp92001","protocol":"TCP","sourcePort":9200},{"containerPort":9300,"dnsName":"es7-nodeport","kind":"NodePort","name":"9300tcp93001","protocol":"TCP","sourcePort":9300}]]'
field.cattle.io/publicEndpoints:open in new window '[{"addresses":["172.18.123.236"],"allNodes":true,"port":9200,"protocol":"TCP","serviceId":"default:es7-nodeport"},{"addresses":["172.18.123.236"],"allNodes":true,"port":9300,"protocol":"TCP","serviceId":"default:es7-nodeport"}]'
workload.cattle.io/state:open in new window '{"":"c-fh95p:m-90a323cc4bdc","aXp3ejkwcGVndTlidWR4NXRrNHJ1eno=":"c-fh95p:m-90a323cc4bdc","aXp3ejlmM3B2azRreDVoYW5yc2xxaHo=":"c-9kkcj:m-173ea115b6eb"}'
creationTimestamp: null
labels:
workload.user.cattle.io/workloadselector:open in new window deployment-default-es7
spec:
containers:
- env:
- name: ES_JAVA_OPTS
value: -Xms128m -Xmx128m
- name: discovery.type
value: single-node
image: elasticsearch:7.6.2
imagePullPolicy: Always
name: es7
ports:
- containerPort: 9200
name: 9200tcp92001
protocol: TCP
- containerPort: 9300
name: 9300tcp93001
protocol: TCP
resources: {}
securityContext:
allowPrivilegeEscalation: false
privileged: false
readOnlyRootFilesystem: false
runAsNonRoot: false
stdin: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
tty: true
volumeMounts:
- mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
name: xd-es
subPath: elasticsearch.yml
- mountPath: /usr/share/elasticsearch/data
name: es-data
- mountPath: /usr/share/elasticsearch/plugins
name: es-plugins
dnsPolicy: ClusterFirst
nodeName: izwz9f3pvk4kx5hanrslqhz
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 511
name: elasticsearch.yml
optional: false
name: xd-es
- hostPath:
path: /mydata/es/data
type: DirectoryOrCreate
name: es-data
- hostPath:
path: /mydata/es/plugins
type: DirectoryOrCreate
name: es-plugins
status: {}


* 重新配置文件,默认为空,需要重新配置

  ![](./img/20220905152330.png)

* 配置主机调度

  * 并到主机下的mydata给es文件夹添加777权限

  ```
  chmod 777 -R /mydata/es
  ```

  ![image.png](./img/1649742667414-95342f65-b2fa-4a42-af68-32ebbef8a097.png)

* 配置账号密码

  * 命令行进入

  ```shell
  bin/elasticsearch-setup-passwords interactive
  ```

  * 按回车输入y,回车一直输入密码elastic即可

### Skywalking-OAP-Server

镜像:apache/skywalking-oap-server:8.5.0-es7
端口:12800:12800 11800:11800

环境变量:
TZ=Asia/Shanghai
SW_ES_PASSWORD=elastic
SW_ES_USER=elastic
SW_STORAGE=elasticsearch7
SW_STORAGE_ES_CLUSTER_NODES=120.76.231.139:9200


### Skywalking-UI

镜像:apache/skywalking-ui:8.5.0
端口:8080:8000 (左边是容器端口,右边是宿主机端口)

环境变量(oap是上面定义的容器服务名称)
SW_OAP_ADDRESS=oap:12800
TZ=Asia/Shanghai