EnterpriseDB: 无人值守安装

上篇博客介绍了EDB 交互式命令行安装方式,EDB同时支持无人值守安装,极大提升了部署效率。

EDB 的无人值守安装是通过预先定义安装配置文件实现的,本文简单演示下。

定义安装配置文件

创建配置文件如下

1
touch /opt/edb/config_edb.conf

给配置文件 /opt/edb/config_edb.conf加入以下内容:

1
2
3
4
5
6
mode=unattended
superpassword=xxxxxx
prefix=/opt/edb
datadir=/opt/edb/data
xlogdir=/opt/edb/data/pg_wal
serverport=5444

参数解释如下:

  • mode: 指定 unattended 模式,表示无人值守安装模式。
  • superpassword: 设置数据库超级用户密码,默认密码为 enterprisedb。
  • prefix: 设置EDB的软件安装目录。
  • datadir: 设置EDB的数据文件目录,对应的环境变量为$PGDATA。
  • xlogdir: 设置wal文件的目录。
  • serverport: 设置EDB的监听端口号,默认为5444。

其它参数根据需要设置。

无人值守安装 EDB

执行安装脚本 edb-as10-server-10.5.12-1-linux-x64.run,并使用 optionfile 指定安装配置文件,如下:

1
[root@pghost6 soft_bak]# ./edb-as10-server-10.5.12-1-linux-x64.run --optionfile /opt/edb/config_edb.conf

无人值守安装无输出结果,验证EDB是否已安装成功。

查看EDB安装文件,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@pghost6 edb]# ll /opt/edb
total 8200
drwxr-xr-x 3 root root 18 Jan 16 10:07 as10
drwxr-xr-x 2 root daemon 4096 Jan 16 10:07 bin
-rw-r--r-- 1 root root 97 Jan 16 10:06 config_edb.conf
drwx------ 20 enterprisedb enterprisedb 4096 Jan 16 10:07 data
drwxr-xr-x 4 root daemon 38 Jan 16 10:06 doc
-rw-r--r-- 1 root daemon 72341 Aug 17 14:09 edb-as10-server_commandlinetools_3rd_party_licenses.txt
-r--r--r-- 1 root daemon 15216 Aug 17 14:09 edb-as10-server_license.txt
drwxr-xr-x 3 root daemon 23 Jan 16 10:06 etc
drwxr-xr-x 6 root daemon 4096 Jan 16 10:06 include
-rw-r--r-- 1 root root 612 Jan 16 10:07 installation_summary.log
drwxr-xr-x 5 root daemon 55 Jan 16 10:06 installer
drwxr-xr-x 4 root daemon 8192 Jan 16 10:07 lib
drwxr-xr-x 10 root daemon 164 Jan 16 10:06 pgAdmin4
-rwxr-xr-x 1 root daemon 915 Jan 16 10:07 pgplus_env.sh
drwxr-xr-x 5 root daemon 73 Jan 16 10:06 scripts
drwxr-xr-x 10 root daemon 4096 Jan 16 10:06 share
drwxr-xr-x 7 root daemon 136 Jan 16 10:06 stackbuilderplus
-rwx------ 1 root daemon 8118363 Jan 16 10:07 uninstall-edb-as10-server
-rw------- 1 root root 141150 Jan 16 10:07 uninstall-edb-as10-server.dat

目录的权限为root,权限需要调整(安装过程中默认创建了 enterprisedb 操作系统用户)

1
[root@pghost6 ~]# chown -R enterprisedb:enterprisedb /opt/edb

