目 录CONTENT

文章目录

nacos

xlong
2024-03-30 / 0 评论 / 0 点赞 / 9 阅读 / 4680 字 / 正在检测是否收录...

nacos安装

创建数据库导入数据

CREATE DATABASE `nacos` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;

mysql nacos < mysql-sechema.sql

mysql8.0数据库配置使用mysql_native_password插件

create user nacos@'%' identified with mysql_native_password by '123456';
grant all on nacos.* to nacos@'%';

docker单节点启动

docker run --name nacos-quick -d \
  -e MODE=standalone -e NACOS_AUTH_ENABLE="true" \
  -e JAVA_OPT="-Ddb.pool.config.connectionTimeout=10000" \
  -e nacos.core.auth.server.identity.key=nacos \
  -e nacos.core.auth.server.identity.value=nacos123 \
  -e nacos.core.auth.system.type=nacos \
  -e NACOS_AUTH_TOKEN=SecretKey01234567890123234567890123456789 
  nacos/nacos-server:v1.4.6-slim

kubernetes集群启动

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
spec:
  podManagementPolicy: OrderedReady
  replicas: 3
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: nacos
  serviceName: nacos
  template:
    metadata:
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
      creationTimestamp: null
      labels:
        app: nacos
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nacos
            topologyKey: kubernetes.io/hostname
      containers:
      - env:
        - name: NACOS_AUTH_ENABLE
          value: "true"
        - name: NACOS_AUTH_IDENTITY_KEY
          value: nacos-key
        - name: NACOS_AUTH_IDENTITY_VALUE
          value: nacos-test
        - name: NACOS_AUTH_TOKEN
          value: "SecretKey01234567890123456789012345674567890123456789"
        - name: SPRING_DATASOURCE_PLATFORM
          value: mysql
        - name: MODE
          value: cluster
        - name: JAVA_OPT
          value: -Ddb.pool.config.connectionTimeout=10000
        - name: MYSQL_SERVICE_HOST
          value: 192.168.1.10
        - name: NACOS_REPLICAS
          value: "3"
        - name: MYSQL_SERVICE_DB_NAME
          value: nacos
        - name: MYSQL_SERVICE_PORT
          value: "3306"
        - name: MYSQL_SERVICE_USER
          value: nacos
        - name: MYSQL_SERVICE_PASSWORD
          value: "123456"
        - name: NACOS_SERVER_PORT
          value: "8848"
        - name: NACOS_APPLICATION_PORT
          value: "8848"
        - name: PREFER_HOST_MODE
          value: hostname
        - name: NACOS_SERVERS
          value: nacos-0.nacos.default.svc.cluster.local:8848 nacos-1.nacos.default.svc.cluster.local:8848 nacos-2.nacos.default.svc.cluster.local:8848
#        image: nacos/nacos-server:latest-slim
#        image: nacos/nacos-server:v2.2.0-slim
        image: nacos/nacos-server:v2.2.3
        imagePullPolicy: IfNotPresent
        name: nacos
        ports:
        - containerPort: 8848
          name: client
          protocol: TCP
        - containerPort: 7848
          name: rpc
          protocol: TCP
        resources:
          requests:
            cpu: 1000m
            memory: 2Gi
---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nacos
  name: nacos
spec:
  ports:
  - name: server
    port: 8848
    protocol: TCP
    targetPort: 8848
    nodePort: 32076
  - name: rpc
    port: 7848
    protocol: TCP
    targetPort: 7848
  selector:
    app: nacos
  type: NodePort

nacos api

登录获取token

# 使用账号密码获取token
curl -X POST 'http://192.168.1.10:8848/nacos/v1/auth/login' -d 'username=nacos&password=nacos'

获取配置

# 使用token获取配置
curl -X GET 'http://192.168.1.10:8848/nacos/v1/cs/configs?accessToken=eyJhbGciOiJOiJuYWNvcyIsImV4cCI6MTcxMTc4NzI0Mn0.DLnEgrRJLxBWg&dataId=dataId=redis.yml&group=system'

发布配置

# 发布配置
curl -X POST "http://cluster-ip:8848/nacos/v1/cs/configs?dataId=test.yml&group=test&content=helloWorld"

0

评论区