postgresql10.5安装
1.下載源碼安裝包
| wget https://ftp.postgresql.org/pub/source/v10.5/postgresql-10.5.tar.gz |
2.創(chuàng)建pg的用戶主、組
| [root@test2019030517 postgresql-10.5]# useradd postgres [root@test2019030517 postgresql-10.5]# groupadd postgres [root@test2019030517 postgresql-10.5]# passwd postgres |
3.解壓、進(jìn)入目錄
| [root@test2019030517 postgresql-10.5]# tar zxvf postgresql-10.5.tar.gz [root@test2019030517 postgresql-10.5]# cd postgresql-10.5 |
4.創(chuàng)建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.預(yù)編譯#-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 |
顯示這個(gè)說(shuō)明成功
| ?PostgreSQl installation complete |
8.安裝contrib目錄下的一些工具,是第三方組織的一些工具代碼,建議安裝
| [root@test2019030517 postgresql-10.5]# cd contrib [root@test2019030517 contrib]# make && make install |
9.創(chuàng)建相關(guān)目錄
| ?數(shù)據(jù)目錄 [root@test2019030517 contrib]# mkdir -p /ecapp/postgresql/data ?日志目錄 [root@test2019030517 contrib]# mkdir -p /ecapp/postgresql/logs |
賦予postgres用戶相關(guān)文件夾權(quán)限
| chown -R postgres:postgres /ecapp/postgresql |
10.配置環(huán)境變量
| [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.啟動(dòng)數(shù)據(jù)庫(kù)
| [root@test2019030517 postgresql-10.5]# su postgres 初始化數(shù)據(jù)庫(kù) [postgres@test2019030517 postgresql-10.5]$ initdb -D /ecapp/postgresql/data/ 啟動(dòng)服務(wù) pg_ctl -D /ecapp/postgresql/data -l /ecapp/postgresql/logs/logfile start 連接數(shù)據(jù)庫(kù) [postgres@test2019030517 postgresql-10.5]$ psql 創(chuàng)建數(shù)據(jù)庫(kù) postgres=# create database test; 創(chuàng)建表 postgres=# create table t_user (id integer, name text); 插入測(cè)試數(shù)據(jù) postgres=# insert into t_user values (1,'joke'); 查詢數(shù)據(jù) postgres=# select * from t_user; 退出psql窗口 postgres-# \q |
12.修改監(jiān)聽(tīng)所有網(wǎng)絡(luò)以及數(shù)據(jù)庫(kù)連接數(shù)以及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.修改遠(yuǎn)程訪問(wèn)
| $ 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是通過(guò)本地的socket套接字連接,host是通過(guò)ip地址連接。 第二列是目標(biāo)數(shù)據(jù)庫(kù) 第三列是用戶 第四列是授權(quán)ip 第五列是認(rèn)證方式 認(rèn)證方式共有11種,最常接觸的是peer,ident和password peer:是指postgresql所在操作系統(tǒng)上的用戶登錄。peer方式簡(jiǎn)單來(lái)說(shuō)就是當(dāng)前系統(tǒng)用戶和登錄到postgresql的用戶名相同,就可以登錄。 Ident:與peer類似,只不過(guò)peer只能在postgresql本地進(jìn)行登錄,ident則是可以跨主機(jī)使用。 Password:使用用戶(角色)和密碼登陸,這里說(shuō)的角色就是mysql的用戶。 |
| ? |
14.防火墻開(kāi)啟端口
| # 切換root用戶 su - root # 防火墻 允許5432 端口<br>iptables -I INPUT -p tcp --dport 5432 -j ACCEPT |
15.重啟postgreSQL服務(wù)
| [root@test2019030517 postgresql-10.5]# su - postgres $?pg_ctl -D /ecapp/postgresql/data/ -l /ecapp/postgresql/logs/logfile restart |
停止服務(wù)命令
| $ pg_ctl -D /usr/local//postgresql/data/ -l /usr/local/postgresql/logs/logfile stop |
16.設(shè)置開(kāi)機(jī)自啟動(dòng)
| 切換到root用戶 [postgres@test2019030517 ~]$ su root 找到解壓后源碼包里面的一個(gè)linux文件 # chmod a+x /data/postgresql-10.5/contrib/start-scripts/linux 復(fù)制linux文件到/etc/init.d目錄下,更名為postgresql # cp /data/postgresql-10.5/contrib/start-scripts/linux /etc/init.d/postgresql |
17.修改/etc/init.d/postgresql文件的兩個(gè)變量
| 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.執(zhí)行service postgresql start,可以啟動(dòng)PostgreSQL服務(wù)
| 啟動(dòng) [root@database2019030517 postgresql]# service postgresql start 停止 [root@database2019030517 postgresql]# service postgresql stop 查看狀態(tài) [root@database2019030517 postgresql]# service postgresql status |
19.設(shè)置postgresql服務(wù)開(kāi)機(jī)自啟動(dòng)
| [root@test2019030517 postgres]# chkconfig --add postgresql [root@test2019030517 postgres]# chkconfig --level 2345 postgresql on [root@test2019030517 postgres]# chkconfig --list |
20.postgresql在原有參數(shù)的基礎(chǔ)上進(jìn)行在編譯
| pg_config --configure?#查看參數(shù) 在原有參數(shù)基礎(chǔ)上加上新的參數(shù)進(jìn)行預(yù)編譯./configure 在make && make install 做之前在測(cè)試環(huán)境上運(yùn)行一遍試一下,編譯完重啟一下就好了 |
轉(zhuǎn)載于:https://www.cnblogs.com/charon2/p/11314872.html
總結(jié)
以上是生活随笔為你收集整理的postgresql10.5安装的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql权限问题
- 下一篇: postgresql语句