centos7 下安装PostgreSQL 及timescaledb 的过程( 二 )

sudo systemctl restart postgresql-15
3:进入 PostgreSQL 控制台添加timescaledb
sudo -u postgres psql
在 PostgreSQL 控制台中运行以下命令安装 TimescaleDB 扩展:
postgres=# CREATE database tutorial;postgres=# c tutorialtutorial=# CREATE EXTENSION IF NOT EXISTS timescaledb;警告:WELCOME TO_____ _ _ ____________|_ _(_) | | | ____ | | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ /| | | | _ ` _/ _ / __|/ __/ _` | |/ _| | | ___ | | | | | | | | | __/__(_| (_| | | __/ |/ /| |_/ /|_| |_|_| |_| |_|___||___/_____,_|_|___|___/ ____/Running version 2.11.2For more information on TimescaleDB, please visit the following links:1. Getting started: https://docs.timescale.com/timescaledb/latest/getting-started2. API reference documentation: https://docs.timescale.com/api/latest3. How TimescaleDB is designed: https://docs.timescale.com/timescaledb/latest/overview/core-conceptsNote: TimescaleDB collects anonymous reports to better understand and assist our users.For more information and how to disable, please see our docs https://docs.timescale.com/timescaledb/latest/how-to-guides/configuration/telemetry.CREATE EXTENSIONtutorial=#后期配置要使其他机器能够访问 PostgreSQL-15 数据库,需要修改 postgresql.conf及 pg_hba.conf 文件的配置 。修改postgresql.conf (/var/lib/pgsql/15/data/)
#listen_addresses = 'localhost'
将注释符号“#”去掉,并将其更改为:
listen_addresses = '*'
修改pg_hba.conf
该文件位于 PostgreSQL 的数据目录下(通常是
/var/lib/pgsql/15/data/pg_hba.conf 或者 /etc/postgresql/<version>/mAIn/pg_hba.conf) 。

  • 打开 pg_hba.conf 文件:
sudo vi /var/lib/pgsql/15/data/pg_hba.conf
  • 添加
# IPv4 local connections:
host all all 10.168.1.0/24 tRust
  • 保存文件并重新加载 PostgreSQL 配置:
sudo systemctl restart postgresql-15.service
  • 如果还是不能链接确保您已经配置了适当的防火墙规则,允许 PostgreSQL 的5432端口
sudo systemctl reload postgresql-15.service
说明:在 PostgreSQL 中,有几种不同的身份验证方法可供选择 , 其中包括 trust、peer 和 ident 。trust:使用该方法时,用户可以无需密码直接访问数据库 。这是最不安全的身份验证方法,因为任何知道连接信息的人都可以登录到数据库 。因此,在生产环境中不建议使用 trust 身份验证方法 。peer:该方法适用于本地连接 。当操作系统用户名与数据库角色名称匹配时,用户可以无需输入密码访问数据库 。这意味着只有具有相同用户名的本地用户才能进行无密码访问 。ident:该方法也适用于本地连接,并要求通过 UNIX 文件系统中的标识文件(通常是 /etc/passwd)进行验证 。当操作系统用户名与数据库角色名称匹配且请求连接的主机地址与数据库服务器主机地址匹配时,用户可以无需输入密码访问数据库 。但是,请注意,ident 方法在网络连接中并不安全,因此不建议在生产环境中使用 。总结起来 , 如果希望在特定 IP 范围内允许无密码访问,可以使用 trust 身份验证方法 。对于本地连接 , 可以考虑使用 peer 或 ident 方法参考:
https://legacy-docs.timescale.com/v1.7/getting-started/installation/rhel-centos/installation-yum
https://legacy-docs.timescale.com/v1.7/getting-started/setup
https://packagecloud.io/constellio/constellio-updates/packages/el/7/libzstd-1.4.5-3.el7.x86_64.rpm
https://packagecloud.io/trifacta/dependencies/packages/el/7/postgresql12-server-12.5-1PGDG.rhel7.x86_64.rpm?page=5
SElinux策略限制:setenforce 0使?.NETstat命令列出所有正在监听的端口和相应的服务 。netstat -tuln | grep LISTEN使用ss命令可以提供更详细的连接状态信息 。ss -tuln | grep LISTEN使用lsof命令会显示与指定端口关联的进程信息 。lsof -i :<port>使用firewall-cmd命令(仅当使用Firewalld防火墙时):firewall-cmd --list-ports该命令将显示防火墙中允许通过的端口列表 。客户端机器用 telnet PostgreSQL-IP 5432 命令查看端口情况




推荐阅读