nacos-group / r-nacos

Nacos server re-implemented in Rust.
https://r-nacos.github.io/docs/
Apache License 2.0
985 stars 104 forks source link

登陆后闪退 #140

Closed snac21 closed 1 month ago

snac21 commented 1 month ago

我在k8s上采用statefulset部署的时候,登陆到控制台,然后随便点服务列表或者配置中心,就会闪退到登陆页面 http://ip:port/rnacos/p/login?redirect_url=%2Frnacos%2Fmanage%2Fservice

apiVersion: v1
kind: Service
metadata:
  name: r-nacos-headless
  namespace: test-rd
spec:
  clusterIP: None
  selector:
    app: r-nacos
  ports:
    - port: 8848
      targetPort: 8848
      name: http
    - port: 9848
      targetPort: 9848
      name: raft
    - port: 10848
      targetPort: 10848
      name: raft-http
---
apiVersion: v1
kind: Service
metadata:
  name: r-nacos-nodeport
  namespace: test-rd
spec:
  type: NodePort
  selector:
    app: r-nacos
  ports:
    - port: 8848
      name: server-nodeport
      targetPort: 8848
    - port: 9848
      name: client-rpc-nodeport
      targetPort: 9848
    - port: 10848
      name: raft-rpc-nodeport
      targetPort: 10848
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: r-nacos
  namespace: test-rd
spec:
  serviceName: r-nacos-headless
  replicas: 3
  selector:
    matchLabels:
      app: r-nacos
  template:
    metadata:
      labels:
        app: r-nacos
    spec:
      containers:
        - name: r-nacos
          image: qingpan/rnacos:stable
          ports:
            - containerPort: 8848
              name: http
              protocol: TCP
            - containerPort: 9848
              name: raft
              protocol: TCP
            - containerPort: 10848
              name: raft-http
              protocol: TCP
          env:
            - name: RNACOS_ENABLE_NO_AUTH_CONSOLE
              value: 'true'
            - name: RNACOS_CONSOLE_ENABLE_CAPTCHA
              value: 'false'
            - name: RNACOS_ENABLE_NO_AUTH_CONSOLE
              value: "admin"
            - name: RNACOS_INIT_ADMIN_PASSWORD
              value: "admin"
            - name: RUST_LOG
              value: "warn"
            - name: RNACOS_HTTP_PORT
              value: "8848"
            - name: RNACOS_CONFIG_DB_DIR
              value: "db"
            - name: RNACOS_RAFT_NODE_ADDR
              value: "r-nacos-0:9848"
            - name: RNACOS_RAFT_NODE_ID
              value: "{{.StatefulSetOrdinal }}"  # 使用 Pod 的索引
            - name: RNACOS_RAFT_AUTO_INIT
              value: "true"
            - name: TZ
              value: "Asia/Shanghai"
heqingpan commented 1 month ago

这个跳转是因为请求时,检测到没有登陆所以跳转到登陆页面。

很现象上看应该是登陆后没能缓存数据,估计是写入文件时有问题,可能是存储相关的配置有问题。

可以检查一下日志,看看是不是有什么异常信息。

snac21 commented 1 month ago

是的,控制台显示,not login,r-nacos日志级别为warn,并没有显示异常日志,请问如何排查呀? 是否一定要挂载,我为了测试,把挂载的步骤去掉了

heqingpan commented 1 month ago

按之前的经验的话大概率是存储写入有问题。

你也可以把日志级别调整为info,先确认raft集群是否正常。正常情况下主节点会固定间隔给从节点发请求。

snac21 commented 1 month ago

可以了,上面写的有点点问题,谢谢 以下是我测试过的statefulset和configMap

configMap:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: r-nacos
  namespace: test-rd
  labels:
    app: r-nacos
data:
  entrypoint.sh: |-
    #!/bin/sh
    set -e

    # 读取当前 Pod 名称 r-nacos-0,r-nacos-1,r-nacos-2
    export MY_POD_NAME=$(hostname -s)

    # 设置环境变量 读取环境变量把r-nacos-0后面的数字拼接起来
    export RNACOS_RAFT_NODE_ADDR=r-nacos-$(echo $MY_POD_NAME | grep -o '[0-9]\+$').r-nacos-headless:9848
    export RNACOS_RAFT_NODE_ID=$(expr 1 + $(echo $MY_POD_NAME | grep -o '[0-9]\+$'))
    export RNACOS_RAFT_JOIN_ADDR=r-nacos-0.r-nacos-headless:9848
    export RUST_LOG=info
    export RNACOS_HTTP_WORKERS=8
    export RNACOS_CONSOLE_LOGIN_ONE_HOUR_LIMIT=5

    # 打印环境变量(调试用)
    echo "RNACOS_RAFT_NODE_ADDR: $RNACOS_RAFT_NODE_ADDR"
    echo "RNACOS_RAFT_NODE_ID: $RNACOS_RAFT_NODE_ID"
    echo "RNACOS_RAFT_JOIN_ADDR: $RNACOS_RAFT_JOIN_ADDR"

    # 执行主程序
    exec /usr/bin/rnacos

