linux安装postgresql数据库
本文提供数据库安装脚本,有部分需要优化,就是脚本中的方法执行存在前后依赖,但是代码里面没有对上一个执行结果进行判断,如果提供的路径和安装包没有问题,脚本能够正常执行
#!/bin/bash
# install postgre
# base_path=$(cd $(dirname ${BASH_SOURCE[]}); pwd )
base_path="/opt"
# Pg database installation package name
pg_name="./postgresql-9.6.15-1-linux-x64-binaries.tar.gz"
# Pg database installation path
pg_deploy_path="$base_path/postgreSQL"
# Directory of data stored in the pg database
pg_data_path="${pg_deploy_path}/data"
# Directory of data stored in the pg database
user_name='pguser' # unzip pg
function pg_untar(){
if [ -d ${pg_deploy_path} ];then
echo "pg has been installed"
else
if [ ! -e ${pg_name} ];then
echo "Missing pg installation package"
else
mkdir -p ${pg_deploy_path}
tar -zxf ${pg_name} -C ${pg_deploy_path}
fi
fi
} # Create a Linux user to log in to the PG database
function pg_create_user(){
# user_exist=`cat /etc/passwd | grep '^${user_name}:' -c`
egrep "^${user_name}" /etc/passwd >/dev/null
if [ $? -eq ]; then
pass=$(perl -e 'print crypt($ARGV[0], "password")' $user_name)
useradd -m -p $pass ${user_name}
#useradd -m -p 'postgres' ${user_name}
[ $? -eq ] && echo "user [${user_name}] has been added to system!" || echo "Failed to add user [${user_name}]"
else
echo "user [${user_name}] exists"
fi
} #init pg
function pg_init(){
#Create a data directory
mkdir -p ${pg_data_path}
touch ${pg_deploy_path}/logfile
#Grant user access
chown -R ${user_name} ${pg_data_path}
chown ${user_name} ${pg_deploy_path}/logfile # init database
su - ${user_name} -c "${pg_deploy_path}/pgsql/bin/initdb -D ${pg_data_path}"
} #Modify config of the pg database
#
function pg_modify_config(){
id_path=${pg_data_path}/postgresql.conf
local_path=${pg_data_path}/pg_hba.conf
localip=$(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
if [ -d ${pg_data_path} ];then
chown -R 'root' ${pg_data_path}
#Modify listening ip
sed -i "s@#listen_addresses = 'localhost'@listen_addresses = \'${localip}\'@g" $id_path
#Modify Trust client ip
#sed -i "s@#listen_addresses = 'localhost'@listen_addresses = \'${localip}\'@g" $id_path
sed '86 ahost all all 0.0.0.0/0 trust' -i $local_path
chown -R ${user_name} ${pg_data_path}
else
echo "You need to initialize the database with the command:\n\t ${pg_deploy_path}/pgsql/bin/initdb -D ${pg_data_path} "
fi
} # start pg database
function pg_start(){
su - ${user_name} -c "${pg_deploy_path}/pgsql/bin/pg_ctl -D ${pg_data_path} -l ${pg_deploy_path}/logfile start"
}
# create default database bms_ops
function pg_createdb(){
sleep 3s
default_db="bms_ops"
su - ${user_name} -c "${pg_deploy_path}/pgsql/bin/createdb -O ${user_name} ${default_db}"
}
#Open port
function pg_open_port(){
isopen=$(firewall-cmd --query-port=/tcp)
if [ 'no' == $isopen ];then
firewall-cmd --add-port=/tcp --permanent>/dev/null
firewall-cmd --reload>/dev/null
else
echo "port 5432 already opened"
fi } echo "============== start install pg =============="
if [ -d ${pg_deploy_path} ];then
echo "pg has been installed"
else
pg_untar
pg_create_user
pg_init
pg_modify_config
pg_start
pg_createdb
pg_open_port
fi
echo "============== finish installing pg =============="
linux安装postgresql数据库的更多相关文章
- Linux 安装 PostgreSQL
Linux 安装 PostgreSQL CentOS 7 安装 PostgreSQL 10 步骤 官网安装步骤,选择服务器和数据库版本,会给出相应的安装命令 # 安装 yum install -y h ...
- Windows Azure上的Odoo(OpenERP)-1.创建Ubuntu虚拟机,安装PostgreSQL 数据库
前提是您必须拥有Windows Azure的账号,如果没有的话,可以去Windows Azure 中国区网站申请免费试用账号.哈哈,我就是第一批申请的试用账号,感觉自己挺幸运的.申请的过程就不写了,请 ...
- Windows安装PostgreSQL数据库 无法初始化数据库问题
背景 由于项目的需要,使用PostgreSQL数据库,因此在Windows上安装PostgreSQL数据库.但是在安装后,无法访问本地数据库,这个时候查看/data目录,没有任何文件.而且安装过程中, ...
- linux下PostgreSQL数据库的源码安装
实验环境>>>>>>>>>>>>>>>>>>操作系统:CentOS release 6.3 ...
- [zz]安装PostgreSQL数据库(Linux篇)
0.编译环境 Linux: CentOS 5.5 gcc: 4.1.2 1. 安装PostgreSQL 1) 解压postgresql-9.1.7.tar.bz2 #tar jxvf postgres ...
- 安装PostgreSQL数据库(Linux篇)
0.编译环境 Linux: CentOS 5.5 gcc: 4.1.2 1. 安装PostgreSQL 1) 解压postgresql-9.1.7.tar.bz2 #tar jxvf postgres ...
- [亲测有效] - Linux安装PostgreSQL
本文章来为各位介绍一篇关于postgresql 9.4 在linux环境的安装步骤详解,希望文章能够对各位新手朋友带来帮助的哦. 环境说明系统:centos 6.4 64位软件:postgresq ...
- linux安装postgresql
第一步在编译安装postgresql源码的时候,需要用到以下依赖,若本机没有的话,需要提前安装依赖环境,执行以下命令:yum install gcc gcc-c++yum install zlib-d ...
- 国产龙芯服务器源码安装PostgreSQL数据库的方法
1. 公司最近有一些国产化项目的需求, 要求在国产CPU的服务器上面安装pg数据库等. 2.. 但是差查了下中标麒麟的官网,在龙芯MIPS的操作系统包源里面仅有 postgreSQL 9.2 版本的r ...
随机推荐
- tomcat启动报错failed to start component
严重: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catali ...
- Educational Codeforces Round 72 (Rated for Div. 2)C(暴力)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[200007];int a[20 ...
- C++11通过拷贝构造器拷贝const字段(待解决)
问题梗概如标题所述. 在今天实现Token类的时候,遇到的问题. 我希望将Token类设定为immutable属性的,这样实现的方式是将这个类内的所有字段均设置为const型,同时每个字段均为publ ...
- 好用的log打印类
package com.huawei.network.ott.weixin.util; import android.util.Log; public final class DebugLog { / ...
- gcc/g++/make/cmake/makefile/cmakelists的恩恩怨怨
以前在windows下用VS写代码,不管有多少个文件夹,有多少个文件,写完以后只需要一键就什么都搞定了.但是当移步linux下时,除非你使用图形界面,并且使用Qt creater这类的IDE时,才可以 ...
- Py2与Py3的区别
总结Py2 与Py3 的区别 1 编码区别 在Python2中有两种字符串类型str和Unicode. 默认ASCII python2 str类型,相当于python3中的bytes类型 python ...
- c++ (翁恺浙大公开课)前言、目录
c++语言比较复杂,学习起来相对难一些,加之特性繁多,很难全部掌握:特别是工作几年之后,每次温故都有很大的收获,之前不懂的地方随着工作的积累和重新的学习,都会慢慢的解开,当然我现在还是很菜... 之所 ...
- 中国6G为什么要从现在上路?
现在,通信5G的概念早已深入人心,正在从蓝图上的规划走向现实,平心而论,中国在2G/3G/4G时代都没有太突出的表现,或受制于人.或沦为跟随者,如今中国想翻身,于是从一开始就卯足了劲儿抢跑5G,不仅把 ...
- 十六、JSONObject与JSONArray使用-不刷新页面做回写显示
需要导入:json-lib-2.2.2-.jar包 1.json:就是一个键对应一个值,超级简单的一对一关系.对于json嵌套,只要记住符号“:”前是键,符号后是值大括号成对找. String arr ...
- ch7对表单和数据表格使用样式
对数据表格应用样式 1.表格特有的元素 caption:基本上用做表格的标题.summary:可应用于表格的标签,用来描述表格的内容(与image的alt文本相似) <table class=& ...