Linux在不能使用yum的環境下安裝pgsql(公司內網)

前言

本次的情況先說明一下:
任務就是在公司的內網服務器中搭建一個pgsql的數據庫

無yum下載,只能使用rpm文件搞定相關軟件安裝

在這裏插入圖片描述


一、安裝環境

liunx系統: Centos7
pgsql數據庫:postgresql-10.2
服務器視圖化工具:finalshell
數據庫視圖化工具:Navicat 12

本次pgsql的文件存放位置: /home/pgsql

在這裏插入圖片描述


二、開始安裝pgsql (按照操作流程來的)

(1)解壓壓縮包
[root@localhost pgsql]# tar -zxvf postgresql-10.2.tar.gz

(2)進入壓縮後文件
[root@localhost pgsql]# cd postgresql-10.2
[root@localhost pgsql]# ls
aclocal.m4 configure contrib doc HISTORY Makefile src
config configure.in COPYRIGHT GNUmakefile.in INSTALL README

(3)編譯postgresql源碼
[root@localhost postgresql-10.2]# ./configure --prefix=/home/pgsql/postgresql

出現問題請一定要看後面問題解決方案!!!

在這裏插入圖片描述
[root@localhost postgresql-10.2]# make
[root@localhost postgresql-10.2]# make install
至此,已完成postgreql的安裝。進入/home/pgsql/postgresql目錄可以看到安裝後的postgresql的文件。
[root@localhost postgresql]# ls
bin include lib share

(4)創建一個用戶
創建pgsql用戶並設置密碼:
[root@localhost postgresql]# groupadd postgres
[root@localhost postgresql]# useradd postgres
[root@localhost postgresql]# passwd postgres
[root@localhost postgresql]# id postgres
uid=501(postgres) gid=501(postgres) 組=501(postgres)

兩次輸入密碼並確認

(5)創建pgsql的數據庫存儲data主目錄,並修改文件所有者

[root@localhost postgresql-10.2]# cd /home/pgsql/postgresql
[root@localhost postgresql]# mkdir data
[root@localhost postgresql]# chown postgres:postgres data
[root@localhost postgresql]# ls -al
total 20
drwxr-xr-x. 7 root root 68 Mar 30 14:38 .
drwxr-xr-x. 4 root root 77 Mar 30 15:52 …
drwxr-xr-x. 2 root root 4096 Mar 30 14:35 bin
drwx------. 19 postgres postgres 4096 Mar 30 15:34 data
drwxr-xr-x. 6 root root 4096 Mar 30 14:35 include
drwxr-xr-x. 4 root root 4096 Mar 30 14:35 lib
drwxr-xr-x. 6 root root 4096 Mar 30 14:35 share

(6)添加環境變量
[root@localhost postgresql]# vi /etc/profile

添加內容爲:

export PGHOME=/home/pgsql/postgresql/
export PGDATA=/home/pgsql/postgresql/data
export PATH=$PGHOME/bin:$PATH:$HOME/bin

刷新一下
[root@localhost postgresql]# source /etc/profile

在這裏插入圖片描述
(7)換postgres賬號並使用initdb初始化數據庫
[root@localhost /]# su postgres
bash-4.2$ cd /home/pgsql/postgresql
bash-4.2$ initdb
The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.
The database cluster will be initialized with locale “en_US.UTF-8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.
Data page checksums are disabled.
fixing permissions on existing directory /home/pgsql/postgresql/data … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting dynamic shared memory implementation … posix
creating configuration files … ok
running bootstrap script … ok
performing post-bootstrap initialization … ok
syncing data to disk … ok
WARNING: enabling “trust” authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
–auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /home/pgsql/postgresql/data -l logfile start

可以看到 /home/pgsql/postgresql/data已經有文件了。
bash-4.2$ cd /home/pgsql/postgresql/data
bash-4.2$ ls
base pg_commit_ts pg_hba.conf pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase pg_wal postgresql.auto.conf
global pg_dynshmem pg_ident.conf pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc PG_VERSION pg_xact postgresql.conf

(8)配置pgsql的服務
修改/pgsql/postgresql/data目錄下的兩個文件。

postgresql.conf : 配置PostgreSQL數據庫服務器的相應的參數。

pg_hba.conf : 配置對數據庫的訪問權限。

bash-4.2$ vi postgresql.conf

