开源数据库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
相关推荐
码农阿豪36 分钟前
行标识符的抉择:深入理解数据库领域的OID与ROWID机制
数据库·oracle
不剪发的Tony老师1 小时前
MyCLI:一个增强型MySQL命令行客户端
数据库·mysql
SHANGHAILINGEN1 小时前
2400 万个未培养病毒重新定义病毒多样性
数据库·测序·组学
刘晨鑫11 小时前
PostgreSQL日常维护
数据库·postgresql
xiaokangzhe1 小时前
PG数据库日常应用
数据库·oracle
XDHCOM1 小时前
MySQL ER_DD_VERSION_INSTALLED报错解析,数据字典版本问题,故障修复与远程处理指南
数据库·mysql
2301_822703202 小时前
开源鸿蒙跨平台Flutter开发:幼儿园作业管理系统:基于 Flutter 的沉浸式交互设计与认知发展追踪
flutter·开源·harmonyos
yaoyouzhong3 小时前
MySQL 批量插入详解:快速提升大数据导入效率的实战方法
大数据·数据库·mysql
冬奇Lab3 小时前
一天一个开源项目(第68篇):DeerFlow - 字节跳动出品的深度研究与超级智能体框架
人工智能·开源·资讯
NineData3 小时前
NineData V5.0 产品发布会:让 AI 成为数据管理的驱动力,4月16日!
数据库·人工智能·ai编程