yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql11
yum install postgresql11-server
通过上面步骤,若无法安装成功,尝试以下安装:
sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
rpm -qi pgdg-redhat-repo
sudo dnf module disable postgresql
sudo dnf clean all
sudo dnf -y install postgresql11-server postgresql11
dnf info postgresql11-server postgresql11
cd /home
mkdir postgresql
chmod 777 /home/postgresql
su postgres
/usr/pgsql-11/bin/initdb -D /home/postgresql/data
cd /home/postgresql
/usr/pgsql-11/bin/pg_ctl -D /home/postgresql/data -l logfile start
密码需要替换
psql
ALTER USER postgres WITH PASSWORD '(密码)';
\q
开放登录端口:
vim /home/postgresql/data/postgresql.conf
修改以下两项内容如下:
listen_addresses = ‘*’
port = 5432
vim /home/postgresql/data/pg_hba.conf
添加内容:
host all all 0.0.0.0/0 md5
重启数据库
/usr/pgsql-11/bin/pg_ctl -D /home/postgresql/data -l logfile restart
新建数据库:
su postgres
psql
CREATE DATABASE tengine2;
\q
psql -d tengine2 -U postgres -f tengine2.0.sql
创建脚本
mkdir /home/postgresql/bin
cd /home/postgresql/bin
vim startup.sh
输入一下内容:
#! /bin/bash
su postgres< cd /home/postgresql
/usr/pgsql-11/bin/pg_ctl -D /home/postgresql/data -l logfile start
exit $?
!
添加脚本路径
chmod -R 755 startup.sh
vim /etc/rc.local
在文件内容最后一行添加:
/home/postgresql/bin/startup.sh
创建脚本:
mkdir -p /home/backup/pgsql/data
chmod 777 /home/backup/pgsql/data
mkdir -p /home/backup/pgsql/bin
cd /home/backup/pgsql/bin
vim backup.sh
输入如下内容:
#! /bin/bash
t=KaTeX parse error: Expected group after '_' at position 112: …ip > backupfile_̲t.sql.gz
find /home/backup/pgsql/data -mtime 7 -type f|xargs rm -f
exit $?
!
配置定时任务:
chmod -R 755 backup.sh
crontab -e