Centos 7 安裝 PostgreSQL

本文只講PostgreSQL在CentOS 7.x 下的安裝,其餘系統請查看:https://www.postgresql.org/downloadsql

PostgreSQL 所用版本爲:PostgreSQL 10數據庫

1.安裝存儲庫vim

https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpmcentos

清華大學鏡像bash

https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/10/redhat/rhel-7-x86_64/服務器

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-1.noarch.rpm

2.安裝客戶端tcp

yum install postgresql10

3.安裝服務端post

yum install postgresql10-server

4.驗證是否安裝成功rest

rpm -aq| grep postgres

輸出以下:postgresql

4.初始化數據庫

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

5.啓用開機自啓動

systemctl enable postgresql-10
systemctl start postgresql-10

6.配置防火牆

firewall-cmd --permanent --add-port=5432/tcp  
firewall-cmd --permanent --add-port=80/tcp  
firewall-cmd --reload

7.修改用戶密碼

su - postgres  切換用戶,執行後提示符會變爲 '-bash-4.2$'
    psql -U postgres 登陸數據庫,執行後提示符變爲 'postgres=#'
    ALTER USER postgres WITH PASSWORD 'postgres'  設置postgres用戶密碼爲postgres
    \q  退出數據庫

8.開啓遠程訪問

vim /var/lib/pgsql/10/data/postgresql.conf
    修改#listen_addresses = 'localhost'  爲  listen_addresses='*'
    固然,此處‘*’也能夠改成任何你想開放的服務器IP

9.信任遠程鏈接

vi m/var/lib/pgsql/10/data/pg_hba.conf
    修改以下內容,信任指定服務器鏈接
    # IPv4 local connections:
    host    all            all      127.0.0.1/32      trust
    host    all            all      192.168.157.1/32(須要鏈接的服務器IP)  trust

10.重啓服務

systemctl restart postgresql-10

11.使用DBMS軟件鏈接

這裏使用的是Navicat

鏈接成功:

相關文章
相關標籤/搜索