k8s 安装 canal 服务
作者:互联网
目录
1. 安装
a | 创建
d |
e | 安装
2. 安装
a | 创建
b | 授权
c |
d | 安装
资源清单
本文安装
canal
依赖K8S集群
、MySQL
,本文不提供K8S集群
安装方式,MySQL
安装可以参考以下文档
软件 | 版本 |
---|---|
canal-admin | v1.1.5 |
canal-server | v1.1.5 |
mysql | 5.7.26 |
kubernetes | v1.19.3 |
K8S
安装 canal
1. 安装 canal-admin
a | 创建 canal-admin
目录
$ mkdir -p /root/canal/canal-admin/ && cd /root/canal/canal-admin/
b | 获取数据库初始化语句
$ wget https://raw.githubusercontent.com/alibaba/canal/canal-1.1.5/admin/admin-web/src/main/resources/canal_manager.sql -O /tmp/canal_manager.sql
c | 创建用户和数据库初始化数据
$ kubectl cp /tmp/canal_manager.sql test-middleware/mysql_host:/tmp/canal_manager.sql
# 连接部署好的 Mysql 数据,创建 apollo 账户和数据库
$ mysql -h mysql_host -u root -p root123
mysql > create database canal_manager default character set utf8mb4 collate utf8mb4_unicode_ci;
mysql > grant all on canal_manager.* to 'canal'@'%' identified by 'canal';
# 执行数据库初始化语句
mysql > sourse /tmp/apolloconfigdb.sql
d | canal-admin
yaml
资源清单
yaml
配置
$ cat << EOF >> canal-admin-test.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: canal-admin
namespace: test-middleware
data:
admin_user: "admin"
admin_password: "123456"
datasource_address: "mysql-cluster-mysql.test-middleware:3306"
datasource_database: "canal_manager"
datasource_username: "canal"
datasource_password: "canal"
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: canal-admin
namespace: test-middleware
labels:
app.kubernetes.io/name: canal-admin
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: canal-admin
template:
metadata:
name: canal-admin
creationTimestamp: null
labels:
app.kubernetes.io/name: canal-admin
spec:
containers:
- name: canal-admin
image: 'canal/canal-admin:v1.1.5'
imagePullPolicy: IfNotPresent
ports:
- name: web
containerPort: 8089
protocol: TCP
env:
- name: server.port
value: '8089'
- name: canal.adminUser
valueFrom:
configMapKeyRef:
name: canal-admin
key: admin_user
- name: canal.adminPasswd
valueFrom:
configMapKeyRef:
name: canal-admin
key: admin_password
- name: spring.datasource.address
valueFrom:
configMapKeyRef:
name: canal-admin
key: datasource_address
- name: spring.datasource.database
valueFrom:
configMapKeyRef:
name: canal-admin
key: datasource_database
- name: spring.datasource.username
valueFrom:
configMapKeyRef:
name: canal-admin
key: datasource_username
- name: spring.datasource.password
valueFrom:
configMapKeyRef:
name: canal-admin
key: datasource_password
resources:
requests:
cpu: 250m
memory: 256Mi
livenessProbe:
httpGet:
path: /
port: 8089
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 30
readinessProbe:
httpGet:
path: /
port: 8089
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 30
restartPolicy: Always
nodeSelector: {}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/name: canal-admin
namespaces:
- test-middleware
topologyKey: kubernetes.io/hostname
revisionHistoryLimit: 10
---
kind: Service
apiVersion: v1
metadata:
name: canal-admin
namespace: test-middleware
spec:
ports:
- protocol: TCP
port: 8089
targetPort: 8089
selector:
app.kubernetes.io/name: canal-admin
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: canal-admin
namespace: test-middleware
spec:
tls: []
rules:
- host: canal-admin.evescn.com # 域名
http:
paths:
- backend:
serviceName: canal-admin # 对应服务名
servicePort: 8089
EOF
e | 安装 canal-admin
# 创建 test-middleware 名称空间
$ kubectl create ns test-middleware
# 安装 canal-admin
$ cd /root/canal/canal-admin/
$ kubectl apply -f canal-admin-test.yaml
f | 查看服务
$ kubectl -n test-middleware get pods
NAME READY STATUS RESTARTS AGE
canal-admin-68b95bfc7c-tjmcj 1/1 Running 0 19m
- 查看ingress
$ kubectl -n test-middleware get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
canal-admin <none> canal-admin.evescn.com 80 20m
2. 安装 canal-server
a | 创建 canal-server
目录
$ mkdir -p /root/canal/canal-server/ && cd /root/canal/canal-server/
b | 授权 canal
用户主从同步权限
# 连接部署好的 Mysql 数据,创建 apollo 账户和数据库
$ mysql -h mysql_host -u root -p root123
mysql > GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
mysql > FLUSH PRIVILEGES;
c | canal-server
yaml
资源清单
yaml
配置
$ cat << EOF >> canal-server-test.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: canal-server
namespace: test-middleware
data:
admin_manager: "canal-admin.test-middleware:8089"
admin_port: "11110"
admin_user: "admin"
admin_password: "6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9"
# admin_register_cluster: "local"
admin_register_auto: "true"
admin_register_name: "test-canal-server"
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: canal-server
namespace: test-middleware
labels:
app.kubernetes.io/name: canal-server
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: canal-server
template:
metadata:
name: canal-server
creationTimestamp: null
labels:
app.kubernetes.io/name: canal-server
spec:
containers:
- name: canal-server
image: 'canal/canal-server:v1.1.5'
imagePullPolicy: IfNotPresent
ports:
- name: tcp
containerPort: 11111
protocol: TCP
env:
- name: canal.admin.manager
valueFrom:
configMapKeyRef:
name: canal-server
key: admin_manager
- name: canal.admin.port
valueFrom:
configMapKeyRef:
name: canal-server
key: admin_port
- name: canal.admin.user
valueFrom:
configMapKeyRef:
name: canal-server
key: admin_user
- name: canal.admin.passwd
valueFrom:
configMapKeyRef:
name: canal-server
key: admin_password
# - name: canal.admin.register.cluster
# valueFrom:
# configMapKeyRef:
# name: canal-server
# key: admin_register_cluster
- name: canal.admin.register.auto
valueFrom:
configMapKeyRef:
name: canal-server
key: admin_register_auto
- name: canal.admin.register.name
valueFrom:
configMapKeyRef:
name: canal-server
key: admin_register_name
resources:
requests:
cpu: 250m
memory: 256Mi
livenessProbe:
tcpSocket:
port: 11112
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 30
readinessProbe:
tcpSocket:
port: 11112
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 30
restartPolicy: Always
nodeSelector: {}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/name: canal-server
namespaces:
- test-middleware
topologyKey: kubernetes.io/hostname
serviceName: canal-server
revisionHistoryLimit: 10
d | 安装 canal-server
# 安装 canal-admin
$ cd /root/canal/canal-server/
$ kubectl apply -f canal-server-test.yaml
3. 查看服务
-
访问
canal-admin
-
查看
canal-server
服务
-
查看
Instance
参考文档
https://www.lerzen.com/post/canal%E5%AD%A6%E4%B9%A0%E5%8F%8Ak8s%E9%9B%86%E7%BE%A4%E9%83%A8%E7%BD%B2/
https://www.cnblogs.com/thepoy/p/14745329.html
https://www.songbingjia.com/javascript/show-64037.html
标签:canal,name,admin,middleware,server,test,k8s,安装 来源: https://www.cnblogs.com/evescn/p/16341932.html