Centos 7 自动安装Postgresql-13

1. 创建自动安装脚本文件

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

 脚本内容如下:

#!/bin/bash
s_="\033[43;35m"
e_="\033[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. 查看安装是否成功

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


版权声明:本文为WLPJLP原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。