mirror of https://github.com/easzlab/kubeasz.git
更新文档mariadb_cluster.md
parent
8bb3b29c86
commit
36993694f0
|
@ -1,3 +1,103 @@
|
||||||
# mariadb 数据库集群
|
# Mariadb 数据库集群
|
||||||
|
|
||||||
|
Mariadb 是从 MySQL 衍生出来的开源关系型数据库,目前兼容 mysql 5.7 版本;它也非常流行,拥有 Google Facebook 等重要企业用户。本文档介绍使用 helm charts 方式安装 mariadb cluster,仅供实践交流使用。
|
||||||
|
|
||||||
|
## 前提条件
|
||||||
|
|
||||||
|
- 已部署 k8s 集群,参考[这里](../setup/quickStart.md)
|
||||||
|
- 已部署 helm,参考[这里](../guide/helm.md)
|
||||||
|
- 集群提供持久性存储,参考[这里](../setup/08-cluster-storage.md)
|
||||||
|
|
||||||
|
这里演示使用 nfs 动态存储,编辑修改 nfs 存储部分参数
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
$ vi roles/cluster-storage/defaults/main.yml
|
||||||
|
storage:
|
||||||
|
# nfs server 参数
|
||||||
|
nfs:
|
||||||
|
enabled: "yes" # 启用 nfs
|
||||||
|
server: "172.16.3.86" # 设置 nfs 服务器地址
|
||||||
|
server_path: "/data/nfs" # 设置共享目录
|
||||||
|
storage_class: "nfs-db" # 定义 storage_class,后面pvc要调用这个
|
||||||
|
provisioner_name: "nfs-provisioner-01" # 任意命名
|
||||||
|
|
||||||
|
# 配置完成,保存退出,运行下面命令
|
||||||
|
$ ansible-playbook /etc/ansible/roles/cluster-storage/cluster-storage.yml
|
||||||
|
# 确认nfs provisioner pod
|
||||||
|
$ kubectl get pod --all-namespaces |grep nfs
|
||||||
|
kube-system nfs-provisioner-01-88694d78c-mrn7f 1/1 Running 0 6m
|
||||||
|
```
|
||||||
|
|
||||||
|
## mariadb charts 配置修改
|
||||||
|
|
||||||
|
按照惯例,直接把 chart 下载到本地,然后把配置复制 values.yaml 出来进行修改,这样方便以后整体更新 chart,安装实际使用需要修改配置文件
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
$ cd /etc/ansible/manifests/mariadb-cluster
|
||||||
|
# 编辑 my-values.yaml 修改以下部分
|
||||||
|
|
||||||
|
service:
|
||||||
|
type: NodePort # 方便集群外部访问
|
||||||
|
port: 3306
|
||||||
|
nodePort:
|
||||||
|
master: 33306 # 设置主库的nodePort
|
||||||
|
slave: 33307 # 设置从库的nodePort
|
||||||
|
|
||||||
|
rootUser: # 设置 root 密码
|
||||||
|
password: test.c0m
|
||||||
|
forcePassword: true
|
||||||
|
|
||||||
|
db: # 设置初始测试数据库
|
||||||
|
user: hello
|
||||||
|
password: hello
|
||||||
|
name: hello
|
||||||
|
forcePassword: true
|
||||||
|
|
||||||
|
replication: # 设置主从复制
|
||||||
|
enabled: true
|
||||||
|
user: replicator
|
||||||
|
password: R4%forep11CAT0r
|
||||||
|
forcePassword: true
|
||||||
|
|
||||||
|
master:
|
||||||
|
affinity: {}
|
||||||
|
antiAffinity: soft
|
||||||
|
tolerations: []
|
||||||
|
persistence:
|
||||||
|
enabled: true # 启用持久化存储
|
||||||
|
mountPath: /bitnami/mariadb
|
||||||
|
storageClass: "nfs-db" # 设置使用 nfs-db 存储类
|
||||||
|
annotations: {}
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
size: 5Gi # 设置存储容量
|
||||||
|
|
||||||
|
slave:
|
||||||
|
replicas: 1
|
||||||
|
affinity: {}
|
||||||
|
antiAffinity: soft
|
||||||
|
tolerations: []
|
||||||
|
persistence:
|
||||||
|
enabled: false # 从库这里没有启用持久性存储
|
||||||
|
```
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
使用 helm 安装
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
$ cd /etc/ansible/manifests/mariadb-cluster
|
||||||
|
$ helm install --name mariadb --namespace default -f my-values.yaml ./mariadb
|
||||||
|
```
|
||||||
|
|
||||||
|
## 验证
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
$ kubectl get pod,svc | grep mariadb
|
||||||
|
pod/mariadb-mariadb-master-0 1/1 Running 0 27m
|
||||||
|
pod/mariadb-mariadb-slave-0 1/1 Running 0 29m
|
||||||
|
|
||||||
|
service/mariadb NodePort 10.68.170.168 <none> 3306:33306/TCP 29m
|
||||||
|
service/mariadb-mariadb-slave NodePort 10.68.151.95 <none> 3306:33307/TCP 29m
|
||||||
|
```
|
||||||
|
|
||||||
待更新...
|
|
||||||
|
|
|
@ -185,12 +185,28 @@ master:
|
||||||
port=3306
|
port=3306
|
||||||
socket=/opt/bitnami/mariadb/tmp/mysql.sock
|
socket=/opt/bitnami/mariadb/tmp/mysql.sock
|
||||||
tmpdir=/opt/bitnami/mariadb/tmp
|
tmpdir=/opt/bitnami/mariadb/tmp
|
||||||
max_allowed_packet=16M
|
|
||||||
bind-address=0.0.0.0
|
bind-address=0.0.0.0
|
||||||
pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid
|
pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid
|
||||||
log-error=/opt/bitnami/mariadb/logs/mysqld.log
|
log-error=/opt/bitnami/mariadb/logs/mysqld.log
|
||||||
character-set-server=UTF8
|
character-set-server=UTF8
|
||||||
collation-server=utf8_general_ci
|
collation-server=utf8_general_ci
|
||||||
|
# optimize
|
||||||
|
max_allowed_packet = 1024M
|
||||||
|
table_open_cache = 512
|
||||||
|
sort_buffer_size = 2M
|
||||||
|
read_buffer_size = 2M
|
||||||
|
read_rnd_buffer_size = 8M
|
||||||
|
thread_cache_size = 8
|
||||||
|
query_cache_size = 32M
|
||||||
|
max_heap_table_size=1024M
|
||||||
|
tmp_table_size=1024M
|
||||||
|
max_connections=65535
|
||||||
|
max_connect_errors=65535
|
||||||
|
wait_timeout=172800
|
||||||
|
interactive_timeout=172800
|
||||||
|
connect_timeout=30
|
||||||
|
# log settings
|
||||||
|
expire_logs_days=3
|
||||||
|
|
||||||
[client]
|
[client]
|
||||||
port=3306
|
port=3306
|
||||||
|
@ -280,12 +296,28 @@ slave:
|
||||||
port=3306
|
port=3306
|
||||||
socket=/opt/bitnami/mariadb/tmp/mysql.sock
|
socket=/opt/bitnami/mariadb/tmp/mysql.sock
|
||||||
tmpdir=/opt/bitnami/mariadb/tmp
|
tmpdir=/opt/bitnami/mariadb/tmp
|
||||||
max_allowed_packet=16M
|
|
||||||
bind-address=0.0.0.0
|
bind-address=0.0.0.0
|
||||||
pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid
|
pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid
|
||||||
log-error=/opt/bitnami/mariadb/logs/mysqld.log
|
log-error=/opt/bitnami/mariadb/logs/mysqld.log
|
||||||
character-set-server=UTF8
|
character-set-server=UTF8
|
||||||
collation-server=utf8_general_ci
|
collation-server=utf8_general_ci
|
||||||
|
# optimize
|
||||||
|
max_allowed_packet = 1024M
|
||||||
|
table_open_cache = 512
|
||||||
|
sort_buffer_size = 2M
|
||||||
|
read_buffer_size = 2M
|
||||||
|
read_rnd_buffer_size = 8M
|
||||||
|
thread_cache_size = 8
|
||||||
|
query_cache_size = 32M
|
||||||
|
max_heap_table_size=1024M
|
||||||
|
tmp_table_size=1024M
|
||||||
|
max_connections=65535
|
||||||
|
max_connect_errors=65535
|
||||||
|
wait_timeout=172800
|
||||||
|
interactive_timeout=172800
|
||||||
|
connect_timeout=30
|
||||||
|
# log settings
|
||||||
|
expire_logs_days=3
|
||||||
|
|
||||||
[client]
|
[client]
|
||||||
port=3306
|
port=3306
|
||||||
|
|
Loading…
Reference in New Issue