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

1、官方下载源码文件

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

2、添加用户

[[email protected] ~]#  useradd postgres

[[email protected] ~]#  passwd postgres

Changing password for user postgres.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

[[email protected] ~]#

3、解压并安装

[[email protected] ~]# tar -jxvf postgresql-9.5.1.tar.bz2

[[email protected] ~]# cd postgresql-9.5.1

[[email protected] postgresql-9.5.1]# ./configure --prefix=/usr/local/pgsql

[[email protected] postgresql-9.5.1]# make

[[email protected] postgresql-9.5.1]# make  install

[[email protected] postgresql-9.5.1]# mkdir /usr/local/pgsql/data

[[email protected] postgresql-9.5.1]# mkdir /usr/local/pgsql/log

[[email protected] postgresql-9.5.1]# chown postgres /usr/local/pgsql/data

4、环境变量设置

[[email protected] pgsql]# su - postgres

[[email protected] ~]$ 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

[[email protected] ~]$ source .bash_profile

5、添加postgresql系统服务

[[email protected] ~]#  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=1
            fi
        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=1
    else
        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=1
        fi
        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 postgresql on

时间: 2025-01-07 10:24:36

CentOS6.5 64位下源码安装PostgreSQL9.5.1的相关文章

centos6.5 64位下安装私有npm

搭建自己的私有npm库 1.安装Couchdb [[email protected]_private ~]# yum install wget [[email protected]_private ~]# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm [[email protected]_private ~]# rpm -ivh --test epel-release-6-

centos6.5下源码安装mysql密码修改

Centos下源码安装mysql密码破解方法: 方法一:首先停止mysql服务,: /etc/init.d/mysqldstop 停止mysql ps -ef |grep mysql 查看mysql是否关闭 然后以跳过权限方式后台启动 /usr/local/mysql/bin/mysqld_safe--skip-grant-tables --user=mysql & /usr/local/mysql/bin/mysql进入mysql 或者执行mysql回车进入mysql,然后修改密码. 修改My

Hadoop 2.2.0 在CentOS6.2 64位下的编译

最近在学习搭建Hadoop,直接从Apache官方网站直接下载最新版本Hadoop2.2,结果运行时发现提示 “libhadoop.so.1.0.0 which might have disabled stack guard” 的警告.Google了一下发现是因为 hadoop 2.2.0提供的是libhadoop.so库是32位的,而我们的机器是64位. 所以需要重新在64位的机器上编译hadoop. 1.安装JDK 下载JDK1.7的Linux 64位版本jdk-7u15-linux-x64

Hadoop2.2.0分布式环境配置笔记1-编译64位hadoop源码

我的测试环境是三台机器 分别是 Hadoop-Yarn.Hark.Com 192.168.1.200 Hadoop-Slave1.Hark.Com 192.168.1.201 Hadoop.Slave2.Hark.Com 192.168.1.202 我为了自己能充分练习hadoop 64位源码编译,所以三台机器都进行了下边的配置 环境: vmware9+centos6.4+hadoop2.2.0 0.创建hadoop帐号,大部分操作都要使用hadoop帐号的 1.关闭窗口模式 使用root账号

Linux下源码安装CodeBlocks

Linux下源码安装CodeBlocks qianghaohao(CodingNutter) 一. 安装平台说明: CentOs6.4-i686  gcc-4.4.7 二. 下载最新源码: http://www.codeblocks.org/downloads 在此安装的是最新版:Code::Blocks 16.01 三. 阅读官方安装说明文档: http://wiki.codeblocks.org/index.php/Installing_Code::Blocks_from_source_on

Linux下源码安装Mysql5.5

本文主要介绍了如何在源码安装mysql5.5,所用系统为CentOS6.5 一.安装相应的开发环境 yum install -y ncurses-devel yum install -y libaio yum install -y bison yum install -y gcc-c++ yum install -y openssl-devel 二.安装cmake 跨平台编译器 # tar xf cmake-2.8.8.tar.gz # cd cmake-2.8.8 # ./bootstrap

Hadoop2.2.0分布式环境配置笔记2-编译64位hadoop源码

11.配置hadoop分布式环境!  三台机器都需要这么配置 1).将/opt/modules/hadoop-2.2.0-src重命名  mv /opt/modules/hadoop-2.2.0-src/ /opt/modules/hadoop-2.2.0-src_x32_back 2).解压64位源码 tar -zxvf /opt/modules/hadoop-2.2.0-src_x32_back/hadoop-dist/target/hadoop-2.2.0.tar.gz -C /opt/m

CentOS 7下源码安装MySQL 5.7

网上说linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有几十M左右,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点是安装速度快,安装步骤简单,缺点是安装包很大,300M左右(5.7版本的是600M左右), 对于第二种方法,我搞了一天,无果,到某个环节实在是无法走通,老大那边也不让搞了,隔了几天老大又吩咐我在生产服务器上安装mysql,这次我就按照第一种方法源码安装方式 下载源码安装包 http://dev.my

CentOS 6.5下源码安装LAMP(Linux+Apache+Mysql+Php)环境

CentOS 6.5下源码安装LAMP(Linux+Apache+Mysql+Php)环境一. 系统环境:Linux系统版本: CentOS release 6.5Apache版本: httpd-2.2.24PHP 版本: php-5.6.11 二.安装前准备: 1.查看是否安装GCC ,GCC-C++编译器,如果没有则进行安装: 查看是否安装的命令: #gcc –v 若未安装在服务器联网情况下可以使用下列命令安装: #yum install gcc #yum install gcc-c++2.