Postgres
麒麟KylinV10编译安装Postgres17.4
本文档使用 MrDoc 发布
-
+
首页
麒麟KylinV10编译安装Postgres17.4
## 安装编译环境及依赖 ```bash yum install -y openssl openssl-devel pam pam-devel \ perl-devel python-devel perl-ExtUtils-Embed readline \ readline-devel zlib zlib-devel gettext gettext-devel \ bison flex gcc gcc-c++ uuid uuid-devel openldap-devel \ systemd-devel libxml2 libxml2-devel libxslt libxslt-devel \ perl libicu-devel cmake ``` ## 新建用户及目标目录 ``` useradd postgres # 不允许在特权帐号下允许 echo 'admin'|passwd --stdin postgres # 用户密码为admin mkdir /data/postgres/{logs,systemd} -p ``` ## 编译安装postgresQL ```bash tar -zxvf postgresql-17.4.tar.gz cd postgresql-17.4/ ./configure --prefix=/data/postgres --with-libxml \ --with-libxslt --with-perl --with-pgport=5432 --with-openssl \ --with-ossp-uuid --with-systemd --with-blocksize=16 make -j $(nproc) && make install chown postgres.postgres -R /data/postgres ``` 参数说明 - --with-blocksize=16 #根据业务需求选择编译的内容,默认8 - --with-system #可注册成系统服务。 ## 初始化数据库 ``` sudo -u postgres /data/postgres/pgsql/bin/initdb -D \ /data/postgres/datadir -E UTF8 --locale=zh_CN.utf8 ```  ## 基础配置 配置远程访问 ``` cat /data/postgres/datadir/postgresql.conf host all all 0.0.0.0/0 trust ``` 配置端口 ``` cat /data/postgres/datadir/pg_hba.conf ``` ``` listen_addresses = '0.0.0.0' prot = 5432 max_connections = 9999 ``` ## 注册服务 ``` cat /etc/systemd/system/postgres.service ``` ``` [Unit] Description=PostgreSQL database server After=network.target [Service] Type=forking User=postgres ExecStart=/data/postgres/pgsql/bin/pg_ctl start -D /data/postgres/datadir -l /data/postgres/logs/postgres.log ExecStop=/data/postgres/pgsql/bin/pg_ctl stop -D /data/postgres/data [Install] WantedBy=multi-user.target ``` ## 环境变量设置 使用postgres用户,环境变量使用/home/postgres/.bashrc文件 ```bash cat /home/postgres/.bashrc ``` ``` export PGHOME=/data/postgres export PGDATA=/data/postgres/datadir export LD_LIBRARY_PATH=$PGHOME/lib:lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH export DATE='date +"%Y%m%d%H%M"' export PATH=$PGHOME/bin:$PATH:. export MANPATH=$PGHOME/share/man:$MANPATH ``` ## 启动Postgres服务 ``` systemctl daemon-reload systemctl enable postgres.service systemctl start postgres ``` ## 设置管理密码 ``` sudo -u postgres /data/postgres/pgsql/bin/psql alter user postgres with password 'postgres'; exit; ``` ## 开放端口 查询指定端口是否已开 ``` firewall-cmd --query-port=5432/tcp ``` 提示 yes,表示开启;no表示未开启。 添加需要开放的端口 ``` firewall-cmd --add-port=5432/tcp --permanent firewall-cmd --reload ``` ## 安装GIS空间插件 >前提条件: >安装PostGIS之前必须先安装proj,geos,gdal. ``` yum install -y cmake3 gcc gcc-c++ make sqlite-devel libtiff libtiff-devel libcurl-devel # 提供插件安装目录 mkdir /data/postgres/plugin ``` ``` http://download.osgeo.org/proj/proj-9.6.1.tar.gz tar -zxvf proj-9.6.1.tar.gz cd proj-9.6.1 mkdir build cd build cmake .. -DCMAKE_INSTALL_PREFIX=/data/postgres/plugin/proj make -j$(nproc) make install echo '/data/postgres/plugin/proj/lib64' > /etc/ld.so.conf.d/proj-9.6.1.conf ldconfig ``` 安装geos开发包 ``` wget https://download.osgeo.org/geos/geos-3.9.6.tar.bz2 tar -jxf geos-3.9.6.tar.bz2 cd geos-3.9.6 mkdir build cd build cmake .. -DCMAKE_INSTALL_PREFIX=/data/postgres/plugin/geos make -j$(nproc) make install echo '/data/postgres/plugin/geos/lib' > /etc/ld.so.conf.d/geos-3.9.6.conf ldconfig ``` 安装gdal开发包 ``` wget http://download.osgeo.org/gdal/3.9.3/gdal-3.9.3.tar.gz tar -zxvf gdal-3.9.3.tar.gz cd gdal-3.9.3 mkdir build cd build cmake .. -DCMAKE_INSTALL_PREFIX=/data/postgres/plugin/gdal \ -DPROJ_INCLUDE_DIR=/data/postgres/plugin/proj/include \ -DPROJ_LIBRARY=/data/postgres/plugin/proj/lib make -j$(nproc) make install echo '/data/postgres/plugin/gdal/lib64/' > /etc/ld.so.conf.d/gdal-3.9.3.conf ldconfig ``` 下载地址 ``` wget https://postgis.net/stuff/postgis-3.7.0dev.tar.gz tar -zxvf postgis-3.7.0dev.tar.gz cd postgis-3.7.0dev yum install -y libxml2 libxml2-devel ./configure --with-pgconfig=/data/postgres/pgsql/bin/pg_config ```
Nathan
2025年9月15日 12:30
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文件
Docx文件
分享
链接
类型
密码
更新密码