国产龙芯服务器源码安装PostgreSQL数据库的方法

1. 公司最近有一些国产化项目的需求, 要求在国产CPU的服务器上面安装pg数据库等.linux

2.. 可是差查了下中标麒麟的官网,在龙芯MIPS的操做系统包源里面仅有 postgreSQL 9.2 版本的rpm包, 可是要求最低版本是10.x 因此没办法就采起源码安装的方式进行安装.sql

3. 安装过程.(备注arm的CPU 无论是 飞腾的仍是华为的过程应该都是如出一辙的)数据库

3.1 下载源码包bootstrap

百度搜索postgreslq的官网,而后下载源码便可.vim

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 目录中post

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 修改环境变量ui

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 进行链接测试.

 

 安装完成. 

相关文章
相关标签/搜索