设为首页 收藏本站
查看: 1431|回复: 0

[经验分享] 源码安装Postgresql9.5

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-9-22 09:35:58 | 显示全部楼层 |阅读模式
Postgresql简介:

PostgreSQL是一个功能强大,开源对象关系型数据库系统。它拥有超过15年的持续开发和经验证的体系结构,赢得了良好的声誉:可靠性,数据完整性和正确性

官方号称:
PostgreSQL: The world's most advanced open source database

官网下载地址:https://www.postgresql.org/download/
Postgresql部署:
环境:

[iyunv@node-01 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

下载包:

[iyunv@node-01 ~]# wget https://ftp.postgresql.org/pub/s ... gresql-9.5.4.tar.gz

安装依赖包:

[iyunv@node-01 ~]# yum install gcc gcc-c++ automake autoconf libtool make readline-devel zlib-devel  -y
[iyunv@node-01 ~]# yum install -y perl-ExtUtils-Embed  perl-ExtUtils-MakeMake perl-ExtUtils-MakeMaker-Coverage readline readline-devel pam pam-devel libxml2 libxml-devel libxml2-python libxml2-static  libxslt libxslt-devel  tcl tcl-devel python-devel openssl openssl-devel

创建postgresql用户及设置密码(postgresql默认不允许root用户启动):

[iyunv@node-01 ~]# useradd -u 6233 -p 123456 postgres   
[iyunv@node-01 ~]# id postgres
uid=6233(postgres) gid=6233(postgres) groups=6233(postgres)

编译安装postgresql:

[iyunv@node-01 ~]# tar -xf postgresql-9.5.4.tar.gz
[iyunv@node-01 ~]# cd postgresql-9.5.4
[iyunv@node-01 postgresql-9.5.4]# ./configure --prefix=/usr/local/postgresql  --with-pgport=1921 --with-perl --with-tcl --with-python --with-openssl --with-pam  --with-libxml --with-libxslt --enable-thread-safety --with-wal-blocksize=16 --with-blocksize=16
编译安装有两种方式:make和gmake,这里推荐gmake
方法1:gmake world &&  gmake install-world
方法2:make -j 4 && make install
[iyunv@node-01 postgresql-9.5.4]# gmake world &&  gmake install-world
[iyunv@node-01 postgresql-9.5.4]# ls /usr/local/postgresql/
bin  include  lib  share

设置数据库目录及权限:

[iyunv@node-01 ~]# mkdir -p /data/postgresql
[iyunv@node-01 ~]# chown -R postgres.postgres /data/postgresql/

添加系统环境变量:

[iyunv@node-01 ~]# echo 'export PATH=$PATH:/usr/local/postgresql/bin/' >> /etc/profile
[iyunv@node-01 ~]# psql -V
psql (PostgreSQL) 9.5.4

初始化数据库:

[iyunv@node-01 ~]# su - postgres
[postgres@node-01 ~]$ initdb -D /data/postgresql/ -U postgres -E UTF8 --locale=C -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 "C".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /data/postgresql ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /data/postgresql/base/1 ... ok
initializing pg_authid ... ok
Enter new superuser password:      设置超级用户的密码
Enter it again:
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... 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:

    pg_ctl -D /data/postgresql/ -l logfile start

参数:
-U postgres:指定的数据库超级管理员,自定义
-W :设置密码
-D :数据存放目录
-E :设置编译

修改验证方式简单的配置:

[postgres@node-01 ~]$ vim /data/postgresql/pg_hba.conf
host    all             all             127.0.0.1/32            md5    MD5验证方式需要输入用户密码
[postgres@node-01 ~]$ vim /data/postgresql/postgresql.conf
port = 1236                            # (change requires restart)
max_connections = 100
unix_socket_directories = '/dev/shm/'

添加服务管理脚本:

[iyunv@node-01 ~]# cd postgresql-9.5.4
[iyunv@node-01 postgresql-9.5.4]# cp contrib/start-scripts/linux /etc/init.d/postgresql
[iyunv@node-01 postgresql-9.5.4]# chmod +x /etc/init.d/postgresql
[iyunv@node-01 postgresql-9.5.4]# chkconfig postgresql on
[iyunv@node-01 postgresql-9.5.4]# vim /etc/init.d/postgresql
prefix=/usr/local/postgresql
PGDATA="/data/postgresql"
PGUSER=postgres
PGLOG="$PGDATA/serverlog"

启动postgresql:

[iyunv@node-01 postgresql-9.5.4]# /etc/init.d/postgresql start
[iyunv@node-01 postgresql-9.5.4]#  lsof -i :1236              
COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postmaste 16232 postgres    3u  IPv6  53256      0t0  TCP localhost:bvcontrol (LISTEN)
postmaste 16232 postgres    4u  IPv4  53257      0t0  TCP localhost:bvcontrol (LISTEN)

登陆postgresql:

[iyunv@node-01 ~]# psql -h 127.0.0.1 -p 1236 -U postgres -d postgres
Password for user postgres:
psql (9.5.4)
Type "help" for help.

postgres=#

安装所有的扩展包:

[iyunv@node-01 ~]# cd postgresql-9.5.4/contrib/  
[iyunv@node-01 contrib]# ls -d */ | xargs -n 1 -P 0 sh -c 'cd {}; make ; make install;'c




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-275811-1-1.html 上篇帖子: ubuntu编译安装postgresql及主从配置 下篇帖子: postgresql同步流复制搭建
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表