首页 > 其他分享 >【Vagrant】 Build PG15 on rhel8

【Vagrant】 Build PG15 on rhel8

时间:2023-10-07 22:00:10浏览次数:39  
标签:15 postgres db sudo Vagrant vm rhel8 pgsql Build

vagrant创建一套single PG15,同时创建一个新的数据库db_pg15 (密同)

Vagrant.configure("2") do |config|
    vms = [
#      { name: "app01", box: "centos-8", hostname: "app01", ip: "192.168.33.11" },
#      { name: "gitlab", box: "centos-8", hostname: "gitlab", ip: "192.168.33.12" },
#      { name: "db01", box: "centos-8", hostname: "db01", ip: "192.168.56.11" },
      { name: "db02", box: "centos-8", hostname: "db02", ip: "192.168.56.12", provision: "postgres_install.sh" }
    ]
  
    vms.each do |vm_data|
      config.vm.define vm_data[:name] do |vm|
        vm.vm.box = vm_data[:box]
        vm.vm.hostname = vm_data[:hostname]
        vm.vm.network "private_network", type: "static", ip: vm_data[:ip]
  
        vm.vm.provider "virtualbox" do |vb|
          vb.name = vm_data[:name]
          vb.memory = 1024
          vb.cpus = 2
        end
  
        if vm_data[:provision]
          vm.vm.provision "shell", path: vm_data[:provision]
        end
      end
    end
  end

postgres_install.sh

#!/bin/bash
sudo  dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

sudo dnf update -y
sudo dnf -y module disable postgresql


sudo dnf -y install postgresql15-server


mkdir -p /pgsql/15/{data,dump,dba,backup}
chown -R postgres:postgres /pgsql
chmod -R 700 /pgsql 
echo "export PATH=/usr/pgsql-15/bin:$PATH">> /etc/profile
 
echo "export PGHOME=/pgsql/15" >> /var/lib/pgsql/.bash_profile
echo "export PGDATA=/pgsql/15/data " >> /var/lib/pgsql/.bash_profile
echo "export PGDUMP=/pgsql/15/dump  " >> /var/lib/pgsql/.bash_profile
echo "export PGBACKUP=/pgsql/15/backup " >> /var/lib/pgsql/.bash_profile

sed -e 's|Environment=PGDATA=/var/lib/pgsql/15/data/|Environment=PGDATA=/pgsql/15/data/|g' -i.bak /usr/lib/systemd/system/postgresql-15.service



sudo /usr/pgsql-15/bin/postgresql-15-setup initdb

echo "host    postgres    postgres    0.0.0.0/0   scram-sha-256" | sudo tee -a /pgsql/15/data/pg_hba.conf > /dev/null

sed -i "s|#listen_addresses = 'localhost'|listen_addresses = '*'|g" -i.bak /pgsql/15/data/postgresql.conf

sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15
sudo systemctl status postgresql-15


sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
/bin/systemctl restart sshd

echo postgres | passwd postgres --stdin 

echo root | passwd root --stdin 




# reset the password for postgres
echo "Setting password for postgres user"
cd /
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"

# create new DB named db_pg15
echo "Creating a new PostgreSQL database"
sudo -u postgres createdb main_db

# reset the password in db_pg15
echo "Creating a new PostgreSQL user and granting access to the database"
sudo -u postgres psql -c "CREATE USER db_pg15 WITH PASSWORD 'db_pg15';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE db_pg15 TO db_pg15;"

#!/bin/bash

# export the db name
#DB_NAME="db_pg15"

# export the db user
#DB_USER="db_user"

# expose the ip
#ALLOWED_NETWORK="192.168.33.0/24"

# export the password 
#DB_PASSWORD="db_user"

# update PostgreSQL pg_hba.conf
echo "host    db_pg15    db_pg15    0.0.0.0/0   scram-sha-256" | sudo tee -a /pgsql/15/data/pg_hba.conf > /dev/null

# restart PostgreSQL
sudo systemctl restart postgresql-15