statefulset:

apiVersion: v1
kind: Service
metadata:
  name: r-nacos-headless
  namespace: test-rd
spec:
  clusterIP: None
  selector:
    app: r-nacos
  ports:
    - port: 8848
      targetPort: 8848
      name: http
    - port: 9848
      targetPort: 9848
      name: raft
    - port: 10848
      targetPort: 10848
      name: raft-http
---
apiVersion: v1
kind: Service
metadata:
  name: r-nacos-nodeport
  namespace: test-rd
spec:
  type: NodePort
  selector:
    app: r-nacos
  ports:
    - port: 8848
      name: server-nodeport
      targetPort: 8848
    - port: 9848
      name: client-rpc-nodeport
      targetPort: 9848
    - port: 10848
      name: raft-rpc-nodeport
      targetPort: 10848
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: r-nacos
  namespace: test-rd
spec:
  serviceName: r-nacos-headless
  replicas: 3
  selector:
    matchLabels:
      app: r-nacos
  template:
    metadata:
      labels:
        app: r-nacos
    spec:
      containers:
        - name: r-nacos
          image: registry.cn-hangzhou.aliyuncs.com/cage_dev/rnacos:latest
          command: ["/bin/sh", "/etc/config/entrypoint.sh"]
          ports:
            - containerPort: 8848
              name: http
              protocol: TCP
            - containerPort: 9848
              name: raft
              protocol: TCP
            - containerPort: 10848
              name: raft-http
              protocol: TCP
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
          env:
            - name: RNACOS_ENABLE_NO_AUTH_CONSOLE
              value: "true"
            - name: RNACOS_CONSOLE_ENABLE_CAPTCHA
              value: "false"
            - name: RNACOS_INIT_ADMIN_USERNAME
              value: "admin"
            - name: RNACOS_INIT_ADMIN_PASSWORD
              value: "admin"
            - name: TZ
              value: "Asia/Shanghai"
      volumes:
        - name: config-volume
          configMap:
            name: r-nacos
heqingpan commented 1 month ago

解决了就好😀

感谢分享k8s的部署配置。

leyou240 commented 1 month ago

@snac21 请问一下,为什么有两个service,r-nacos-headless和r-nacos-nodeport

snac21 commented 1 month ago

headless配合statefulset一起使用,这个可选;nodeport主要是给外网访问的,比如网页访问r-nacos控制页面,还有我后来发现,那个nodePort的端口得指定,偏移量需要保持1000,否则无法通过心跳校验,issuse关闭后,就没法修改了…

---- 回复的原邮件 ---- | 发件人 | @.> | | 发送日期 | 2024年10月13日 16:05 | | 收件人 | nacos-group/r-nacos @.> | | 抄送人 | snac21 @.>, Mention @.> | | 主题 | Re: [nacos-group/r-nacos] 登陆后闪退 (Issue #140) |

@snac21 请问一下,为什么有两个service,r-nacos-headless和r-nacos-nodeport

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

snac21 commented 1 month ago

headless服务可能在集群选举时会被用到,还有请问下,配置中心后续有计划支持mysql吗?

---- 回复的原邮件 ---- | 发件人 | @.> | | 发送日期 | 2024年10月13日 16:05 | | 收件人 | nacos-group/r-nacos @.> | | 抄送人 | snac21 @.>, Mention @.> | | 主题 | Re: [nacos-group/r-nacos] 登陆后闪退 (Issue #140) |

@snac21 请问一下,为什么有两个service,r-nacos-headless和r-nacos-nodeport

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

heqingpan commented 1 month ago

后续没有支持mysql的打算,不过会支持把数据导入导出到sqlite,让用户可以充分管理自己的数据。


原因:

r-nacos集群需要用raft分布式协议,raft协议本身就已经支持持久化。

多写一个数据库持久化,多依赖一个系统、多写一遍数据。没有带来什么优点,部署便捷、性能都有所降低。

所以r-nacos运行时设计上是不会再去支持额外的数据库。(和etcd,redis类似)。