开源数据库postgresql在统信系统上的离线安装shell脚本

一个tar包:pgsql_install.tar.bz2

bash 复制代码
#!/bin/sh
echo "安装pgsql_15.4"
rm -rf /home/postgres/postgresql
mysqldir="/home/postgres"
mkdir -p $mysqldir
cp /home/pgsql_install.tar.bz2 $mysqldir
cd $mysqldir

tar -jxvf pgsql_install.tar.bz2

echo "解压pgsql_15.4源码包"
tar zxvf postgresql-15.4.tar.gz
mv postgresql-15.4 postgresql

echo "下载pgsql_15.4依赖"
rpm -ivh --force --nodeps *.rpm

echo "编译的时候用来指定程序存放路径..."
cd $mysqldir/postgresql
./configure --prefix=/home/postgres/postgresql

echo "编译安装pgsql..."
make && make install

echo "创建用户和用户组"
groupadd -g 2000 postgres
useradd -g 2000 -u 2000 postgres
id postgres

echo "创建相关目录并授权"
mkdir data log
chown -R postgres.postgres $mysqldir/postgresql

echo "设置环境变量"
if grep -q "PGHOME=/home/postgres/postgresql" /etc/profile; then
    echo "存在pgsql的环境变量"
else
    echo -e 'export PGHOME=/home/postgres/postgresql\nexport PGDATA=$PGHOME/data\nexport PGLIB=$PGHOME/lib\nexport LC_ALL=en_US.UTF8\nexport LANG=en_US.UTF8\nPATH=$PGHOME/bin:$PATH\nexport PATH' >> /etc/profile
fi

source /etc/profile

echo "关闭防火墙"
systemctl stop firewalld.service 
systemctl disable firewalld.service
setenforce 0 

echo "解决退出问题"
touch /home/postgres/.psql_history
chown postgres:postgres /home/postgres/.psql_history
chmod 700 /home/postgres/.psql_history

echo "初始化"
su - postgres <<EOF
cd /home/postgres/postgresql/bin/
initdb -D ../data/

echo "修改postgresql.conf,监听所有地址"
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /home/postgres/postgresql/data/postgresql.conf

echo "修改pg_hba.conf,修改密码"
echo 'host all all 0.0.0.0/0 md5' >> /home/postgres/postgresql/data/pg_hba.conf

echo "重启数据库"
pg_ctl -D /home/postgres/postgresql/data/ -l logfile start
exit;
EOF

echo "修改初始化密码"
psql -p 5432 -U postgres -d postgres <<EOF
ALTER USER postgres WITH PASSWORD 'postgres';
create user root with password 'Test~123';
create database test with encoding='utf8' owner=root;
EOF
相关推荐
小白学大数据11 小时前
Redis 在定时增量爬虫中的去重机制与过期策略
开发语言·数据库·redis·爬虫
方璧11 小时前
ETCD注册中心
数据库·学习·etcd
week_泽12 小时前
百战商城商品数据云函数化改造总结_百战_3
数据库·笔记·微信小程序·小程序
爱吃提升12 小时前
Python 使用 MySQL 数据库进行事务处理步骤
数据库·python·mysql
Antoine-zxt12 小时前
深入解析MySQL事务ACID:从理论到实践的完整指南
数据库·mysql·oracle
7ioik12 小时前
什么是版本链?
数据库·mysql
手握风云-12 小时前
MySQL数据库精研之旅第二十期:存储过程,数据处理的全能工具箱(三)
数据库·mysql
2509_9408802212 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
胖头鱼的鱼缸(尹海文)12 小时前
数据库管理-第399期 Oracle 19c搭建DG Far Sync日志备库(20260107)
数据库·oracle
Vic1010112 小时前
华为云高斯数据库:gsqlexec用法
java·大数据·数据库·postgresql·华为云