开源数据库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
相关推荐
山峰哥29 分钟前
数据库工程与SQL调优——从索引策略到查询优化的深度实践
数据库·sql·性能优化·编辑器
较劲男子汉41 分钟前
CANN Runtime零拷贝传输技术源码实战 彻底打通Host与Device的数据传输壁垒
运维·服务器·数据库·cann
java搬砖工-苤-初心不变1 小时前
MySQL 主从复制配置完全指南:从原理到实践
数据库·mysql
大大大反派1 小时前
CANN 生态未来展望:统一框架 `CANN Unified` 与开源协同演进
开源
酷酷的崽7982 小时前
CANN 开源生态实战:端到端构建高效文本分类服务
分类·数据挖掘·开源
晚霞的不甘2 小时前
CANN 在工业质检中的亚像素级视觉检测系统设计
人工智能·计算机视觉·架构·开源·视觉检测
山岚的运维笔记3 小时前
SQL Server笔记 -- 第18章:Views
数据库·笔记·sql·microsoft·sqlserver
爱吃烤鸡翅的酸菜鱼3 小时前
CANN ops-nn激活函数与池化算子深度解析
网络·开源·aigc
ujainu3 小时前
CANN仓库中的AIGC可持续演进工程:昇腾AI软件栈如何构建“活”的开源生态
人工智能·开源·aigc
酷酷的崽7983 小时前
深度解析 CANN 开源项目:以 `ops-transformer` 为例探索 AI 模型加速实践
开源