1.安装postgresql
安装依赖包
yum install -y glibc-devel bison flex readline-devel zlib-devel pgdg-srpm-macros lz4-devel libicu-devel llvm5.0-devel llvm-toolset-7-clang krb5-devel e2fsprogs-devel \
openldap-devel pam-devel perl-ExtUtils-Embed python3-devel tcl-devel systemtap-sdt-devel libselinux-devel openssl-devel libuuid-devel libxml2-devel libxslt-devel systemd-devel \
gcc gcc-c++
# libedit-devel
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libedit-devel-3.0-12.20121213cvs.el7.x86_64.rpm
rpm -ivh libedit-devel-3.0-12.20121213cvs.el7.x86_64.rpm
# llvm5.0-devel
wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm
rpm -ivh epel-release-7-14.noarch.rpm
yum install -y llvm5.0-devel
# lz4-devel
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/lz4-devel-1.8.3-1.el7.x86_64.rpm
rpm -ivh lz4-devel-1.8.3-1.el7.x86_64.rpm
# llvm-toolset-7-clang
#写入yum源
cat << EOF > /etc/yum.repos.d/c7-devtoolset-7-x86_64.repo
[c7-devtoolset-7]
name=c7-devtoolset-7
baseurl=https://buildlogs.centos.org/c7-devtoolset-7.x86_64/
gpgcheck=0
enabled=1
[c7-llvm-toolset-7]
name=c7-llvm-toolset-7
baseurl=https://buildlogs.centos.org/c7-llvm-toolset-7.x86_64/
gpgcheck=0
enabled=1
[fedoraproject-epel-7]
name=fedoraproject-epel-7
baseurl=https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/
gpgcheck=0
enabled=1
EOF
yum install -y llvm5.0-devel llvm-toolset-7-clang
安装PostgreSQL14
# 下载官方RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# 安装PostgreSQL:
sudo yum install -y postgresql14-libs postgresql14 postgresql14-devel postgresql14-contrib.x86_64
初始化数据(若需要修改指定的数据存放目录,则参考修改数据库默认数据存储目录):
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
如果出现Data directory is not empty!,
cd /var/lib/pgsql/14/
rm -rf data
再次执行初始化命令 sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
# 设置开机自启动并启动PostgreSQL:
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
修改数据库默认数据存储目录
默认安装路径Environment=PGDATA=/var/lib/pgsql/14/data/
自定义数据存放目录
#创建自定义数据存储目录
mkdir -p /data/pgsql/14/data/
#修改目录权限
chown -R postgres:postgres /data/pgsql
修改自定义服务
vi /usr/lib/systemd/system/postgresql-14.service
修改默认环境变量数据存放路径,找到Environment修改为自己定义的数据存放目录
[Service]
Environment=PGDATA=/data/pgsql/14/data/
#修改完后保存退出
#重新加载systemctl
systemctl daemon-reload
初始化数据库
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
可以看到/data/pgsql/14/data/目录下多了很多文件,证明初始化成功
运行数据库
systemctl enable postgresql-14
systemctl start postgresql-14
2.配置postgresql
切换到postgres用户
su - postgres
-bash-4.2$ psql
用户 postgres 的口令:
psql (14.2)
输入 "help" 来获取帮助信息.
修改系统用户密码,一定要修改不然等你改完配置文件就不能这么轻松愉快的进入这个页面了
postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
postgres=# \q
修改配置文件
vim /var/lib/pgsql/14/data/postgresql.conf
开启远程访问,将listen_address 修改为 * ,端口号可改可不改
vim /var/lib/pgsql/14/data/pg_hba.conf
在文件末尾增加如下配置
host all all 0.0.0.0/0 scram-sha-256
3.重启服务,远程链接测试
sudo systemctl restart postgresql-14
[root@jerry ~]# psql -U postgres -h 127.0.0.1 --port 58063
用户 postgres 的口令:
psql (14.2)
输入 "help" 来获取帮助信息.
postgres=#
4. postgis安装
yum install -y postgis32_14.x86_64
# 安装完成后,要开启拓展
// 转到postgres用户
# su - postgres
//开启psql
# psql
// 开启pgsql的插件
postgres=# create extension postgis;
postgres=# create extension postgis_topology;
postgres=# create extension fuzzystrmatch;
postgres=# create extension address_standardizer;
postgres=# create extension address_standardizer_data_us;
postgres=# create extension postgis_tiger_geocoder;
//查看版本,验证安装是否成功
postgres=# SELECT PostGIS_full_version();