PostgreSQL自动安装脚本

抽空写了一个postgresql的自动安装部署脚本,方便集群化安装

环境:
OS:CentOS 6.3
DB:PostgreSQL 9.3.2

使用步骤:
分两个脚本,一个是执行文件,另一个是初始化脚本,实际只要点击执行文件install_postgres.sh即可。

1.上传这两个文件到/tmp目录下
2.root用户执行sh install_postgres.sh 内容:

1.install_postgres.sh

1[root@db tmp]# more install_postgres.sh 2#!/bin/bash 3 4###################################################### 5## 6## Purpose:Install Postgresql Automatically 7## 8## Author :Kenyon 9## 10## Created:2014-02-08 11## 12## Version:1.0.0 13##################################################### 14 15echo "--------------------Check current OS datetime---------------------" 16 17DATE=`date +"%Y-%m-%d %H:%M:%S"` 18 19echo "------系统当前时间: $DATE------------------" 20echo "------确保系统时间不早于实际时间----------" 21echo "------请输入 Y or N 继续-----------------" 22read input 23if [ "$input" = "N" -o "$input" = "n" ]; then 24echo "-------------------Modify OS datetime correctly,exit install!-----" 25exit 1 26 27elif [ "$input" = "Y" -o "$input" = "y" ];then 28echo "---------------------start install PostgreSQL---------------------" 29yum install -y wget perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake 30mkdir -p /database/pgdata 31 32echo "---------------------create postgres user if not exist------------" 33if [ `grep "postgres" /etc/passwd | wc -l` -eq 0 ];then 34echo "adding user postgres" 35/usr/sbin/groupadd postgres 36/usr/sbin/useradd postgres -g postgres 37echo "postgres"|passwd --stdin postgres 38else 39echo "-------------- the user of Postgres is already exist,ignore useradd" 40fi 41 42cd /database 43chown -R postgres:postgres ./pgdata 44 45echo "---------------------download PostgreSQL source code----------------" 46cd /tmp 47chown postgres:postgres ./initdb_postgres.sh 48chmod u+x ./initdb_postgres.sh 49su - postgres -c /tmp/initdb_postgres.sh 50 51else 52echo "--------------------输入错误,请输入 Y or N-------------------" 53exit 1 54fi

2.initdb_postgres.sh

1#!/bin/bash 2 3###################################################### 4## 5## Purpose: Init Postgresql Automatically 6## 7## Author :Kenyon 8## 9## Created:2014-02-08 10## 11## Version:1.0.0 12##################################################### 13 14if [ `whoami` != "postgres" ] ; then 15echo "------------------Should be postgres user initdb!!----------------" 16exit 1 17 18else 19 20ecgo "-------------------init postgres's environment variables-----------" 21cat >> ~/.bash_profile << EOF 22export PGPORT=1949 23export PGHOME=/home/postgres 24export PGDATA=/database/pgdata 25export PATH=\$PGHOME/bin:\$PATH 26export MANPATH=\$PGHOME/share/man:\$MANPATH 27export LANG=en_US.utf8 28export LD_LIBRARY_PATH=\$PGHOME/lib:\$LD_LIBRARY_PATH 29 30alias pg_stop='pg_ctl -D \$PGDATA stop -m fast' 31alias pg_start='pg_ctl -D \$PGDATA start' 32alias pg_reload='pg_ctl -D \$PGDATA reload' 33EOF 34 35wget http://ftp.postgresql.org/pub/source/v9.3.2/postgresql-9.3.2.tar.gz 36echo "tar -zxvf postgresql-9.3.2.tar.gz" 37tar -zxvf postgresql-9.3.2.tar.gz 38cd postgresql-9.3.2 39 40echo "-------------------Configuring PostgreSQL,please wait---------------" 41./configure --prefix=/home/postgres --with-pgport=1949 --with-perl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety 42 43if [ $? -ne 0 ];then 44echo "Configure Postgresql失败,请检查config日志!" 45exit 1 46fi 47 48echo "-------------------Installing PostgreSQL,please wait----------------" 49gmake world 50if [ $? -ne 0 ];then 51echo "Gmake Postgresql失败 ,请检查日志!" 52exit 1 53fi 54 55gmake install-world 56if [ $? -ne 0 ];then 57echo "Gmake install Postgresql failed ,请检查日志!" 58exit 1 59fi 60 61echo "-----------------Initing Database----------------------------------" 62 63echo "Tc_Pgsql_ky">/tmp/postgres_pwd.txt 64initdb -D /database/pgdata -E UTF8 --locale=C -U postgres --pwfile /tmp/postgres_pwd.txt 65if [ $? -eq 0 ];then 66 echo "---------------安装PostgreSQL成功---" 67 rm -f /tmp/postgres_pwd.txt 68else 69 echo "--------------安装PostgreSQL失败,请检查日志------------" 70 exit 1 71fi 72 73 74fi

其他: 时间关系后期调整一下输入端口选择和密码动态输入

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )