当前位置:网站首页>给小白的 PostgreSQL 容器化部署教程(上)
给小白的 PostgreSQL 容器化部署教程(上)
2022-07-30 05:08:00 【RadonDB】
作者:王志斌
编辑:钟华龙
本文来自社区小伙伴 王志斌 的投稿。从小白的角度,带你一步步实现将 RadonDB PostgreSQL 集群部署到 Kubernetes 上。文章分为上下两部分,第一部分将为大家演示如何搭建一套 Kubernetes 环境,包括详细的配置调优等。
什么是 RadonDB PostgreSQL Operator?
RadonDB PostgreSQL 是一款基于 PostgreSQL 使用 Operator 实现的数据库容器化项目。
- 被广泛应用于地理空间和移动领域
- 具备高可用、稳定性、数据完整性等性能
- 支持在线水平扩展
- 支持故障自动转移 ,提供 HA 功能
- 提供 PostgreSQL 常用参数接口,方便调整参数
- 提供 PostGIS 插件,具备存储、查询和修改空间关系的能力
- 提供实时监控、健康检查、日志自动清理等功能
RadonDB PostgreSQL Operator 可基于 KubeSphere、OpenShift、Rancher 等 Kubernetes 容器平台交付。可自动执行与运行 RadonDB PostgreSQL 集群有关的任务。
RadonDB PostgreSQL Operator基于 https://github.com/CrunchyData/postgres-operator 项目实现,进行了改进优化,后续会持续回馈给社区。
仓库地址:https://github.com/radondb/radondb-postgresql-operator
部署目标
目标:准备一套 Kubernetes 作为后续数据库部署环境。
| 主机名 | IP | 角色 | 备注 |
|---|---|---|---|
| master | 192.168.137.2 | kubernetes master | 去除污点 |
| node1 | 192.168.137.3 | kubernetes node | |
| node2 | 192.168.137.4 | kubernetes node |
配置操作系统
操作系统:CentOS 7
1、修改各自主机名并修改主机列表
#192.168.137.2vi /etc/hostnamemastercat >> /etc/hosts << EOF192.168.137.2 master192.168.137.3 node1192.168.137.4 node2EOF#192.168.137.3vi /etc/hostnamenode1cat >> /etc/hosts << EOF192.168.137.2 master192.168.137.3 node1192.168.137.4 node2EOF#192.168.137.4vi /etc/hostnamenode2cat >> /etc/hosts << EOF192.168.137.2 master192.168.137.3 node1192.168.137.4 node2EOF2、其他配置
关闭防火墙、关闭 SELinux、关闭 SWAP ,设置时间同步。
systemctl stop firewalld && systemctl disable firewalldsed -i 's/enforcing/disabled/' /etc/selinux/config && setenforce 0swapoff -a && sed -ri 's/.*swap.*/#&/' /etc/fstabyum install ntpdate -y && ntpdate time.windows.com3、配置内核参数
将桥接的 IPv4 流量传递到 iptables 的链。
cat > /etc/sysctl.d/k8s.conf <<EOFnet.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1EOFsysctl --system准备 Docker
1、 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm22、添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo3、更新并安装 Docker-CE
yum makecache fastyum -y install docker-ce4、开启 Docker 服务
systemctl start docker && systemctl enable docker# 可以通过修改 daemon 配置文件 /etc/docker/daemon.json 来使用加速器mkdir -p /etc/dockertee /etc/docker/daemon.json <<-'EOF'{ "registry-mirrors": ["https://s2q9fn53.mirror.aliyuncs.com"]}EOFsystemctl daemon-reload && sudo systemctl restart dockerKubernetes 准备
1、初始化
添加 Kubernetes 阿里云的 YUM 源。
cat <<EOF > /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/enabled=1gpgcheck=1repo_gpgcheck=0gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgEOFyum install kubectl-1.20.0 kubelet-1.20.0 kubeadm-1.20.0 && systemctl enable kubelet && systemctl start kubelet初始化集群。
#masterkubeadm init --kubernetes-version=1.20.0 \--apiserver-advertise-address=192.168.137.2 \--image-repository registry.aliyuncs.com/google_containers \--service-cidr=10.10.0.0/16 --pod-network-cidr=10.122.0.0/16mkdir -p $HOME/.kubecp -i /etc/kubernetes/admin.conf $HOME/.kube/configchown $(id -u):$(id -g) $HOME/.kube/config其他节点加入集群。
kubeadm join 192.168.137.2:6443 --token scw8xm.x5y7fck1via4mwc2 \ --discovery-token-ca-cert-hash sha256:8944421887121b6a2ac32987d9d1c7786fe64316cebdf7a63b6048fba183cc672、部署 CNI 网络插件
安装 flannel 网络插件。
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml发送 admin.conf 到所有节点,可以在任何一个节点管理集群。
scp /etc/kubernetes/admin.conf [email protected]:/etc/kubernetes/admin.confscp /etc/kubernetes/admin.conf [email protected]:/etc/kubernetes/admin.conf在 node 节点上加入环境变量。
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profilesource /etc/profile执行完成以后可以在任意 node 节点上管理集群,查看节点是否正常。
kubectl get nodes
节点状态正常。
3、查看节点
[[email protected] images]# kubectl label node node1 node-role.kubernetes.io/worker=workernode/node1 labeled[[email protected] images]# kubectl label node node2 node-role.kubernetes.io/worker=workernode/node2 labeled4、创建默认 storageclass
vi sc.ymlkind: StorageClassapiVersion: storage.k8s.io/v1metadata: name: fast-disksprovisioner: kubernetes.io/no-provisionervolumeBindingMode: WaitForFirstConsumer[[email protected] ~]# kubectl apply -f sc.ymlstorageclass.storage.k8s.io/local-storage create设置为默认。
kubectl patch storageclass fast-disks -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'5、去除污点
添加 尽量不调度 PreferNoSchedule 。
kubectl taint nodes master node-role.kubernetes.io/master:PreferNoSchedule去除污点 NoSchedule,最后一个 “-” 代表删除。
kubectl taint nodes master node-role.kubernetes.io/master:NoSchedule-镜像的问题
RadonDB PostgreSQL Opeartor 的安装需要准备一些镜像,但编译镜像的步骤可以省略,社区已经在 dockerhub 已经构建好了 RadonDB PostgreSQL 所有依赖的镜像,直接使用即可。
至此,我们已经准备好了 Kuberentes 环境,下一期我们将带您进行 RadonDB PostgreSQL Operator 的部署。
作者简介:
王志斌,北京航空航天大学硕士,荣获PMP和NPDP专业认证,巨杉数据库认证讲师和PostgreSQL官方认证讲师,拥有PGCM、PCTP、SCDD、KCP、OBCA等相关认证。荣获工信部中国开源软件推进联盟PostgreSQL ACE以及PostgreSQL开源社区推动贡献奖,并参与编著《PostgreSQL高可用实战》。
致谢 RadonDB 开源社区向本文的投稿作者表示感谢!也期待更多的社区小伙伴的投稿~
边栏推荐
- Seven, custom configuration
- LeetCode Algorithm 328. Parity linked list
- 聊一聊什么是SaaS,以及遇到的问题......
- 2.6 Radix sort (bucket sort)
- 斐波那契数列的递归优化《备忘录递归》
- SVN 查看用户名密码
- L2-020 功夫传人
- VisualStudio2022 local debugging entry is particularly slow problem solving
- String problem (below)
- (Hexagon_V65_Programmers_Reference_Manual(13)
猜你喜欢

Code readability, pre-checks, comments and summaries

Usage of EFR32 as sniffer for Zigbee/Thread

pyinstaller打包程序所遇问题记录

【Vitis】ZCU102开发板PS端控制PL端复位的代码实现

六、读取应用配置+日志配置

protobuf 中复合数据类型的读写

WPF study notes "WPF Layout Basics"

Hexagon_V65_Programmers_Reference_Manual (11)

Predictive maintenance scheduling of multiple power equipment based on data-driven fault prediction

webService接口
随机推荐
Simulation Problem (Part 1)
Summary of skills in using ms project2010 project management software
2.6 Radix sort (bucket sort)
罗湖区工匠技能领军人才奖励项目申请指南
go语言学习笔记三
Discourse 自定义头部链接(Custom Header Links)
DLL description (1)
模拟问题(上)
模拟问题(下)
[3D Detection Series-PointRCNN] Reproduces the PointRCNN code, and realizes the visualization of PointRCNN3D target detection, including the download link of pre-training weights (starting from 0 and
Unity踩坑记录 —— GetComponent的使用
webService interface
Web page element parsing a tag
如何与墨西哥大众VW Mexico建立EDI连接
Divide and conquer. L2-025
uni-app realizes cross-end development of mobile phone Bluetooth to receive and send data
坪山区关于开展2022年度科技创新专项资金申报工作的通知
IIS网站出现401未授权访问
Whole process scheduling - Azkaban entry and advanced
需求设计文档和产品经理的角色改变