CentOS7安装PostgreSQL9.4

  这次选择的数据库安装的是run 文件,更容易掌握.这次数据库全是默认安装,如果有需求的可以自行修改一下的.

这是我的第一篇博客,各位观众老爷,如果觉得哪里有什么不好的,可以留言一起探讨,探讨.有什么问题的也可以一起学习学习.

,打开centos7ssh

因为我的CentOS7 是新安装的,所以需要爱打开ssh,如果你的已经在使用了,这个就忽略吧.

1.1 设置静态ip

1.1.1 进入/etc/sysconfig/network-scripts/ 目录找到需要修改的网络的配置文件,并修改.

例如:vim /etc/sysconfig/network-scripts/ifcfg-eth0  

1.1.2 修改如下内容

  1. BOOTPROTO="static" #dhcp改为static   
  2. ONBOOT="yes" #开机启用本配置  
  3. IPADDR=192.168.200.106 #静态IP  
  4. GATEWAY=192.168.200.1 #默认网关  
  5. NETMASK=255.255.255.0 #子网掩码  
  6. DNS1=192.168.99.99 #DNS 配置  

1.1.3 最终效果

  1. # ]# cat /etc/sysconfig/network-scripts/ifcfg-eth0  
  2. HWADDR="00:15:5D:07:F1:02"  
  3. TYPE="Ethernet"  
  4. BOOTPROTO="static" #dhcp改为static   
  5. DEFROUTE="yes"  
  6. PEERDNS="yes"  
  7. PEERROUTES="yes"  
  8. IPV4_FAILURE_FATAL="no"  
  9. IPV6INIT="yes"  
  10. IPV6_AUTOCONF="yes"  
  11. IPV6_DEFROUTE="yes"  
  12. IPV6_PEERDNS="yes"  
  13. IPV6_PEERROUTES="yes"  
  14. IPV6_FAILURE_FATAL="no"  
  15. NAME="eth0"  
  16. UUID="aa7e302d-dc46-54u8-881e-d46cafd0nm98"  
  17. ONBOOT="yes" #开机启用本配置  
  18. IPADDR=192.168.7.106 #静态IP  
  19. GATEWAY=192.168.7.1 #默认网关  
  20. NETMASK=255.255.255.0 #子网掩码  
  21. DNS1=192.168.7.1 #DNS 配置  

1.1.4 重启服务

  1. # service network restart  

1.2打开ssh

1.2.1 进入sshd的配置文件

Vi /etc/ssh/sshd_config

打开port 22

PasswordAuthentication设成yes

找到#PermitRootLogin no将其修改为PermitRootLogin yes

 service sshd restart 重启服务

,安装postgresql-9.4 run文件

2.1 安装:root

2.1.1 傻瓜式安装

  [root@rong opt]# chmod 777 postgresql-9.4.12-1-linux.run

[root@rong opt]# ./postgresql-9.4.12-1-linux.run 

直接默认安装到opt/PostgreSQL/

中间只有设置用户postgres 的密码 注意

2.2 把配置文件分配给postgres 用户(可跳过)

2.2.1复制配置文件

  1. [root@rong opt]# su - postgres  
  2. -bash-4.6$ pwd  
  3. /opt/PostgreSQL/9.4
  4. -bash-4.6$ su -  
  5. Password:  
  6. [root@rong ~]# cp .bash_profile /opt/PostgreSQL/9.4
  7. [root@rong ~]# cp .bashrc /opt/PostgreSQL/9.4
  8. [root@rong ~]# su - postgres  

2.2.2更改文件权限

  1. [root@rong PostgreSQL]# pwd  
  2. /opt/PostgreSQL  
  3. [root@rong PostgreSQL]# chown -R postgres:postgres /opt/PostgreSQL/  
  4. [root@rong PostgreSQL]# ll  
  5. total 4  
  6. drwxr-xr-x 12 postgres postgres 4096  4 14 18:52 9.0  

4

2.2.3 然后设置postgres用户的环境变量

  1. export PGHOME=/opt/PostgreSQL/9.4  
  2. export PATH=$PGHOME/bin:$PATH  
  3. export PGDATA=$PGHOME/data  
  4. export LD_LIBRARY_PATH=$PGHOME/lib 

2.2.4 然后我们可以启动服务,其实默认服务以及启动了

  1. [root@rong ~]# service postgresql-9.4 start  

   2.2.5  检查端口和服务状态

  1. [root@rong ~]# chkconfig --list postgresql-9.4  
  2. postgresql-9.4  0:off   1:off   2:on    3:on    4:on    5:on    6:off  
  3. [root@rong ~]# netstat -ano | grep 5432  
  4. tcp        0      0 0.0.0.0:5432                0.0.0.0:*                   LISTEN      off (0.00/0/0)  
  5. tcp        0      0 :::5432                     :::*                        LISTEN      off (0.00/0/0)  
  6. unix  2      [ ACC ]     STREAM     LISTENING     3759370 /tmp/.s.PGSQL.5432  

2.3 root下直接配置(跳过2.2)

这个就不用分配权限,就让在root权限下就行

直接在root 下配置 .bash_profile

export PGHOME=/opt/PostgreSQL/9.4

export PGDATA=$PGHOME/data

PATH=$PATH:$HOME/bin:$PGHOME/bin

启动服务,查看端口都一样

2.4 配置pg_hba.conf

 # IPv4 local connections:

  host all all 127.0.0.1/32 md5
  host all all 0.0.0.0/0 md5

2.5 设置自启动,打开端口

有的时候还是连接不上,有可能是5432关闭了所以需要重新打开

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

systemctl enable postgresql-9.4

systemctl start postgresql-9.4

 开放防火墙端口

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

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

firewall-cmd --reload

附录

一些问题的参考

如何为CentOS 7配置静态IP地址
http://Linux.cn/article-3977-1.html
CentOS 7上给一个网卡分配多个IP地址
https://linux.cn/article-5127-1-rel.html

postgresql 安装(linux)

http://jingyan.baidu.com/article/4f7d5712cf761e1a20192784.html

SSH远程登录失败,提示“Password authentication failed

http://m.blog.csdn.net/article/details?id=6045176

错误::Could not connect to serverConnection refused(0x00002740/10061) 

         Is the server running on host xxx.xxx.xx.xx and accepting 

         TCP/IP connetions on port 5432?

http://m.ithao123.cn/content-5942383.html

Centos7 PostgreSQL安装

http://m.blog.csdn.net/article/details?id=50359549

常见的linux指令

原文地址:https://www.cnblogs.com/aihuxi/p/6977912.html