國產龍芯服務器源碼安裝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

界面效果:

 

 

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

 

 需要修改安全配置, 注意 數據庫的配置文件就在/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

 

 注意 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 進行連接測試.

 

 安裝完成. 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM