开源数据库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
相关推荐
Leo.yuan23 分钟前
不同数据仓库模型有什么不同?企业如何选择适合的数据仓库模型?
大数据·数据库·数据仓库·信息可视化·spark
麦兜*40 分钟前
MongoDB 6.0 新特性解读:时间序列集合与加密查询
数据库·spring boot·mongodb·spring·spring cloud·系统架构
chat2tomorrow42 分钟前
数据采集平台的起源与演进:从ETL到数据复制
大数据·数据库·数据仓库·mysql·低代码·postgresql·etl
稻草人想看远方1 小时前
关系型数据库和非关系型数据库
数据库
考虑考虑1 小时前
Postgerssql格式化时间
数据库·后端·postgresql
千里码aicood1 小时前
【springboot+vue】党员党建活动管理平台(源码+文档+调试+基础修改+答疑)
java·数据库·spring boot
TDengine (老段)1 小时前
TDengine 选择函数 Max() 用户手册
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
驾驭人生1 小时前
Asp .Net Core 系列:Asp .Net Core 集成 Hangfire+MySQL
数据库·mysql·.netcore
xhbh6662 小时前
不止是DELETE:MySQL多表关联删除的JOIN语法实战详解
数据库·mysql·程序员·mysql删除语句