学习是一种信仰
分类: Mysql/postgreSQL
2015-09-30 16:41:23
设置环境变量
1.配置内核参数
vi /etc/sysctl.conf
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
vm.overcommit_memory = 0
将参数加载到内核,执行sysctl –p
2.配置limits.conf文件
vi /etc/security/limits.conf
* soft memlock 50000000
* hard memlock 50000000
安装
1.创建pg用户及组
[root@localhost]# groupadd postgres
[root@localhost]# useradd -g postgres postgres
[root@localhost]# passwd postgres
2. 解压安装包postgresql-9.4.1.tar.bz2
[root@localhost src]# tar -jxvf postgresql-9.4.1.tar.bz2
[root@localhost src]# cd postgresql-9.4.1
3. 编译postgresql源码
[root@localhost postgresql-9.4.1]# yum -y install readline-devel.x86_64
[root@localhost postgresql-9.4.1]# yum -y install zlib-devel.x86_64
[root@localhost postgresql-9.4.1]# ./configure --prefix=/usr/local/postgresql-9.4.1 --with-pgport=5432
[root@localhost pgsql-9.4.1]# make
[root@localhost pgsql-9.4.1]# make install
[root@localhost pgsql-9.4.1]# cd /usr/local
[root@localhost local]# ln -s postgresql-9.4.1 pgsql
[root@localhost local]# chown -R postgres:postgres postgresql-9.4.1
[root@localhost local]# chown -R postgres:postgres pgsql
注:编译安装过程中可能因为缺包报错,缺什么补什么,再重新执行即可。
4. 设置Postgres用户环境变量
[root@localhost local]# su - postgres
[postgres@localhost ~]$ more .bash_profile
[postgres@localhost ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export PGPORT=5432
export PGHOME=/usr/local/pgsql
export PGDATA=/PGDATA/data
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
[postgres@localhost ~]$ source .bash_profile
5 初始化数据库
[root@localhost]mkdir -p /PGDATA/data
[root@localhost]chown -R postgres:postgres /PGDATA
[root@localhost] su - postgres
[postgres@localhost ~]$initdb
6. 设置Postgres开机自启动
[root@localhost start-scripts]# cd /usr/local/src/postgresql-9.4.1/contrib/start-scripts
[root@localhost start-scripts]# cp /usr/local/src/postgresql-9.4.1/contrib/start-scripts/linux /etc/init.d/postgresql
[root@localhost start-scripts]# cd /etc/init.d/
[root@localhost init.d]# ls -l|grep -i postgresql
-rw-r--r-- 1 root root 3437 Jul 29 09:45 postgresql
[root@localhost init.d]# chmod +x postgresql
[root@localhost init.d]# vi postgresql
#prefix=/usr/local/pgsql
prefix=/usr/local/pgsql --postgresql安装路径
#PGDATA="/usr/local/pgsql/data"
PGDATA=/PGDATA/data --postgresql的数据目录路径
设置postgresql服务开机自启动
[root@localhost init.d]# chkconfig --add postgresql
配置postgres数据库(/pgdata/data下)
1. 修改pg_hba.conf文件,对访问数据库的服务器添加信任
[postgres@localhost ~]$ cd /PGDATA/data
vi pg_hba.conf
host all all 192.168.xxx.xxx/32 md5
2. 修改PostgreSQL.conf文件
[postgres@xing data]$ vi postgresql.conf
listen_addresses = '*'
port = 5432
max_connections = 300
shared_buffers = 512MB
wal_level = hot_standby
checkpoint_segments = 16
archive_mode = on
archive_command = 'cp -i %p /PGDATA/archive_log/%f'
max_wal_senders = 5
wal_keep_segments = 1000
hot_standby = on
log_destination = 'csvlog'
logging_collector = on
log_directory = '/PGDATA/data/pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_line_prefix = '%t %r %a %d %c %u'
autovacuum = off
3 创建归档日志目录
[postgres@ localhost]$ mkdir -p /PGDATA/archive_log
启动数据库
[postgres@ localhost data]$pg_ctl start