当前位置:网站首页>给小白的 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 开源社区向本文的投稿作者表示感谢!也期待更多的社区小伙伴的投稿~
边栏推荐
- Recursive Optimization of Fibonacci Sequences "Memo Recursion"
- Excellent MySQL interview questions, 99% must ask in preparation for August!I can't pass the interview
- go language study notes 2
- Dynamic Programming Problems (End)
- 1. Get data - requests.get()
- 22. Why do you need a message queue?What are the advantages of using the message queue?
- go语言学习笔记三
- Six, read application configuration + log configuration
- Nuxt3 learning
- Image stitching (registration) case based on OpenCV
猜你喜欢

Hexagon_V65_Programmers_Reference_Manual (14)

1. Get data - requests.get()

protobuf 中复合数据类型的读写

ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序

工作效率-十五分钟让你快速学习Markdown语法到精通排版实践备忘

Discourse Custom Header Links

A must see for software testers!Database knowledge MySQL query statement Daquan

Us to raise interest rates by 75 basis points in "technical recession"?Encryption market is recovering

3. Dependency configuration management

Protobuf compound data types, speaking, reading and writing
随机推荐
C# One Week Introductory "C# - Classes and Objects" Day Six
光明区关于促进科技创新的若干措施(征求意见稿)
Golang channel implementation principle
罗湖区工匠技能领军人才奖励项目申请指南
WPF introduces ttf icon file usage record
Golang eight-legged text finishing (continuous handling)
C语言实现安全性极高的游戏存档并读档
聊一聊什么是SaaS,以及遇到的问题......
05 Detailed explanation of the global configuration file application.properties
Image stitching (registration) case based on OpenCV
WPF recursively obtains the list of specified control types in the form
(RCE) Remote Code/Command Execution Vulnerability Vulnerability Exercise
Usage when saving pointers in std::vector
A must see for software testers!Database knowledge MySQL query statement Daquan
如何与墨西哥大众VW Mexico建立EDI连接
5. View parsing and template engine
五、视图解析与模板引擎
Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering
[Vitis] Code implementation of ZCU102 development board PS-side control PL-side reset
Three Solutions for SaaS Multi-tenant Data Isolation