一、前言

PostgreSQL通常也简称Postgres,是一个关系型数据库管理系统,适用于各种Linux操作系统、Windows、Solaris、BSD和Mac OS X。PostgreSQL遵循PostgreSQL许可,是一个开源软件。PostgreSQL由PostgreSQL全球开发组开发,由极少数的公司志愿组成并进行监督管理,这些公司有红帽、EnterpriseDB等。

PostgreSQL的知名度越来越大,这是理所当然的:它是如此可靠、高效。与传统企业级关系型数据库相比,PostgreSQL完全基于社区驱动,有着丰富的工具和文档,形成了一个完善的生态系统。

目前搜索的大部分CentOS下安装均是用于Centos6.X的部分命令已经有很大变化,本文主要记录在Linux Centos 7.1下安装PostgreSQL的过程。

二、安装PostgreSQL源

CentOS 6.x 32bit

rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-i386/pgdg-centos94-9.4-1.noarch.rpm

CentOS 6.x 64bit

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

CentOS 7 64bit

rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm

在添加源的步骤中并没有太多的区别,主要是源的地址有一定的变化。

三、执行安装命令

yum update

yum install postgresql94-server postgresql94-contrib

四、验证是否安装成功

rpm -aq| grep postgres

执行结果如下:

postgresql94-libs-9.4.1-1PGDG.rhel7.x86_64
postgresql94-server-9.4.1-1PGDG.rhel7.x86_64
postgresql94-9.4.1-1PGDG.rhel7.x86_64
postgresql94-contrib-9.4.1-1PGDG.rhel7.x86_64

五、初始化数据库

CentOS 6.x 系统

service postgresql-9.4 initdb

CentOS 7 系统

/usr/pgsql-9.4/bin/postgresql94-setup initdb

如果我在CentOS 7下执行 service postgresql-9.4 initdb 将会报如下问题

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

六、启动服务并设置为开机启动

CentOS 6.x 系统

service postgresql-9.4 start
chkconfig postgresql-9.4 on

CentOS 7 系统

systemctl enable postgresql-9.4
systemctl start postgresql-9.4

七、开放防火墙端口

CentOS 6.x 系统

vi /etc/sysconfig/iptables

按下I进入输入模式,在文件中加入一下语句

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

输入完成后按ESC退出编辑模式,输入:wq退出VI编辑界面。

重启防火墙服务

service iptables restart

CentOS 7 系统

firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload

八、访问PostgreSQL

su - postgres

输出结果如下:

上一次登录:一 5月 18 15:17:29 CST 2015pts/0 上
-bash-4.2$

输入命令psql将看到PostgrSQL的版本信息。

psql (9.4.1)
输入 "help" 来获取帮助信息.

九、设置postgres用户密码

postgres=# \password postgres

以上操作基本完成整个PostgreSQL的安装。

十、修改配置文件,令服务器可通过远程访问

对于未执行该步骤的配置将无法通过pgadmin远程管理。运行一下脚本修改pg的配置

echo "allow remote connections"
cat >> /var/lib/pgsql/9.4/data/pg_hba.conf <<EOF
host all all 0.0.0.0/0 md5
EOF
echo "listen all"
cat >> /var/lib/pgsql/9.4/data/postgresql.conf <<EOF
listen_addresses = '*'
EOF
sed 's/ssl = true/#ssl = true/' -i /var/lib/pgsql/9.4/data/postgresql.conf

  

