1、postgresql的基础安装与部署

1、基础安装与部署

机型2c_4g_20hd

1.1 yum源安装(安装完成之后解释一下各个路径位置)

路径说明yum方式安装编译安装[可自己修改]
数据目录/var/lib/pgsql/10/data/pgdata/10/data
包目录/usr/pgsql-10/bin//opt/pg10/
1.1.1yum安装步骤

进入官网找到下载源地址,选择对应的系统
更正一下,此处yum安装12版本

下载地址:https://www.postgresql.org/download/linux/redhat/

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql12-server
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl enable postgresql-12
sudo systemctl start postgresql-12

执行完以上操作,yum方式安装pg10已经完成,安装时候自动生成了postgres用户,以下检测一下是否可用

[root@localhost ~]# ps -ef|grep pg
postgres   2292      1  0 01:08 ?        00:00:00 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/
root      10139   1953  0 01:09 pts/0    00:00:00 grep --color=auto pg
[root@localhost ~]# /usr/pgsql-10/bin/psql 
psql: FATAL:  role "root" does not exist
[root@localhost ~]# su - postgres
-bash-4.2$ psql
psql (10.21)
Type "help" for help.

postgres=# 
1.1.2通过yum安装的各个文件位置

如何找到命令存放目录:ps -ef|grep pg

其中:/usr/pgsql-10/bin/postmaster是启动进程

​ /var/lib/pgsql/10/data/是数据目录

数据存放目录:/var/lib/pgsql/10/data

[root@localhost data]# pwd
/var/lib/pgsql/10/data
[root@localhost data]# ls
base              log           pg_hba.conf    pg_multixact  pg_serial     pg_stat_tmp  pg_twophase  pg_xact               postmaster.opts
current_logfiles  pg_commit_ts  pg_ident.conf  pg_notify     pg_snapshots  pg_subtrans  PG_VERSION   postgresql.auto.conf  postmaster.pid
global            pg_dynshmem   pg_logical     pg_replslot   pg_stat       pg_tblspc    pg_wal       postgresql.conf

命令存放目录:/usr/pgsql-10/bin

[root@localhost bin]# ps -ef|grep pg
postgres   2292      1  0 10:46 ?        00:00:00 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/
root      10811  10598  0 10:57 pts/0    00:00:00 grep --color=auto pg
[root@localhost bin]# pwd
/usr/pgsql-10/bin
[root@localhost bin]# ls
clusterdb   dropdb    pg_archivecleanup  pg_config       pg_dump     pg_receivewal  pg_rewind       pg_upgrade  postgresql-10-check-db-dir  psql
createdb    dropuser  pg_basebackup      pg_controldata  pg_dumpall  pg_resetwal    pg_test_fsync   pg_waldump  postgresql-10-setup         reindexdb
createuser  initdb    pgbench            pg_ctl          pg_isready  pg_restore     pg_test_timing  postgres    postmaster                  vacuumdb

1.2 源码编译安装(要科学的安装规划路径)

下载源码地址:

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

1.2.1将包放在soft目录下
[root@localhost soft]# pwd
/root/soft
[root@localhost soft]# ls
postgresql-10.20.tar.gz
1.2.2准备编译环境和数据目录
yum groupinstall "Development tools"
yum install -y bison flex readline-devel zlib-devel
mkdir -p /pgdata/10/{data,backups,scripts,archvie_wals}
chown -R postgres.postgres /pgdata/10
chmod 0700 /pgdata/10/data
1.2.3解压安装包,编译安装
[root@localhost soft]# tar -zxvf postgresql-10.20.tar.gz
[root@localhost soft]# cd postgresql-10.20
[root@localhost postgresql-10.20]# ./configure --prefix=/opt/pg10/ --with-pgport=54321

执行gmake ,gmake install

gmake  #出现successfully成功
gmake install  #PostgreSQL installation complete.安装成功

查看安装版本

[root@localhost postgresql-10.20]# /opt/pg10/bin/postgres --version
postgres (PostgreSQL) 10.20
[root@localhost postgresql-10.20]# 
1.2.4设置/opt/pgsql的软连接指向当前版本,当变更版本的时候修改软连接即可
ln -s /opt/pg10/ /opt/pgsql
[root@localhost opt]# ll
total 0
drwxr-xr-x. 6 root root 56 Jun 13 01:48 pg10
lrwxrwxrwx. 1 root root 10 Jun 13 01:49 pgsql -> /opt/pg10/
1.2.5创建用户组和用户命令
[root@localhost opt]# groupadd -g 1001 postgres
[root@localhost opt]# useradd -g 1001 -u 1001 postgres
[root@localhost opt]# id postgres
uid=1001(postgres) gid=1001(postgres) groups=1001(postgres)
1.2.6切换为postgres用户,初始化数据库目录
-bash-4.2$ /opt/pgsql/bin/initdb -D /pgdata/10/data/ -W
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 "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password: 
Enter it again: 

fixing permissions on existing directory /pgdata/10/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... America/New_York
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:

    /opt/pgsql/bin/pg_ctl -D /pgdata/10/data/ -l logfile start

到此,pg的编译安装部署完毕。

连接到刚安装好的数据库:

psql -p 端口 -h IP地址 -U 用户名称

-bash-4.2$ psql -p 54321 -h 127.0.0.1 -U postgres
psql (10.21, server 10.20)
Type "help" for help.

postgres=# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值