源碼編譯安裝Postgresql 11.4

1 環境

  • 操做系統: Centos 7.6 (cat /etc/redhat-release)
  • postgresql版本: 11.4(由於12仍是beta版)

2 準備工做

2.1 安裝gcc編輯器

[root@localhost postgresql-11.4]# gcc --version
    gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
    Copyright © 2015 Free Software Foundation, Inc.
    本程序是自由軟件;請參看源代碼的版權聲明。本軟件沒有任何擔保;
    包括沒有適銷性和某一專用目的下的適用性擔保。
gcc用於編譯源碼

2.2 安裝make

[root@localhost postgresql-11.4]# make --version
    GNU Make 3.82
    Built for x86_64-redhat-linux-gnu
    Copyright (C) 2010  Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
make用於批量編譯連接源碼,實際幹活的仍是gcc

2.3 安裝readline

yum install readline
    yum -y install -y readline-devel
readline是個坑啊。能夠選擇不安裝readline,後果是在psql裏執行完命令,想用方向鍵再次獲取該命令時就成了亂碼。因此必需要安裝readline。
只yum install readline時,configure的時候任然會報錯,提示找不到readline。解決方法是安裝readline-devel。

2.4 安裝zlib-devel

yum install zlib  //通常狀況下,系統已經默認安裝了zlib
    yum install zlib-devel
zlib用於數據壓縮

3 下載postgresql源碼

postgresql的官方網站下載:https://www.postgresql.org/

4 編譯安裝

4.1 解壓下載的壓縮包

cd /home/software/
    tar -xzvf postgresql-11.4.tar.gz

4.2 建立postgresql的安裝目錄

mkdir /home/app/postgresql

4.3 生成makefile

./configure --prefix=/home/app/postgresql

4.4 編譯安裝

make && make install
All of PostgreSQL successfully made. Ready to install.
[1]+ 完成 make

4.5 安裝工具集

cd /home/software/postgresql-11.4/contrib
    make && make install

4.6 建立postgres用戶:

groupadd postgres
    useradd -g postgres postgres
爲了安全考慮,postgresql不容許使用root用戶操做數據庫,咱們在系統中爲了使用postgresql添加一個用戶postgres:
也能夠是其餘用戶名,可是習慣上你們都是建立postgres用戶做爲數據庫的超級用戶。
初始化數據庫時,就以這個用戶做爲數據庫的超級用戶

4.7 修改data目錄的用戶爲postgres

chown -R postgres:postgres /home/app/postgresql/data

4.8 修改環境變量

su postgres 
    vim /home/postgres/.bash_profile

      添加環境變量:html

export PGHOME=/home/app/postgresql
    export PGDATA=/home/app/postgresql/data
    export PATH=$PGHOME/bin:$PATH
    export MANPATH=$PGHOME/share/man:$MANPATH
    export LANG=en_US.utf8
    export DATE=`date +"%Y-%m-%d %H:%M:%S"`
    export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
    alias rm='rm  -i'
    alias ll='ls -lh'

      而後使環境變量當即生效,不然initdb命令會找不到:linux

source /home/postgres/.bash_profile

4.9 初始化數據庫

initdb -D /home/app/postgresql/data/
Success. You can now start the database server using:
pg_ctl -D /home/app/postgresql/data/ -l logfile start

4.10 啓動數據庫

su postgres
    cd /home/postgres  //logfile須要在postgres的用戶目錄下建立
    pg_ctl -D /home/app/postgresql/data/ -l logfile start

  查看5432端口是否已經啓動redis

netstat -nltp|grep 5432

4.11 添加postgresql至服務

cd /home/software/postgresql-11.4/contrib/start-scripts
    chmod a+x linux.
    cp linux /etc/init.d/postgresql
此時就可使用 /etc/init.d/postgresql stop 來中止postgresql
也可使用:service postgresql start 來啓動postgresql
修改postgresql腳本中prefix和PGDATA的內容
chkconfig --add postgresql   //設置服務開機啓動

5 配置數據庫容許鏈接

#設置監聽整個網絡,查找「listen_addresses 」字符串,
vim /home/app/postgresql/data/postgresql.conf
#修改成以下:
listen_addresses = '*'

#配置鏈接方式:
 vim /home/app/postgresql/data/pg_hba.conf
#修改成以下:
host    all             all             192.168.2.0/24           md5

結束

相關文章
相關標籤/搜索