CentOS6.5 64位下源码安装PostgreSQL9.5.1

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:

2000元阿里云代金券免费领取,2核4G云服务器仅664元/3年,新老用户都有优惠,立即抢购>>>


阿里云采购季(云主机223元/3年)活动入口:请点击进入>>>,


阿里云学生服务器(9.5元/月)购买入口:请点击进入>>>,

1、官方下载源码文件

http://www.postgresql.org/ftp/source/v9.5.1/

2、添加用户

[root@test1 ~]#  useradd postgres

[root@test1 ~]#  passwd postgres

Changing password for user postgres.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

[root@test1 ~]#

3、解压并安装

[root@test1 ~]# tar -jxvf postgresql-9.5.1.tar.bz2

[root@test1 ~]# cd postgresql-9.5.1

[root@test1 postgresql-9.5.1]# ./configure --prefix=/usr/local/pgsql

[root@test1 postgresql-9.5.1]# make

[root@test1 postgresql-9.5.1]# make  install

[root@test1 postgresql-9.5.1]# mkdir /usr/local/pgsql/data

[root@test1 postgresql-9.5.1]# mkdir /usr/local/pgsql/log

[root@test1 postgresql-9.5.1]# chown postgres /usr/local/pgsql/data

4、环境变量设置

[root@test1 pgsql]# su - postgres

[postgres@test1 ~]$ vim .bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin

PGDATA=/usr/local/pgsql/data

export PATH PGDATA

[postgres@test1 ~]$ source .bash_profile

5、添加postgresql系统服务

[root@test1 ~]#  vim /etc/init.d/postgresql

#!/bin/sh
#
# postgresql    This is the init script for starting up the PostgreSQL
#               server.
#
# chkconfig: - 64 36
# description: PostgreSQL database server.
# processname: postmaster
# pidfile: /var/run/postmaster.PORT.pid

# This script is slightly unusual in that the name of the daemon (postmaster)
# is not the same as the name of the subsystem (postgresql)

# PGVERSION is the full package version, e.g., 8.4.0
# Note: the specfile inserts the correct value during package build
PGVERSION=9.5.1
# PGMAJORVERSION is major version, e.g., 8.4 (this should match PG_VERSION)
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`

# Source function library.
. /etc/rc.d/init.d/functions

# Get network config.
. /etc/sysconfig/network

# Find the name of the script
NAME=`basename $0`
if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
then
        NAME=${NAME:3}
fi

# For SELinux we need to use 'runuser' not 'su'
if [ -x /sbin/runuser ]
then
    SU=runuser
else
    SU=su
fi


# Set defaults for configuration variables
PGENGINE=/usr/local/pgsql/bin
PGPORT=5432
PGDATA=/usr/local/pgsql/data
PGLOG=/usr/local/pgsql/log/pgstartup.log
# Value to set as postmaster process's oom_adj
PG_OOM_ADJ=-17

# Override defaults from /etc/sysconfig/pgsql if file is present
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}

export PGDATA
export PGPORT

lockfile="/var/lock/subsys/${NAME}"
pidfile="/var/run/postmaster.${PGPORT}.pid"

script_result=0

start(){
        [ -x "$PGENGINE/postmaster" ] || exit 5

        PSQL_START=$"Starting ${NAME} service: "

        # Make sure startup-time log file is valid
        if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
        then
                touch "$PGLOG" || exit 4
                chown postgres:postgres "$PGLOG"
                chmod go-rwx "$PGLOG"
                [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG"
        fi

        # Check for the PGDATA structure
        if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
        then
                # Check version of existing PGDATA
                if [ x`cat "$PGDATA/PG_VERSION"` != x"$PGMAJORVERSION" ]
                then
                        SYSDOCDIR="(Your System's documentation directory)"
                        if [ -d "/usr/doc/postgresql-$PGVERSION" ]
                        then
                                SYSDOCDIR=/usr/doc
                        fi
                        if [ -d "/usr/share/doc/postgresql-$PGVERSION" ]
                        then
                                SYSDOCDIR=/usr/share/doc
                        fi
                        if [ -d "/usr/doc/packages/postgresql-$PGVERSION" ]
                        then
                                SYSDOCDIR=/usr/doc/packages
                        fi
                        if [ -d "/usr/share/doc/packages/postgresql-$PGVERSION" ]
                        then
                                SYSDOCDIR=/usr/share/doc/packages
                        fi
                        echo
                        echo $"An old version of the database format was found."
                        echo $"You need to upgrade the data format before using PostgreSQL."
                        echo $"See $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information."
                        exit 1
                fi
        else
                # No existing PGDATA! Warn the user to initdb it.
                echo
                echo "$PGDATA is missing. Use \"service postgresql initdb\" to initialize the cluster first."
                echo_failure
                echo
                exit 1
        fi

        echo -n "$PSQL_START"
        test x"$PG_OOM_ADJ" != x && echo "$PG_OOM_ADJ" > /proc/self/oom_adj
        $SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null
        sleep 2
        pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null`
        if [ "x$pid" != x ]
        then
                success "$PSQL_START"
                touch "$lockfile"
                echo $pid > "$pidfile"
                echo
        else
                failure "$PSQL_START"
                echo
                script_result=1
        fi
}