listen_addresses = '*'                 # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                            # (change requires restart)

其中,參數“listen_addresses”表示監聽的IP地址,默認是在localhost處監聽,也就是127.0.0.1的ip地址上監聽,只接受來自本機localhost的連接請求,這會讓遠程的主機無法登陸這臺數據庫,如果想從其他的機器上登陸這臺數據庫,需要把監聽地址改爲實際網絡的地址,一種簡單的方法是,將行開頭的#去掉,把這個地址改爲*,表示在本地的所有地址上監聽。

bash-4.2$ vi pg_hba.conf
找到最下面這一行 ,這樣局域網的人才能訪問。紅色爲新添加內容。

IPv4 local connections:

host all all 0.0.0.0/0 trust
host all all 127.0.0.1/32 trust

(9)設置開機自啓動
bash-4.2$ cd /home/pgsql/postgresql-10.2/contrib/start-scripts
bash-4.2$ ls
freebsd linux macos osx

1)切換爲root用戶,修改linux文件屬性,添加X屬性
bash-4.2$ su root
Password:
[root@localhost start-scripts]# chmod a+x linux

2)複製linux文件到/etc/init.d目錄下,更名爲postgresql
[root@localhost start-scripts]# cp linux /etc/init.d/postgresql

3)修改/etc/init.d/postgresql文件的兩個變量
[root@localhost start-scripts]# vi /etc/init.d/postgresql

prefix設置爲postgresql的安裝路徑:/pgsql/postgresql

PGDATA設置爲postgresql的數據目錄路徑:/pgsql/postgresql/data

4)設置postgresql服務開機自啓動
[root@localhost start-scripts]# chkconfig --add /etc/init.d/postgresql
查看開機自啓動服務設置成功。
[root@localhost start-scripts]# chkconfig
postgresql 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉

5)打開5432的防火牆

//開放5432端口
firewall-cmd --zone=public --add-port=5432/tcp --permanent
//跟新防火牆規則
firewall-cmd --reload
//防火牆列表
firewall-cmd --zone=public --list-ports
//防火牆狀態
systemctl status firewalld
//啓動防火牆
systemctl start firewalld
//關閉防火牆
systemctl stop firewalld.service
systemctl disable firewalld.service

(10)開啓服務 service postgresql start
[root@localhost sysconfig]# cd /etc/init.d
[root@localhost init.d]# service postgresql start
Starting PostgreSQL: su: warning: cannot change directory to /home/postgres: No such file or directory ok

查看postgresql的狀態
[root@localhost init.d]# ps -ef | grep postgres

在這裏插入圖片描述


三、問題解決方案

1、兩個問題

①第一個問題 : configure:error:readline library not found (readline的軟件問題)

解決方法1:下載一個合適的版本!(記住一定要是合適的版本!)
readline-devel下載地址
不知道什麼才叫合適的點這裏
在這裏插入圖片描述
解決方法2:加上–without-readline(不用readline功能)

./configure --prefix=/home/pgsql/postgresql --without-readline

②第二個問題 : configure: error: zlib library not found (zlib的軟件問題)

解決方案: 下載一個合適的版本!(記住一定要是合適的版本!)
zlib-devel下載地址
不知道什麼才叫合適的點這裏

在這裏插入圖片描述


2、npm的安裝過程

(1)下載一個npm文件
(2)運行一個npm文件:rpm -ivh rpm文件名 (有可能版本和系統不一致而導致用不了的)
–force (強行覆蓋)
–nodeps (忽略依賴關係)
列如:rpm -ivh zlib-devel-1.2.7-18.el7.x86_64.rpm --force --nodeps

這篇博客寫的比較詳細了

後言

本次搞這個是最累人的一次了:我先講一下比較有用的參考:
內容很詳細了,不過是2018年的多少有些變動了,【主要參考】
這個也可以的,我也就是參照一部分的內容,【次要參考】
rpm寫的很詳細,只不過我要用的就前面一點點

因爲之前沒有搞過這種情況的服務器,什麼都要先下下來然後再上傳到服務器上。經過這一次我也漲見識了許多。
①瞭解了yum源可以換成163的源
②rpm文件原來還可以這麼玩
③pgsql等一些配置服務的配置

我是按照流程一步一步來的,如果有什麼紕漏大家也可以看我推薦的參考。
也歡迎大家在評論區討論(~ ̄▽ ̄)~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章