签到成功

知道了

CNDBA社区CNDBA社区

postgresql的安装

2016-09-01 21:01 3235 0 原创 PostgreSQL
作者: Expect-乐


1.yum安装

   1.1首先配置一些yum源

        在【Base】和[Update]之间,添加一句exclude=postgresql*。根据官方文档解释:是为了解决依赖性问题:

Configure your YUM repository
Locate and edit your distributions .repo file, located:
On Fedora: /etc/yum.repos.d/fedora.repo and /etc/yum.repos.d/fedora-updates.repo, [fedora] sections
On CentOS: /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
On Red Hat: /etc/yum/pluginconf.d/rhnplugin.conf [main] section
To the section(s) identified above, you need to append a line (otherwise dependencies might resolve to the postgresql supplied by the base repository):
exclude=postgresql*

1.2安装PGDG文件http://www.cndba.cn/Expect-le/article/112

PGDG文件如:

yum local install http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm

1.2.1安装数据库

yum list postgre*

查看相关postgresql相关的包,根据需要安装。http://www.cndba.cn/Expect-le/article/112

yum install postgresql94-server

会自动安装相关的包,这些前面的配置yum就用上了。

1.3初始化数据库

service postgresql-9.4 initdb

然后去/var/lib/pgsql/9.4/data/下就会多了好多文件,这就是数据库的文件。在此之前是咩有文件的。

1.3.1设置数据库自动http://www.cndba.cn/Expect-le/article/112

chkconfig postgresql-9.4 on

1.4查看默认创建PostgreSQL 用户

[root@PGLEI data]# more /etc/passwd|grep postpostfix:x:89:89::/var/spool/postfix:/sbin/nologinpostgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash

1.5打开数据库

service postgresql-9.4 start


1.6删除数据库

yum erase postgresql94*

2.源码安装

2.1必要的包的安装

yum -y install lrzsz sysstat e4fsprogs ntp readline-devel zlib zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc makesmartmontools flex bison perl perl-devel perl-ExtUtils* OpenIPMI-tools systemtap-sdt-devel perl-ExtUtils-Embed

2.2下载一些安装文件

wget https://ftp.postgresql.org/pub/source/v9.4.5/postgresql-9.4.5.tar.bz2
flex:http://sourceforge.net/projects/flex/files/
pgfincore:http://git.postgresql.org/gitweb/?p=pgfincore.git;a=summary

2.3安装flex解压:

xz -d flex-2.5.39.tar.xz        
tar xvf flex-2.5.39.tar ,
./configure,make,make install

查看版本:

flex -V

2.4修改一些系统参数

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
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_syn_backlog = 4096
net.core.netdev_max_backlog = 10000
vm.overcommit_memory = 0
net.ipv4.ip_conntrack_max = 655360
fs.aio-max-nr = 1048576
net.ipv4.tcp_timestamps = 0 
sysclt -p
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

关闭selinuxhttp://www.cndba.cn/Expect-le/article/112

vi /etc/sysconfig/selinux
SELINUX=disable

查看Selinux状态:

/usr/sbin/sestatus -v
getenforce

防火墙关闭或者设置一下只对局域网访问。

查看状态:

service iptables status

修改防火墙:

vi /etc/sysconfig/iptables
-A INPUT -s 192.168.0.0/5432 -j ACCEPT

重启网络:

service network restart

添加用户

useradd postgres
cd /opt/soft_bak/
tar -jxvf postgresql-9.4.4.tar.bz2
tar -zxvf pgfincore.tar.gz
mv pgfincore postgresql-9.4.4/contrib/

 http://www.cndba.cn/Expect-le/article/112

配置postgres用户的参数文件

http://www.cndba.cn/Expect-le/article/112

vi /home/postgres/.bash_profile 
export PGPORT=5432 
export PGDATA=/home/postgres/pgdata 
export.utf8 
export PGHOME=/opt/pgsql 
export LD_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 
export PGDATABASE=postgres

安装systemtap环境 

# uname -r 
2.6.32-358.el6.x86_64
# yum install -y kernel-devel-2.6.32-358.el6.x86_64 kernel-debuginfo-2.6.32-358.el6.x86_64 kernel-debuginfo-common-x86_64-2.6.32-358.el6.x86_64 systemtap stap -v -e 'probe vfs.read {printf("read performed/n"); exit()}'

https://sourceware.org/systemtap/ftp/releases/ 或下载systemtap源码编译

2.5.安装数据库

# cd /opt/soft_bak/postgresql-9.4.4
# ./configure --prefix=/opt/pgsql9.4.4 --with-pgport=5432 --with-perl --with-tcl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enablethread-safety --with-wal-blocksize=8 --with-blocksize=8 
gmake world
gmake install-world
ln -s /opt/pgsql9.4.4 /opt/pgsql(软连接)

初始化数据库: 

# initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W

然后psql进入数据库,

http://www.cndba.cn/Expect-le/article/112
http://www.cndba.cn/Expect-le/article/112

如果报错:

[postgres@prod pgdata]$ psql
psql: could not connect to server: No such file or directory       
 Is the server running locally and accepting    
    connections on Unix domain socket "/home/postgres/pgdata/.s.PGSQL.5432"?

错误原因是没有找到相应的文件:

第一,可以通过:

[postgres@prod pgdata]$ psql -h 127.0.0.1
psql (9.4.4)Type "help" for help.postgres=# /q

第二:修改postgresql.confhttp://www.cndba.cn/Expect-le/article/112

参数:

unix_socket_directories = '/home/postgres/pgdata/'

然后:http://www.cndba.cn/Expect-le/article/112

[postgres@prod pgdata]$  pg_ctl stop -m fast -D $PGDATA
waiting for server to shut down....
LOG:  received fast shutdown request
LOG:  aborting any active transactions
LOG:  autovacuum launcher shutting down
LOG:  shutting down
LOG:  database system is shut down doneserver stopped
[postgres@prod pgdata]$ pg_ctl start -D $PGDATA
server starting
[postgres@prod pgdata]$ LOG:  database system was shut down at 2015-08-24 12:50:41 CST
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
[postgres@prod pgdata]$ psql
psql (9.4.4)Type "help" for help.postgres=# /q

2.5安装pgfincore

cd /opt/soft_bak/postgresql-9.4.4/contrib/pgfincore
./home/postgres/.bash_profile
make clean
makemake install

2.6设置postgresql.conf    

具体参数设置根据实际情况,参考官方文档进行设置,然后重启数据库生效。


版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Expect-乐

Expect-乐

关注

Without the continuous bitter cold, there can be no fragrant plum blossom

  • 336
    原创
  • 6
    翻译
  • 100
    转载
  • 41
    评论
  • 访问:1366296次
  • 积分:1957
  • 等级:核心会员
  • 排名:第3名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