- 在一台可以聯網的centos上安裝postgresql源
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- 使用yumdownloader下載安裝包
yumdownloader --resolve postgresql13-server
- 上傳rpm包到安裝的centos服務器上
-rw-rw-rw- 1 root root 1490812 Sep 27 09:45 postgresql13-13.4-1PGDG.rhel7.x86_64.rpm
-rw-rw-rw- 1 root root 390420 Sep 27 09:45 postgresql13-libs-13.4-1PGDG.rhel7.x86_64.rpm
-rw-rw-rw- 1 root root 5654980 Sep 27 09:45 postgresql13-server-13.4-1PGDG.rhel7.x86_64.rpm
- 批量安裝rpm包
rpm -ivh postgresql13-13.4-1PGDG.rhel7.x86_64.rpm postgresql13-libs-13.4-1PGDG.rhel7.x86_64.rpm postgresql13-server-13.4-1PGDG.rhel7.x86_64.rpm
報錯了,缺少依賴libicu
warning: postgresql13-13.4-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
error: Failed dependencies:
libicu is needed by postgresql13-13.4-1PGDG.rhel7.x86_64
libicui18n.so.50()(64bit) is needed by postgresql13-server-13.4-1PGDG.rhel7.x86_64
libicuuc.so.50()(64bit) is needed by postgresql13-server-13.4-1PGDG.rhel7.x86_64
- 使用yumdownloader下載libicu
yumdownloader --resolve libicu
-rw-r--r-- 1 root root 7250656 Mar 25 2020 libicu-50.2-4.el7_7.i686.rpm
-rw-r--r-- 1 root root 7202728 Mar 25 2020 libicu-50.2-4.el7_7.x86_64.rpm
-rw-r--r-- 1 root root 1490812 Aug 12 18:07 postgresql13-13.4-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 390420 Aug 12 18:07 postgresql13-libs-13.4-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 5654980 Aug 12 18:07 postgresql13-server-13.4-1PGDG.rhel7.x86_64.rpm
刪除libicu-50.2-4.el7_7.i686.rpm(32位安裝包)
6. 重新上傳到需要安裝的服務器,執行安裝命令
rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm postgresql13-13.4-1PGDG.rhel7.x86_64.rpm postgresql13-libs-13.4-1PGDG.rhel7.x86_64.rpm postgresql13-server-13.4-1PGDG.rhel7.x86_64.rpm
- 安裝成功后初始化數據庫
/usr/pgsql-13/bin/postgresql-13-setup initdb
- 開機啟動postgresql數據庫
systemctl enable postgresql-13
- 啟動postgresql數據庫服務
systemctl start postgresql-13
- 創建用戶和數據庫,使用postgres用戶登錄(PostgresSQL安裝后會自動創建postgres用戶,無密碼)
su postgres
- 登錄postgresql數據庫
psql
- 創建用戶和數據庫並授權
create user ycloans with password 'ycloans'; // 創建用戶
create database sonarqube owner ycloans; // 創建數據庫
grant all privileges on database sonarqube to ycloans; // 授權
\q 退出命令模式
13. 開啟遠程訪問,修改/var/lib/pgsql/13/data/postgresql.conf文件,取消 listen_addresses 的注釋,將參數值改為“*”
- 修改/var/lib/pgsql/13/data/pg_hba.conf文件,增加下圖紅框部分內容
- 切換到root用戶,重啟postgresql服務
systemctl restart postgresql-13