本站总访问量 postgresql数据库+SSL搭建 - Jerry的小站

Jerry Gao

上帝就是真理,真理就是上帝

Postgresql是一个功能强大的开源对象关系数据库管理系统(ORDBMS),它是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系数据库管理系统。POSTGRES的许多领先概念只是在商业数据库中实现,而PostgreSQL是一个真正的开源数据库,它的源代码是开放的,任何人都可以免费使用。

特性:

  • 复杂的查询
  • 支持多版本并发控制
  • 支持外键、触发器、视图、事务
  • 支持函数和存储过程
  • 支持大型对象
  • 支持表空间
  • 支持异步复制
  • 支持表继承
  • 支持规则
  • 支持自定义数据类型
  • 支持自定义索引方法
  • 支持Unicode

Kubernetes部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgresql-ssl
namespace: stable-db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
storageClassName: standard-rwo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgresql-ssl
namespace: stable-db
labels:
app: postgresql-ssl
spec:
replicas: 1
selector:
matchLabels:
app: postgresql-ssl
template:
metadata:
labels:
app: postgresql-ssl
spec:
volumes:
- name: postgresql-ssl
persistentVolumeClaim:
claimName: postgresql-ssl
containers:
- name: postgresql-ssl
image: <镜像tag>
ports:
- name: tcp-0
containerPort: 5432
protocol: TCP
env:
- name: POSTGRES_USER
value: <用户名>
- name: POSTGRES_PASSWORD
value: <密码>
- name: POSTGRES_DB
value: <数据库名>
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
volumeMounts:
- name: postgresql-ssl
mountPath: /var/lib/postgresql/data
subPath: pgdata
livenessProbe:
tcpSocket:
port: 5432
initialDelaySeconds: 30
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
startupProbe:
tcpSocket:
port: 5432
initialDelaySeconds: 30
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
---
apiVersion: v1
kind: Service
metadata:
name: postgresql-ssl
namespace: stable-db
annotations:
cloud.google.com/l4-rbs: "enabled"
labels:
app: postgresql-ssl
spec:
loadBalancerIP: <IP>
type: LoadBalancer
externalTrafficPolicy: Cluster
ports:
- port: <端口>
nodePort: <端口>
targetPort: 5432
protocol: TCP
selector:
app: postgresql-ssl

docker-compose 部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
version: '3'
services:
postgresql:
image: <镜像tag>
deploy:
replicas: 1
resources:
limits:
cpus: '1'
memory: 2G
reservations:
cpus: '1'
memory: 2G
container_name: postgresql
restart: always
ports:
- "5432:5432"
environment:
- POSTGRES_USER=<username>
- POSTGRES_PASSWORD=<password>
- POSTGRES_DB=<database>
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- /data/postgresqlSSL:/var/lib/postgresql/data/pgdata
- ./conf/pg_hba.conf:/var/lib/postgresql/data/pgdata/pg_hba.conf

评论