centos7安裝postgres-10

[TOC]php

前一篇的centos6安裝postgresql在centos7發生了一些變化。html

安裝

下載yum repo

https://yum.postgresql.org/repopackages.phpsql

yum install pgdg-centos10-10-2.noarch.rpm

安裝server和客戶端

yum install -y postgresql10-server postgresql10

初始化db

/usr/pgsql-10/bin/postgresql-10-setup initdb

數據文件依舊是: /var/lib/pgsql/10/data/數據庫

啓動Postgres

systemctl start postgresql-10

確認端口是否啓動vim

[root@localhost system]# netstat -antup | grep 5432
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      2753/postmaster

設置開機啓動

systemctl enable postgresql-10

服務文件: /usr/lib/systemd/system/postgresql-10.servicecentos

修改data目錄

默認安裝在系統盤下,一般系統盤只有40g。咱們須要將data和log放到咱們的數據盤 。bash

中止服務

systemctl stop postgresql-10

遷移data目錄

複製數據庫文件tcp

cp -R /var/lib/pgsql/10 /data/postgres/db/
chown -R postgres.postgres   /data/postgres/db/

修改postgres用戶的環境變量ide

vim /var/lib/pgsql/.bash_profile
設置
PGDATA=/data/postgres/db/10/data

修改service文件post

vim /usr/lib/systemd/system/postgresql-10.service
設置
Environment=PGDATA=/data/postgres/db/10/data

重啓

systemctl daemon-reload
systemctl start postgresql-10

鏈接測試

切換用戶postgres能夠免密鏈接

su postgres
psql

設置密碼

\password

修改容許遠程其餘IP鏈接

首先進入咱們設置的data目錄

cd /data/postgres/db/10/data

而後 vim pg_hba.conf,添加

# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
host    all             all             10.7.10.1/24           md5

第二行是咱們新增長的,意思是容許10.7.10.1到10.7.10.254的網段經過密碼鏈接。

繼續修改vim postgresql.conf

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 2000                  # (change requires restart)

打開listen_addresses 順手修改下最大鏈接數。

而後重啓就行了。

systemctl start postgresql-10

在另外一臺機器上遠程鏈接測試:

export PGPASSWORD='123456'
psql -Upostgres  -h10.7.10.111

,鏈接成功。

查看最大鏈接數

postgres=# show max_connections;
 max_connections 
-----------------
 2000
(1 row)

原文出處:https://www.cnblogs.com/woshimrf/p/centos7-install-pg10.html

相關文章
相關標籤/搜索