stop(){
        echo -n $"Stopping ${NAME} service: "
        if [ -e "$lockfile" ]
        then
            $SU -l postgres -c "$PGENGINE/pg_ctl stop -D '$PGDATA' -s -m fast" > /dev/null 2>&1 < /dev/null
            ret=$?if [ $ret -eq 0 ]
            then
                echo_success
                rm -f "$pidfile"
                rm -f "$lockfile"
            else
                echo_failure
                script_result=1fi
        else
            # not running; per LSB standards this is "ok"
            echo_success
        fi
        echo
}

restart(){
    stop
    start
}

condrestart(){
    [ -e "$lockfile" ] && restart || :
}

reload(){
    $SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null
}

initdb(){
    if [ -f "$PGDATA/PG_VERSION" ]
    then
        echo -n "Data directory is not empty!"
        echo_failure
        echo
        script_result=1else
        echo -n $"Initializing database: "
        if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ]
        then
                mkdir -p "$PGDATA" || exit 1
                chown postgres:postgres "$PGDATA"
                chmod go-rwx "$PGDATA"
        fi
        # Clean up SELinux tagging for PGDATA
        [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA"

        # Make sure the startup-time log file is OK, too
        if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
        then
                touch "$PGLOG" || exit 1
                chown postgres:postgres "$PGLOG"
                chmod go-rwx "$PGLOG"
                [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG"
        fi

        # Initialize the database
        $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null

        # Create directory for postmaster log
        mkdir "$PGDATA/pg_log"
        chown postgres:postgres "$PGDATA/pg_log"
        chmod go-rwx "$PGDATA/pg_log"

        if [ -f "$PGDATA/PG_VERSION" ]
        then
            echo_success
        else
            echo_failure
            script_result=1fi
        echo
    fi
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p "$pidfile" postmaster
        script_result=$?;;
  restart)
        restart
        ;;
  condrestart|try-restart)
        condrestart
        ;;
  reload)
        reload
        ;;
  force-reload)
        restart
        ;;
  initdb)
        initdb
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|initdb}"
        exit 2
esac

exit $script_result

chkconfig --add postgresql

chkconfig postgresql  on




本文转自 ygqygq2 51CTO博客,原文链接:http://blog.51cto.com/ygqygq2/1750503,如需转载请自行联系原作者

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
5天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
19 0
|
7月前
|
监控 PHP Apache
centos7.源码安装zabbix4.4
centos7.源码安装zabbix4.4
|
8月前
|
Linux Shell 开发工具
centos7源码包安装git傻瓜式安装步骤
centos7源码包安装git傻瓜式安装步骤
239 0
|
7月前
|
关系型数据库 Linux PostgreSQL
Linux centos8 docker中安装postgresql12.4及远程访问设置
Linux centos8 docker中安装postgresql12.4及远程访问设置
396 0
|
5天前
|
Linux 数据安全/隐私保护 Docker
源码管理新征程:CentOS 7上GitLab安装全程解析
源码管理新征程:CentOS 7上GitLab安装全程解析
37 0
源码管理新征程:CentOS 7上GitLab安装全程解析
|
5天前
|
Linux Apache
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
23 0
|
5天前
|
监控 关系型数据库 MySQL
centos7 zabbix-service 源码编译 安装部署服务端 和 常见安装错误
centos7 zabbix-service 源码编译 安装部署服务端 和 常见安装错误
22 0
|
5天前
|
关系型数据库 Linux Shell
Centos系统上安装PostgreSQL和常用PostgreSQL功能
Centos系统上安装PostgreSQL和常用PostgreSQL功能
|
5天前
|
关系型数据库 MySQL Linux
Centos安装MySQL数据库(注意:源码安装)
Centos安装MySQL数据库(注意:源码安装)
151 0
|
5天前
|
存储 缓存 NoSQL
CentOS7 下源码安装Redis并配置服务开机启动
CentOS7 下源码安装Redis并配置服务开机启动
157 1
http://www.vxiaotou.com