1. 程式人生 > >CentOS7安裝PostgreSQL9.4

CentOS7安裝PostgreSQL9.4

password 關閉 mes add-port -1 ane log 0.00 spa

這次選擇的數據庫安裝的是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 傻瓜式安裝

[[email protected] opt]# chmod 777 postgresql-9.4.12-1-linux.run

[[email protected] opt]# ./postgresql-9.4.12-1-linux.run

直接默認安裝到opt/PostgreSQL/

中間只有設置用戶postgres 的密碼 註意

2.2 把配置文件分配給postgres 用戶(可跳過)

2.2.1復制配置文件

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

2.2.2更改文件權限

  1. [[email protected] PostgreSQL]# pwd
  2. /opt/PostgreSQL
  3. [[email protected] PostgreSQL]# chown -R postgres:postgres /opt/PostgreSQL/
  4. [[email protected] 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. [[email protected] ~]# service postgresql-9.4 start

2.2.5 檢查端口和服務狀態

  1. [[email protected] ~]# chkconfig --list postgresql-9.4
  2. postgresql-9.4 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  3. [[email protected] ~]# 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指令

CentOS7安裝PostgreSQL9.4