开源数据库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
相关推荐
冬奇Lab9 小时前
每日一个开源项目(第147篇):HyperGraphRAG - 用超图表示 N 元关系,RAG 的第三代范式
人工智能·开源·graphql
倔强的石头_10 小时前
《Kingbase护城河》——猎捕慢查询:执行计划的微观解析与索引调优实战
数据库
网易云信11 小时前
Cursor点燃个人开发者,企业级AI为何频频受挫?Agent工厂从提效工具到AI员工的跃迁
人工智能·开源
SelectDB12 小时前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python
ZzT13 小时前
在 GitHub 上 @一下 claude,它自己把 issue 改成 PR
人工智能·开源
饼干哥哥14 小时前
最强视频创作工作流:Image2 + Seedance 2.0,Topview一键闭环|跨境电商版
开源·产品·设计
ApacheSeaTunnel15 小时前
当多表数据涌入,Apache SeaTunnel 如何巧妙化解主键冲突?
大数据·开源·数据集成·seatunnel·技术分享·数据同步
稀土熊猫君15 小时前
一个人能做出什么开源项目?
vue.js·后端·开源
狂师20 小时前
比 Playwright 更给力,推荐一个AI Agent的浏览器自动化开源项目!
前端·开源·测试
AI袋鼠帝1 天前
开源「仓颉.Skill」2.0,你现在可以蒸馏任何视频!
开源·aigc