postgresql10.5安装
1.下載源碼安裝包
| wget https://ftp.postgresql.org/pub/source/v10.5/postgresql-10.5.tar.gz |
2.創建pg的用戶主、組
| [root@test2019030517 postgresql-10.5]# useradd postgres [root@test2019030517 postgresql-10.5]# groupadd postgres [root@test2019030517 postgresql-10.5]# passwd postgres |
3.解壓、進入目錄
| [root@test2019030517 postgresql-10.5]# tar zxvf postgresql-10.5.tar.gz [root@test2019030517 postgresql-10.5]# cd postgresql-10.5 |
4.創建postgreSQL的安裝目錄
| [root@test2019030517 postgresql-10.5]# mkdir /ecapp/postgresql |
5.下載依賴包
| [root@test2019030517 postgresql-10.5]# yum -y install -y readline-devel [root@test2019030517 postgresql-10.5]#yum install -y systemtap-sdt-devel.x86_64 yum install perl-ExtUtils-Embed -y yum install zlib zlib-devel?-y yum install openssl openssl-devel?-y yum install pam pam-devel?-y yum install libxml2 libxml2-devel?-y yum install libxslt libxslt-devel?-y yum install tcl tcl-devel |
6.預編譯#-prefix是指定postgreSQL安裝路徑
| [root@test2019030517 postgresql-10.5]# ./configure --prefix=/ecapp/postgresql?\ --with-perl --with-tcl --with-python --with-openssl \ |
7.編譯安裝
| [root@test2019030517 postgresql-10.5]# make [root@test2019030517 postgresql-10.5]# make install |
顯示這個說明成功
| ?PostgreSQl installation complete |
8.安裝contrib目錄下的一些工具,是第三方組織的一些工具代碼,建議安裝
| [root@test2019030517 postgresql-10.5]# cd contrib [root@test2019030517 contrib]# make && make install |
9.創建相關目錄
| ?數據目錄 [root@test2019030517 contrib]# mkdir -p /ecapp/postgresql/data ?日志目錄 [root@test2019030517 contrib]# mkdir -p /ecapp/postgresql/logs |
賦予postgres用戶相關文件夾權限
| chown -R postgres:postgres /ecapp/postgresql |
10.配置環境變量
| [root@test2019030517 postgresql-10.5]# cat /etc/profile.d/pgsql.sh export PATH=$PATH:/ecapp/postgresql/bin/ [root@test2019030517 postgresql-10.5]# source /etc/profile.d/pgsql.sh |
11.啟動數據庫
| [root@test2019030517 postgresql-10.5]# su postgres 初始化數據庫 [postgres@test2019030517 postgresql-10.5]$ initdb -D /ecapp/postgresql/data/ 啟動服務 pg_ctl -D /ecapp/postgresql/data -l /ecapp/postgresql/logs/logfile start 連接數據庫 [postgres@test2019030517 postgresql-10.5]$ psql 創建數據庫 postgres=# create database test; 創建表 postgres=# create table t_user (id integer, name text); 插入測試數據 postgres=# insert into t_user values (1,'joke'); 查詢數據 postgres=# select * from t_user; 退出psql窗口 postgres-# \q |
12.修改監聽所有網絡以及數據庫連接數以及port
| $ vim /usr/local/postgresql/data/postgresql.conf ?60 listen_addresses = '*' ?????????# what IP address(es) to listen on; ?65 max_connections = 100 ??????????????????# (change requires restart) 普通用戶 |
13.修改遠程訪問
| $ vim /usr/local/postgresql/data/pg_hba.conf #在文件的最下方加上下面的這句話 host ???all ????????all ????????0.0.0.0/0 ????????????trust |
如下
| $ tail -n 6 /usr/local/postgresql/data/pg_hba.conf # replication privilege. local ??replication ?????all? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?trust host ???replication ????all ????????????127.0.0.1/32? ? ? ? ? trust host ???replication ????all ????????????::1/128 ????????????????trust host ???all? ? ? ? ? ? ? ? all? ? ? ? ? ? ? 0.0.0.0/0? ? ? ? ? ? ? trust 第一列是連接方式,local是通過本地的socket套接字連接,host是通過ip地址連接。 第二列是目標數據庫 第三列是用戶 第四列是授權ip 第五列是認證方式 認證方式共有11種,最常接觸的是peer,ident和password peer:是指postgresql所在操作系統上的用戶登錄。peer方式簡單來說就是當前系統用戶和登錄到postgresql的用戶名相同,就可以登錄。 Ident:與peer類似,只不過peer只能在postgresql本地進行登錄,ident則是可以跨主機使用。 Password:使用用戶(角色)和密碼登陸,這里說的角色就是mysql的用戶。 |
| ? |
14.防火墻開啟端口
| # 切換root用戶 su - root # 防火墻 允許5432 端口<br>iptables -I INPUT -p tcp --dport 5432 -j ACCEPT |
15.重啟postgreSQL服務
| [root@test2019030517 postgresql-10.5]# su - postgres $?pg_ctl -D /ecapp/postgresql/data/ -l /ecapp/postgresql/logs/logfile restart |
停止服務命令
| $ pg_ctl -D /usr/local//postgresql/data/ -l /usr/local/postgresql/logs/logfile stop |
16.設置開機自啟動
| 切換到root用戶 [postgres@test2019030517 ~]$ su root 找到解壓后源碼包里面的一個linux文件 # chmod a+x /data/postgresql-10.5/contrib/start-scripts/linux 復制linux文件到/etc/init.d目錄下,更名為postgresql # cp /data/postgresql-10.5/contrib/start-scripts/linux /etc/init.d/postgresql |
17.修改/etc/init.d/postgresql文件的兩個變量
| 31 # Installation prefix<br>32 prefix=/usr/local/postgresql 33 34 # Data directory 35 PGDATA="/usr/local/postgresql/data" 37 # Who to run the postmaster as, usually "postgres". ?(NOT "root") 38 PGUSER=postgres ? |
18.執行service postgresql start,可以啟動PostgreSQL服務
| 啟動 [root@database2019030517 postgresql]# service postgresql start 停止 [root@database2019030517 postgresql]# service postgresql stop 查看狀態 [root@database2019030517 postgresql]# service postgresql status |
19.設置postgresql服務開機自啟動
| [root@test2019030517 postgres]# chkconfig --add postgresql [root@test2019030517 postgres]# chkconfig --level 2345 postgresql on [root@test2019030517 postgres]# chkconfig --list |
20.postgresql在原有參數的基礎上進行在編譯
| pg_config --configure?#查看參數 在原有參數基礎上加上新的參數進行預編譯./configure 在make && make install 做之前在測試環境上運行一遍試一下,編譯完重啟一下就好了 |
轉載于:https://www.cnblogs.com/charon2/p/11314872.html
總結
以上是生活随笔為你收集整理的postgresql10.5安装的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql权限问题
- 下一篇: postgresql语句