CentOS7安裝PostgreSQL9.4
這次選擇的數據庫安裝的是run 文件,更容易掌握.這次數據庫全是默認安裝,如果有需求的可以自行修改一下的.
這是我的第一篇博客,各位觀眾老爺,如果覺得哪裏有什麽不好的,可以留言一起探討,探討.有什麽問題的也可以一起學習學習.
一,打開centos7的ssh
因為我的CentOS7 是新安裝的,所以需要愛打開ssh,如果你的已經在使用了,這個就忽略吧.
1.1 設置靜態ip
1.1.1 進入/etc/sysconfig/network-scripts/ 目錄找到需要修改的網絡的配置文件,並修改.
例如:vim /etc/sysconfig/network-scripts/ifcfg-eth0
1.1.2 修改如下內容
- BOOTPROTO="static" #dhcp改為static
- ONBOOT="yes" #開機啟用本配置
- IPADDR=192.168.200.106 #靜態IP
- GATEWAY=192.168.200.1 #默認網關
- NETMASK=255.255.255.0 #子網掩碼
- DNS1=192.168.99.99 #DNS 配置
1.1.3 最終效果
- # ]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
- HWADDR="00:15:5D:07:F1:02"
- TYPE="Ethernet"
- BOOTPROTO="static" #dhcp改為static
- DEFROUTE="yes"
- PEERDNS="yes"
- PEERROUTES="yes"
- IPV4_FAILURE_FATAL="no"
- IPV6INIT="yes"
- IPV6_AUTOCONF="yes"
- IPV6_DEFROUTE="yes"
- IPV6_PEERDNS="yes"
- IPV6_PEERROUTES="yes"
- IPV6_FAILURE_FATAL="no"
- NAME="eth0"
- UUID="aa7e302d-dc46-54u8-881e-d46cafd0nm98"
- ONBOOT="yes" #開機啟用本配置
- IPADDR=192.168.7.106 #靜態IP
- GATEWAY=192.168.7.1 #默認網關
- NETMASK=255.255.255.0 #子網掩碼
- DNS1=192.168.7.1 #DNS 配置
1.1.4 重啟服務
- # 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復制配置文件
- [[email protected] opt]# su - postgres
- -bash-4.6$ pwd
- /opt/PostgreSQL/9.4
- -bash-4.6$ su -
- Password:
- [[email protected] ~]# cp .bash_profile /opt/PostgreSQL/9.4
- [[email protected] ~]# cp .bashrc /opt/PostgreSQL/9.4
- [[email protected] ~]# su - postgres
2.2.2更改文件權限
- [[email protected] PostgreSQL]# pwd
- /opt/PostgreSQL
- [[email protected] PostgreSQL]# chown -R postgres:postgres /opt/PostgreSQL/
- [[email protected] PostgreSQL]# ll
- total 4
- drwxr-xr-x 12 postgres postgres 4096 4月 14 18:52 9.0
4
2.2.3 然後設置postgres用戶的環境變量
- export PGHOME=/opt/PostgreSQL/9.4
- export PATH=$PGHOME/bin:$PATH
- export PGDATA=$PGHOME/data
- export LD_LIBRARY_PATH=$PGHOME/lib
2.2.4 然後我們可以啟動服務,其實默認服務以及啟動了
- [[email protected] ~]# service postgresql-9.4 start
2.2.5 檢查端口和服務狀態
- [[email protected] ~]# chkconfig --list postgresql-9.4
- postgresql-9.4 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- [[email protected] ~]# netstat -ano | grep 5432
- tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN off (0.00/0/0)
- tcp 0 0 :::5432 :::* LISTEN off (0.00/0/0)
- 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 server:Connection 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