标签:15,postgres,db,sudo,Vagrant,vm,rhel8,pgsql,Build
From: https://www.cnblogs.com/Jeona/p/17747592.html

相关文章

  • 【HBuilderX】解决黑色主题中的注释颜色太浅的问题(代码示例)
    "foreground":"#a6a085"打开后,搜索Comment,修改,一个是//的颜色,一个是注释内容的颜色{ "name":"Comment", "scope":"comment", "settings":{ "foreground":"#a6a085" } }, {......
  • 包装类、StringBuilder、StringBuffer、StringJoiner
    1、怎么将Int类型的包装成对象使用Integer的valueOf方法Integera2==Integer.valueOf(12);2、自动装箱机制(可以自动把基本数据类型的数据转换成对象)Integera3=12;自动拆箱机制(可以自动把包装类型的对象转换成对应的基本数据类型)inta4=a3;......
  • typescript: Builder Pattern
     /***TypeScript实体类Model*BuilderPattern*生成器是一种创建型设计模式,使你能够分步骤创建复杂对象。*https://stackoverflow.com/questions/12827266/get-and-set-in-typescript*https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines*/cl......
  • soui uiresbuilder.exe使用
    "D:\work\tmp\soui-master\tools\uiresbuilder.exe"-i"D:\work\tmp\soui-master\demo\uires\uires.idx"-puires-r.\res\soui_res.rc2-h.\res\resource.hidtable 【转】:soui编译资源-CSDN博客 ......
  • PowerBuilder编程新思维10.5:外传2(PowerPlume下一代开发解决方案)
    万里归来年愈少 PowerBuilder编程新思维10.5:外传2(PowerPlume下一代解决方案) 前言今天我们就来盘点一下,PB下一代开发的所有技术可能性。所谓下一代开发技术,就是指脱离或半脱离PBVM的应用开发技术,主要指后端。 后端技术汇总  前端PB+JSON前端PB+BLOBWEB后端P......
  • PowerBuilder现代编程方法X11:PB程序完全跨平台方案
     PB可能要支持Windows、macOS、Linux、iOS、Android与鸿蒙操作系统和X86、ARM、RISC-V与国产龙芯CPU的原生应用了! PowerBuilder现代编程方法X11:PB程序完全跨平台方案 前言《PowerBuilder编程新思维》在写到了WebUI后,陷入了沉寂。原因是我对PB发展的下一代技术方案不太满......
  • Sentinel系列之SlotChain、NodeSelectorSlot、ClusterBuilderSlot分析
    本文基于Sentinel1.8.6版本分析1.SlotChain我们从入口com.alibaba.csp.sentinel.SphU#entry(java.lang.String)开始分析。一路走读下来,会进入到这个方法com.alibaba.csp.sentinel.CtSph#lookProcessChain,查找该资源对应的SlotChain。接下来看如何构建这个SlotChain.Se......
  • Module build failed (from ./node_modules/css-loader/dist/cjs.js): CssSyntaxError
    问题描述在webpack的时候报错ERRORin./packages/theme-chalk/mixins/mixins.scss(./node_modules/css-loader/dist/cjs.js!./packages/theme-chalk/mixins/mixins.scss)Modulebuildfailed(from./node_modules/css-loader/dist/cjs.js):CssSyntaxError(14:8)......
  • docker build过慢问题
    有一个前端项目,在我删除了node_modules之后,构建非常慢,半个小时都没执行完一直以为是jenkins问题,重启了也没用,一直卡在dockerbuild步骤,后来干脆就挂着执行,执行完查看日志后来看到 SendingbuildcontexttoDockerdaemon932MB好家伙,一个前端项目项目最多20M,怎么会这么大,查......
  • [Linux] Compile and Build h5py with MPI
    HowtoInstallH5PY-MPI0.Preparationlinuxsystemgccanaconda/miniconda1.Installopen-mpiGoto"https://www.open-mpi.org/software/".Downloadthelastestrelease(endedwith".tar.gz").Opentheterminalandchangedirtothed......