麒麟v10 arm架构安装PostgreSQL

创建日期:2025-01-07
更新日期:2025-01-07

PostgreSQL源码下载地址:Index of /pub/source/

安装方法

1、查询麒麟系统版本。

nkvers

返回值

############## Kylin Linux Version #################
Release:
Kylin Linux Advanced Server release V10 (Lance)

Kernel:
<ol class="list-group list-group-numbered">
<li class="list-group-item border-0">19.90-52.22.v2207.ky10.aarch64</li>
</ol>

Build:
Kylin Linux Advanced Server
release V10 (SP3) /(Lance)-aarch64-Build23/20230324
#################################################

2、下载PostgreSQL源码。

curl https://ftp.postgresql.org/pub/source/v16.6/postgresql-16.6.tar.gz -o postgresql-16.6.tar.gz

3、解压PostgreSQL源码压缩包。

postgres]# tar -zvxf postgresql-16.6.tar.gz

4、安装依赖包。

yum install readline.aarch64 readline-devel.aarch64

5、编译并安装PostgreSQL。

cd postgresql-16.6/
./configure --prefix=/opt/postgresql --without-readline
make
make install

6、配置环境变量。

cd /etc/profile.d/
vim postgresql.sh

编辑文件

export PGHOME=/opt/postgresql
export PGDATA=/opt/postgresql/data
export PATH=$PGHOME/bin:$PATH
export LANG=en_US.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH

运行文件

source postgresql.sh

7、 创建用户和数据中心。

useradd postgres
mkdir -p /opt/postgresql/data/pgsql
chown postgres:postgres /opt/postgresql/data/pgsql

8、初始化数据库。

su - postgres
/opt/postgresql/bin/initdb -D /opt/postgresql/data/pgsql

9、配置监听的IP地址。

vim /opt/postgresql/data/pgsql/postgresql.conf

找到并修改下面一行:

#listen_addresses = 'localhost'

10、配置允许远程访问。

vim /opt/postgresql/data/pgsql/pg_hba.conf

修改

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

trust表示无密码登录,md5表示使用密码登录。

11、启动数据库。

/opt/postgresql/bin/pg_ctl -D /opt/postgresql/data/pgsql -l logfile start

12、验证5432端口是否开启。

netstat -anp|grep 5432