天天看點

國産龍芯伺服器源碼安裝PostgreSQL資料庫的方法

1. 公司最近有一些國産化項目的需求, 要求在國産CPU的伺服器上面安裝pg資料庫等.

2.. 但是差查了下中标麒麟的官網,在龍芯MIPS的作業系統包源裡面僅有 postgreSQL 9.2 版本的rpm包, 但是要求最低版本是10.x 是以沒辦法就采取源碼安裝的方式進行安裝.

3. 安裝過程.(備注arm的CPU 不管是 飛騰的還是華為的過程應該都是一模一樣的)

3.1 下載下傳源碼包

百度搜尋postgreslq的官網,然後下載下傳源碼即可.

https://www.postgresql.org/ftp/source/v10.10/

具體的下載下傳位址為:
https://ftp.postgresql.org/pub/source/v10.10/postgresql-10.10.tar.gz
      

界面效果:

國産龍芯伺服器源碼安裝PostgreSQL資料庫的方法

3.2 linux上面建立檔案夾

[root@neoky01 ~]# mkdir /pg10
[root@neoky01 ~]# useradd postgres
[root@neoky01 ~]# mkdir /pgdata
[root@neoky01 ~]# chown postgres:root /pgdata

第一步建立 存放 PG源碼的檔案夾
第二步建立 運作postgreSQL資料庫的使用者
第三步建立 存放postgreSQL資料庫資料檔案的目錄
第四步修改 存放postgreSQL資料庫資料檔案的目錄的屬主      

3.3 将postgresql的源碼上傳至伺服器的/pg10 目錄中

3.4 解壓縮然後進行安裝.

tar -zxvf 解壓縮檔案壓縮包

cd .. 進入到解壓縮後的檔案夾

執行如下指令進行配置.

./configure --without-readline  --without-zlib 

執行 make && make install 進行安裝

龍芯3吖000的機器大約耗時: 900s
15:01 到 15:16

然後進入到 源檔案的 contrib 的目錄下面 執行指令 
make && make install
大約耗時: 120s
15:19 到 15:21      

3.5 修改環境變量

postgresql 源碼安裝預設安裝到 
/usr/local/pgsql/bin
這個目錄中, 為了簡單起見. 可以修改一下 環境變量便于使用.
vim /etc/profile.d/pg.sh
增加上一行内容即可
export PATH=$PATH:/usr/local/pgsql/bin
然後使之生效
source  /etc/profile.d/pg.sh      

3.6 初始化資料庫

需要切換使用者
su - postgres
執行指令:
 initdb -D /pgdata

就完成了資料庫的建立過程.      

一般的提示資訊為:

[root@neoky01 bin]# su - postgres
[postgres@neoky01 ~]$ initdb -D /pgdata
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

fixing permissions on existing directory /pgdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... PRC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /pgdata -l logfile start      

3.7 使用systemd 設定為daemon 服務啟動

注意 需要使用root 使用者進行編輯
vim /etc/systemd/system/pg.service

插入内容:

[Unit]
Description=pg

[Service]
User=postgres

ExecStart=/usr/local/pgsql/bin/postmaster -D /pgdata
Restart=always

[Install]
WantedBy=multi-user.target      

設定服務自動啟動還有開啟服務

systemctl enable pg
systemctl restart pg      

3.8 檢視服務狀态以及修改安全配置

systemctl status pg      
國産龍芯伺服器源碼安裝PostgreSQL資料庫的方法

 需要修改安全配置, 注意 資料庫的配置檔案就在/pgdata 裡面

3.放開監聽以及修改連接配接數等.

vim /pgdata/postgresql.conf

主要修改如下内容:
# - Connection Settings -

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)      

修改安全配置

vim /pgdata/pg_hba.conf

在ipv4 下面增加一行記錄
host    all             all             0.0.0.0/0              md5      
國産龍芯伺服器源碼安裝PostgreSQL資料庫的方法

 注意 md5 必須使用密碼登入 trust 可以不使用密碼登入 非常不安全  是以強烈不建議使用trust ..

3.9 設定 postgres 資料庫使用者的密碼

linux 下面執行指令
su - postgres
然後執行指令
psql
進入postgreSQL資料庫的操作界面, 一般的提示資訊如:      

然後執行指令

alter role postgres with password \'Test6530\';

注意 一定要有 分号, 并且湖之一要有具體的提示資訊才可以.

[root@neoky01 bin]# su - postgres

[postgres@neoky01 ~]$ psql

psql (10.10)

Type "help" for help.

postgres=# alter role postgres with password \'Test6530\';

ALTER ROLE

postgres=#

出現alter role 即可.

3.10 重新開機postgresql 資料庫,并且驗證是否可以連接配接

systemctl restart pg      

然後使用 navicat 進行連接配接測試.

國産龍芯伺服器源碼安裝PostgreSQL資料庫的方法

 安裝完成.