查看EDB数据库进程,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@pghost6 soft_bak]# ps -ef | grep post
root 1232 1 0 2018 ? 00:00:18 /usr/libexec/postfix/master -w
postfix 1240 1232 0 2018 ? 00:00:04 qmgr -l -t unix -u
postfix 6373 1232 0 08:37 ? 00:00:00 pickup -l -t unix -u
enterpr+ 12677 1 0 10:07 ? 00:00:00 /opt/edb/bin/edb-postgres -D /opt/edb/data
enterpr+ 12678 12677 0 10:07 ? 00:00:00 postgres: logger process
enterpr+ 12680 12677 0 10:07 ? 00:00:00 postgres: checkpointer process
enterpr+ 12681 12677 0 10:07 ? 00:00:00 postgres: writer process
enterpr+ 12682 12677 0 10:07 ? 00:00:00 postgres: wal writer process
enterpr+ 12683 12677 0 10:07 ? 00:00:00 postgres: autovacuum launcher process
enterpr+ 12684 12677 0 10:07 ? 00:00:00 postgres: stats collector process
enterpr+ 12685 12677 0 10:07 ? 00:00:00 postgres: bgworker: dbms_aq launcher
enterpr+ 12686 12677 0 10:07 ? 00:00:00 postgres: bgworker: logical replication launcher
enterpr+ 12698 12677 0 10:07 ? 00:00:00 postgres: bgworker: dbms_aq worker[postgres] idle
enterpr+ 12704 12677 0 10:07 ? 00:00:00 postgres: bgworker: dbms_aq worker[edb] idle
root 12713 22990 0 10:07 pts/0 00:00:00 grep --color=auto post

说明 EDB 已安装并且数据库已启动。

设置环境变量

安装完成后自动生成环境变量文件 /opt/edb/pgplus_env.sh, 脚本内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# EnterpriseDB shell environment loader
#
# Instructions:
# This file contains additions to the user environment
# that make accessing EDB Postgres Advanced Server
# executables easier.
#
# To load the environment for a single user:
# cp pgplus_env.sh /home/<username>
# chown <username> /home/<username>/pgplus_env.sh
# vi /home/<username>/.bash_profile
# At the bottom, add the line:
# . /home/<username>/pgplus_env.sh
# ( Note the '.' followed by a space )

# To load the environment for all users:
# cp pgplus_env.sh /etc
# vi /etc/profile
# At the bottom, add the line:
# . /etc/pgplus_env.sh
# ( Note the '.' followed by a space )

# Environment

export PATH=/opt/edb/bin:$PATH
export EDBHOME=/opt/edb
export PGDATA=/opt/edb/data
export PGDATABASE=edb
# export PGUSER=enterprisedb
export PGPORT=5444
export PGLOCALEDIR=/opt/edb/share/locale

将整个文件内容或尾部的环境变量加到系统用户 enterprisedb 环境变量文件 .bash_profile 中,如下:

1
2
3
4
[root@pghost6 ~]# su - enterprisedb
Last login: Tue Jan 15 11:00:16 CST 2019 on pts/1

-bash-4.2$ cp /opt/edb/pgplus_env.sh /opt/edb/.bash_profile

登录EDB验证

登录 EDB 数据库,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-bash-4.2$ psql -h 127.0.0.1 -p 5444 edb enterprisedb
Password for user enterprisedb:
psql.bin (10.5.12)
Type "help" for help.

edb=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU | Access privileges
-----------+--------------+----------+-------------+-------------+-----+-------------------------------
edb | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | |
postgres | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | |
template0 | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | =c/enterprisedb +
| | | | | | enterprisedb=CTc/enterprisedb
template1 | enterprisedb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | =c/enterprisedb +
| | | | | | enterprisedb=CTc/enterprisedb
(4 rows)

edb=# SELECT version();
version
--------------------------------------------------------------------------------------------------------------
EnterpriseDB 10.5.12 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18), 64-bit
(1 row)

参考

最后推荐和张文升共同编写的《PostgreSQL实战》,本书基于PostgreSQL 10 编写,共18章,重点介绍SQL高级特性、并行查询、分区表、物理复制、逻辑复制、备份恢复、高可用、性能优化、PostGIS等,涵盖大量实战用例!

购买链接:https://item.jd.com/12405774.html

PostgreSQL实战
感谢支持!
0%