postgressql安装 基于pgpool-ii的集群配置(一)

本文详细介绍了在Linux环境下安装配置PostgreSQL集群的过程,包括安装基础依赖、编译安装PostgreSQL、配置环境变量、系统参数调整及数据库配置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1     集群安装配置

1.1      安装Linux环境依赖

以下两个依赖包是postgresql数据库安装的基础。

rm -f /var/run/yum.pid            非必须执行项

yum install gcc-c++              必须执行项

yum install flex                  必须执行项

yum -y install -y readline-devel    非必须执行项

yuminstall zlib-devel             非必须执行项

1.2      postgresql安装

1.2.1     上传postgresql源码

su - root              root用户登录

mkdir /opt/soft_bak    新建目录

cd /opt/soft_bak      切换目录

上传postgresql-9.3.2.tar.bz2 到/opt/soft_bak目录

1.2.2     解压缩postgresql源码

tar -jxvf postgresql-9.3.2.tar.bz2

cd postgresql-9.3.2  切换到postgresql-9.3.2解压缩目录下

1.2.3     安装配置postgresql

./configure --prefix=/opt/pgsql932 设定postgresql数据库管理系统安装位置

gmake world   编译源码

gmake install-world 安装源码

1.2.4     添加用户

useradd pg93 添加安装启动管理数据库的普通用户

passwd pg93 设置密码cuipeng

1.2.5     配置环境变量

vi /home/pg93/.bash_profile 设置环境变量,添加内容如下:

export PGPORT=1999 

export PGDATA=/home/pg93/pg_root

export LANG=en_US.utf8

export PGHOME=/opt/pgsql932

exportLD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH

export DATE=`date +"%Y%m%d%H%M"`

export PATH=$PGHOME/bin:$PATH:.

export MANPATH=$PGHOME/share/man:$MANPATH

export PGUSER=postgres

export PGHOST=$PGDATA 

alias rm='rm -i'

alias ll='ls -lh'

export PGDATABASE=postgresql

1.2.6     设置目录目录权限

chmod 755 /home/      设置目录权限,这里不允许设置777,否则Linux互信不好使

chmod 755 /home/pg93/ 设置目录权限,这里不允许设置777,否则Linux互信不好使

1.2.7     检测数据库管理系统

su - pg93

which psql 检查psql数据库管理系统是否安装正常

psql -V检查psql数据库管理系统是否安装正常

echo $PGDATA检查psql数据库管理系统是否安装正常

echo $PGHOME检查psql数据库管理系统是否安装正常

1.2.8     初始化数据库

initdb -D $PGDATA -E UTF8 --locale=C -Upostgres -W 初始化数据库

超级管理员密码设置为cuipeng

1.3      linux系统参数调整

1.3.1     修改系统变量

su - root

vi /etc/sysctl.conf

kernel.shmmni = 4096

kernel.sem = 50100 64128000 50100 1280

fs.file-max = 7672460

net.ipv4.ip_local_port_range = 9000 65000

net.core.rmem_default = 1048576

net.core.rmem_max = 4194304

net.core.wmem_default = 262144

net.core.wmem_max = 1048576

1.3.2     设置区域大小

vi /etc/security/limits.conf

soft nofile 131072

hard nofile 131072

soft nproc 131072

hard nproc 131072

soft core unlimited

hard core unlimited

soft memlock 50000000

hard memlock 50000000

 

1.3.3     关闭防火墙

Centos6.x适用

chkconfig iptables off

service iptables stop

 

Centos7.x适用
systemctl start firewalld.service #
启动firewall
systemctl stop firewalld.service #
停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

 

1.4      postgresql配置

su - pg93

cd $PGDATA

vi pg_hba.conf  添加内容如下:

host    all all  0.0.0.0/0  md5

 

vi postgresql.conf添加内容如下:

listen_addresses = '0.0.0.0'                                                                                                                   

port = 1999                                            

superuser_reserved_connections = 20   

unix_socket_directories = '.'                     

unix_socket_permissions = 0700         

tcp_keepalives_idle = 60                               

tcp_keepalives_interval = 10          

tcp_keepalives_count = 10             

vacuum_cost_delay = 10                 

bgwriter_delay = 10ms

synchronous_commit = off               

checkpoint_segments = 8       

wal_writer_delay = 10ms        

log_destination = 'csvlog'

logging_collector = on        

log_directory = 'pg_log'               

log_filename ='postgresql-%Y-%m-%d_%H%M%S.log'

log_file_mode = 0600                                     

log_truncate_on_rotation = on          

log_rotation_age = 1d                                      

log_rotation_size = 10MB

 

1.5      测试数据库是否安装成功

su - pg93

pg_ctl start 启动数据库

pg_ctl -m fast stop 停止数据库

pg_ctl restart 重启数据库

Linux下执行:

ps -ef | grep postgres         数据库服务是否正常启动

psql -h 127.0.0.1 -p 1999 -U postgrespostgres   登录数据库

 

以上步骤请在两个Linux系统中安装两套数据库系统,用来配置双机热备节点。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值