Skip to content

ccwxl/mysql2postgresql-jdbc-agent

Repository files navigation

mysql2postgresql-jdbc-agent

  • 使用java agent无侵入的方式使用postgresql替换mysql. 参考 https://github.com/wuwen5/ojdbc-mysql2oracle 移植了postgresql版本
  • nacos基于2.1.0,2.1.2 测试
  • xxljob基于2.3.0 测试

使用环境变量JAVA_TOOL_OPTIONS注入javaagent

export JAVA_TOOL_OPTIONS=-javaagent:path/to/mysql2postgresql-jdbc-agent-1.0.0.jar

k8s环境下注入开启agent

  • 将编译的agent进行封装到docker基础镜像中
docker build -t mysql2postgresql-jdbc-agent:1.0.0 .
  • 使用initContainers挂载agent镜像
  • 增加agent环境变量
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
  namespace: default
spec:
  serviceName: nacos-hs
  replicas: 2
  template:
    metadata:
      labels:
        app: nacos
    spec:
      initContainers:
        - name: mysql2postgresql-jdbc-agent
          image: xxxx:81/mysql2postgresql-jdbc-agent/mysql2postgresql-jdbc-agent:1.0.0
          command: [ "/bin/sh" ]
          args: [ "-c", "cp -R /tmp/mysql2postgresql-jdbc-agent-1.0.0.jar /agent/" ]
          volumeMounts:
            - mountPath: /agent
              name: mysql2postgresql-jdbc-agent-volume
      containers:
        - name: nacos
          image: nacos/nacos-server:v2.1.0
          resources:
            requests:
              memory: "1Gi"
              cpu: "500m"
            limits:
              memory: "1Gi"
              cpu: "512m"
          ports:
            - containerPort: 8848
              name: client
            - containerPort: 9848
              name: client-rpc
            - containerPort: 9849
              name: raft-rpc
            - containerPort: 7848
              name: old-raft-rpc
          env:
            - name: JAVA_TOOL_OPTIONS
              value: "-javaagent:/agent/mysql2postgresql-jdbc-agent-1.0.0.jar"
            - name: MYSQL_SERVICE_HOST
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.db.host
            - name: MYSQL_SERVICE_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.db.name
            - name: MYSQL_SERVICE_PORT
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.port
            - name: MYSQL_SERVICE_USER
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.user
            - name: MYSQL_SERVICE_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.password
            - name: MYSQL_SERVICE_DB_PARAM
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.db.param
            - name: SPRING_DATASOURCE_PLATFORM
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.db.type
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: SERVICE_NAME
              value: "nacos-hs"
            - name: FUNCTION_MODE
              value: "config"
            - name: DOMAIN_NAME
              value: "cluster.local"
            - name: NACOS_APPLICATION_PORT
              value: "8848"
            - name: NACOS_SERVER_PORT
              value: "8848"
            - name: NACOS_REPLICAS
              value: "3"
            - name: MODE
              value: "cluster"
            - name: PREFER_HOST_MODE
              value: "hostname"
          volumeMounts:
            - name: mysql2postgresql-jdbc-agent-volume
              mountPath: /agent
      volumes:
        - name: mysql2postgresql-jdbc-agent-volume
          emptyDir: { }
  selector:
    matchLabels:
      app: nacos

About

Non-invasive replacement of mysql to postgresql , jdbc javaagent

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published