安装postgres

分享到:

安装postgres

https://www.postgresql.org/about/news/1957/ 官网

安装postgres

https://github.com/Kong/kubernetes-ingress-controller/blob/master/deploy/manifests/postgres/postgres.yaml

安装postgres-operator

 1git clone https://github.com/zalando/postgres-operator.git
 2cd postgres-operator
 3
 4# 处理好postgres-operator.yaml中的镜像;
 5docker pull dongzhangqi/postgres-operator:v1.2.0
 6
 7docker tag dongzhangqi/postgres-operator:v1.2.0 registry.opensource.zalan.do/acid/postgres-operator:v1.2.0
 8
 9docker rmi dongzhangqi/postgres-operator:v1.2.0
10
11# 或者修改postgres-operator.yaml中的镜像(推荐,因为你不知道pod在哪个k8s集群的节点上,所以每个node都要tag镜像)
12dongzhangqi/postgres-operator:v1.2.0
13
14
15# apply the manifests in the following order
16kubectl create -f manifests/configmap.yaml  # configuration
17kubectl create -f manifests/operator-service-account-rbac.yaml  # identity and permissions
18kubectl create -f manifests/postgres-operator.yaml  # deployment

Create a Postgres cluster

1# if you've created the operator using yaml manifests
2kubectl get pod -l name=postgres-operator
3
4# if you've created the operator using helm chart
5kubectl get pod -l app.kubernetes.io/name=postgres-operator
6
7# create a Postgres cluster
8kubectl create -f manifests/minimal-postgres-manifest.yaml
1# check the deployed cluster
2kubectl get postgresql
3
4# check created database pods
5kubectl get pods -l application=spilo -L spilo-role
6
7# check created service resources
8kubectl get svc -l application=spilo -L spilo-role

Connect to the Postgres cluster via psql

Delete a Postgres cluster

1kubectl delete postgresql acid-minimal-cluster

本地安装

 1--postgresql安装
 2yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm 安装存储库
 3yum -y install postgresql11 安装客户端
 4yum -y install postgresql11-server 安装服务端
 5rpm -aq| grep postgres验证安装情况
 6/usr/pgsql-11/bin/postgresql-11-setup initdb 初始化数据库
 7systemctl enable postgresql-11 开机启动
 8systemctl start postgresql-11 启动PG
 9sudo su - postgres 切换用户
10psql -d postgres 登录数据库
11#或者 psql -U postgres 登录数据库
12ALTER USER postgres WITH PASSWORD 'postgres';修改密码
13CREATE DATABASE kong; 创建数据库
14CREATE USER kong CREATEDB LOGIN PASSWORD 'postgres';创建登录用户
15GRANT ALL ON DATABASE kong TO kong;分配权限
16\q 退出
17systemctl restart postgresql-11 重启
18
19--postgresql配置
20开启远程访问
21vim /var/lib/pgsql/11/data/postgresql.conf
22修改#listen_addresses = 'localhost' 为 listen_addresses='*’
23此处‘*’也可以改为任何你想开放的服务器IP
24信任远程连接
25vim /var/lib/pgsql/11/data/pg_hba.conf
26修改如下内容,信任指定服务器连接 
27# IPv4 local connections: 
28host all all 0.0.0.0/0 trust
29
30systemctl restart postgresql-11 重启
31
32

连接 ip

用户 postgres 密码 postgres 用户 kong 密码 postgres