Linux CentOS安装postgresql 9.4的更多相关文章

  1. Linux下安装PostgreSQL 转载linux社区

    Linux下安装PostgreSQL [日期:2016-12-25] 来源:Linux社区  作者:xiaojian [字体:大 中 小]   在Linux下安装PostgreSQL有二进制格式安装和 ...

  2. 阿里云服务器Linux CentOS安装配置(零)目录

    阿里云服务器Linux CentOS安装配置(零)目录 阿里云服务器Linux CentOS安装配置(一)购买阿里云服务器 阿里云服务器Linux CentOS安装配置(二)yum安装svn 阿里云服 ...

  3. 阿里云服务器Linux CentOS安装配置(九)shell编译、打包、部署

    阿里云服务器Linux CentOS安装配置(九)shell编译.打包.部署 1.查询当前目录以及子目录下所有的java文件,并显示查询结果 find . -name *.java -type f - ...

  4. 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定

    阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...

  5. 阿里云服务器Linux CentOS安装配置(七)域名解析

    阿里云服务器Linux CentOS安装配置(七)域名解析 1.购买域名 登录阿里云,左侧菜单点击[域名],然后[域名注册],完成域名购买.(一般首年45元) 2.添加域名解析 在域名列表里点击你的域 ...

  6. 阿里云服务器Linux CentOS安装配置(六)resin多端口配置、安装、部署

    阿里云服务器Linux CentOS安装配置(六)resin多端口配置.安装.部署 1.下载resin包 http://125.39.66.162/files/2183000003E08525/cau ...

  7. 阿里云服务器Linux CentOS安装配置(五)jetty配置、部署

    阿里云服务器Linux CentOS安装配置(五)jetty配置.部署 1.官网下载jetty:wget http://repo1.maven.org/maven2/org/eclipse/jetty ...

  8. 阿里云服务器Linux CentOS安装配置(四)yum安装tomcat

    阿里云服务器Linux CentOS安装配置(四)yum安装tomcat 1.yum -y install tomcat  执行命令后,会帮你把jdk也安装好 2.tomcat安装目录:/var/li ...

  9. 阿里云服务器Linux CentOS安装配置(三)yum安装mysql

    阿里云服务器Linux CentOS安装配置(三)yum安装mysql 1.执行yum安装mysql命令:yum -y install mysql-server mysql-devel 2.启动mys ...

随机推荐

  1. mysql 的max_connections和max_user_connections 的区别

    ----查看max_user_connections 默认值 MySQL> show variables like 'max_user_connections'; +-------------- ...

  2. Python requests 为pfsense 添加Routes

    # !/usr/bin/python 2 # -*- coding: utf-8 -*- __author__ = "Evilxr" import requests ips = o ...

  3. 使用RXTX获取电脑串口

    RXTX是javacomm串口通信的一个扩展 RXTX开发所需文件的下载地址:http://rxtx.qbang.org/wiki/index.php/Download 解压之后可以看到支持各个平台的 ...

  4. Ext.Net 学习随笔 003 Panel基本使用

    Panel() 1.使用Content和Html属性设置Panel内容 前台View代码 @(X.Panel() .ID("panel1") .Width() .Height() ...

  5. 依赖注入 – ASP.NET MVC 4 系列

           从 ASP.NET MVC 3.0 开始就引入了一个新概念:依赖解析器(dependence resolver).极大的增强了应用程序参与依赖注入的能力,更好的在 MVC 使用的服务和创 ...

  6. C#子类调用基类构造备忘

    using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace First ...

  7. Visibility属性控制元素的显示和隐藏

    w3cschool案例: <!DOCTYPE html> <html> <body> <p id="p1">这是一段文本.</ ...

  8. OpenRefine 数据清洗工具

    OpenRefine(官方网站:http://openrefine.org/).它能自动对数据内容进行修正与整理.OpenRefine可以实现数据排序.自动查找重复条目并完成数据记录.OpenRefi ...

  9. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十二) 代码重构使用反射工厂解耦(一)缓存切换

    前言 上一篇中,我们用了反射工厂来解除BLL和UI层耦合的问题.当然那是最简单的解决方法,再复杂一点的程序可能思路相同,但是在编程细节中需要考虑的就更多了,比如今天我在重构过程中遇到的问题.也是接下来 ...

  10. JS Date当前时间:获取日期时间方法在各浏览器中的差异

    转自:http://www.feiesoft.com/00047/<script type="text/javascript"> // JS Date当前时间获取方法在 ...