栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Centos 7 自动安装Postgresql-13

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Centos 7 自动安装Postgresql-13

1. 创建自动安装脚本文件
# 切换路径为 /home
cd /home
 
# 创建脚本文件并写入执行的脚本
vi pgsqlShell.sh

 脚本内容如下:

#!/bin/bash
s_="33[43;35m"
e_="33[0m"
echo -e "$s_ 安装PostgreSQL-13 $e_"
  if ! type postgresql >/dev/null 2>&1; then
    rpm -Uvh https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    yum install -y postgresql13-server
    echo "初始化库PostgreSQL"
    /usr/pgsql-13/bin/postgresql-13-setup initdb
    systemctl start postgresql-13
    sleep 5
    # PostgreSQL 数据库密码,请自行修改
    POSTGRES_PASS="myPostgres.com"
    
    echo "ALTER USER postgres WITH PASSWORD '${POSTGRES_PASS}';" | sudo -u postgres psql
    echo "listen_addresses = '*'">> /var/lib/pgsql/13/data/postgresql.conf
    echo 'host    all             all             0.0.0.0/0                md5'>> /var/lib/pgsql/13/data/pg_hba.conf
    systemctl restart postgresql-13
    systemctl daemon-reload
    systemctl enable postgresql-13
    echo -e "$s_ 安装PostgreSQL-13 完毕 $e_"
    echo -e "$s_ PostgreSQL-13的用户:'postgres' 密码:'${POSTGRES_PASS}' $e_"
  else
    echo -e "$s_ PostgreSQL-13已安装,无需安装操作 $e_"
  fi

保存并退出即可

2. 执行脚本

命令:sh  /home/pgsqlShell.sh

3. 查看安装是否成功

远程连接自行测试,脚本中已经开启了远程访问

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/291884.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号