1 Linux环境信息
--- 查看linux版本
cat /etc/redhat-release
--- 查看内核版本
uname -r
--- 查看操作系统位数
uname -m
2 安装依赖包
PostgreSQL的依赖包需提前安装
rpm -qa | grep ncurses libaio
yum install ncurses-devel libaio-devel -y
yum install readline readline-devel openssl openssl-devel zlib zlib-devel -y
yum install gcc bison tcl perl flex
3 创建PostgreSQL账号
useradd psql
id psql
4 获取PostgreSQL软件包
PostgreSQL源码包:https://www.postgresql.org/ftp/source/v9.5.18/
PostgreSQL源码包:postgresql-9.5.18.tar.gz
5 编译&安装PostgreSQL
配置、编译安装步骤如下:
1. 下载PostgreSQL软件包
mkdir -p /opt/media
cd /opt/media
wget -q https://www.postgresql.org/ftp/source/v9.5.18/postgresql-9.5.18.tar.gz
ls -rtlh
2. 解压、配置PostgreSQL
tar -zxvf postgresql-9.5.18.tar.gz -C /opt/media
cd /opt/media/postgresql-9.5.18
./configure --prefix=/app/psql
cmake . -DCMAKE_INSTALL_PREFIX=/app/psql9.5 \
-DMYSQL_DATADIR=/app/psql9.5/data \
-DMYSQL_UNIX_ADDR=/app/psql9.5/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_BOOST=/usr/local/boost \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
3. 编译、安装mysql
--- 编译,启用4核并行编译
make -j 4
make install
4. 配置安装目录的软连接
ln -s /app/pysql9.5 /app/psql
ls -lrth /app
ls /app/pysql
完成上述步骤,psql软件安装完成
6 初始化数据库
-- 创建数据目录
mkdir -p /app/psql/data
-- 初始化数据库
initdb -D /app/psql/data
7 配置访问控制
-- 配置访问控制文件
vi /app/psql/pg_hba.conf
修改前
# IPv4 local connections:
host all all 127.0.0.1/32 trust
修改后
# IPv4 local connections:
host all all 10.6.0.*/24 md5
-- 配置PostgreSQL服务监听端口
vi /app/psql/postgresql.conf
#listen_addresses = '10.6.0.*'
#port = 5432
8 启动PostgreSQL服务
-- 创建PostgreSQL日志目录
mkdir -p /app/psql/log
touch /app/psql/log/server.log
-- 启动PostgreSQL服务
pg_ctl -D /app/psql/data -l /app/psql/log/server.log start
-- 停止PostgreSQL服务
pg_ctl -D /app/psql/data -l /app/psql/log/server.log stop
9 编辑postgresql.conf文件
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
# name = value
#
# (The "=" is optional.) Whitespace may be used. Comments are introduced with
# "#" anywhere on a line. The complete list of parameter names and allowed
# values can be found in the PostgreSQL documentation.
#
# The commented-out settings shown in this file represent the default values.
# Re-commenting a setting is NOT sufficient to revert it to the default value;
# you need to reload the server.
#
# This file is read on server startup and when the server receives a SIGHUP
# signal. If you edit the file on a running system, you have to SIGHUP the
# server for the changes to take effect, or use "pg_ctl reload". Some
# parameters, which are marked below, require a server shutdown and restart to
# take effect.
#
# Any parameter can also be given as a command-line option to the server, e.g.,
# "postgres -c log_connections=on". Some parameters can be changed at run time
# with the "SET" SQL command.
#
# Memory units: kB = kilobytes Time units: ms = milliseconds
# MB = megabytes s = seconds
# GB = gigabytes min = minutes
# TB = terabytes h = hours
# d = days
#------------------------------------------------------------------------------
# FILE LOCATIONS
#------------------------------------------------------