如何在CentOS上安装PostgreSQL
首先添加官方PostgreSQL仓库,然后禁用系统自带模块并安装PostgreSQL服务器与客户端,初始化数据库后启动服务并设置开机自启,接着配置认证方式与网络访问权限,最后重启服务使配置生效。
To install PostgreSQL on CentOS, follow the steps below depending on your CentOS version. This guide covers CentOS 7, 8, and 9, using the official PostgreSQL repository for the latest versions.
Add the PostgreSQL Repository
PostgreSQL is available in the default CentOS repositories, but the version may be outdated. To get the latest version, add the official PostgreSQL YUM repository.
- Visit PostgreSQL YUM Repository page.
- Select your CentOS version and desired PostgreSQL version (e.g., PostgreSQL 15 or 16).
- Run the provided command. For example, for PostgreSQL 16 on CentOS 8/9:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Note: For CentOS 7, replace EL-8 with EL-7.Install PostgreSQL Server and Client
After adding the repository, disable the built-in PostgreSQL module (especially on CentOS 8/9) to avoid conflicts:
sudo dnf -qy module disable postgresql
Now install PostgreSQL:
sudo dnf install -y postgresql16-server postgresql16
Replace 16 with your desired version number if different.Initialize and Start PostgreSQL
Before starting the service, initialize the database cluster:
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
Start and enable PostgreSQL to run at boot:
sudo systemctl enable postgresql-16
sudo systemctl start postgresql-16
Configure Access and Security
By default, PostgreSQL uses ident or peer authentication. To allow password access:
- Switch to the postgres user: sudo -i -u postgres
- Access the PostgreSQL prompt: psql
- Set a password for the postgres user:
ALTER USER postgres PASSWORD 'your_password';
Exit the prompt: \q
To allow remote connections, edit the configuration files:- postgresql.conf: Located at /var/lib/pgsql/16/data/postgresql.conf. Update listen_addresses to '*' or specific IPs.
- pg_hba.conf: Located at /var/lib/pgsql/16/data/pg_hba.conf. Add host-based access rules for your network.
基本上就这些。PostgreSQL 已安装并运行,可根据应用需求进一步配置。防火墙和 SELinux 设置可能需要额外调整,尤其是开放 5432 端口时。
以上是如何在CentOS上安装PostgreSQL的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undress AI Tool
免费脱衣服图片

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Stock Market GPT
人工智能驱动投资研究,做出更明智的决策

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

要更新CentOS系统上的所有软件包,可使用yum(CentOS7)或dnf(CentOS8及以上),具体步骤如下:1.检查可用更新,使用“sudoyumcheck-update”或“sudodnfcheck-update”列出待更新的包;2.执行全系统更新,分别用“sudoyumupdate-y”或“sudodnfupgrade--allowerasing”命令进行升级,其中-y参数自动确认操作,--allowerasing允许删除冲突包;3.如更新涉及新内核,则需重启系统生效,可用“unam

更新CentOS内核的关键在于使用ELRepo仓库并正确设置启动项。1.首先运行uname-r查看当前内核版本;2.安装ELRepo仓库并导入密钥;3.使用yum安装kernel-lt(长期支持版)或kernel-ml(主线版);4.安装完成后通过awk命令查看可用内核并使用grub2-set-default设置默认启动项;5.生成新的GRUB配置文件grub2-mkconfig-o/boot/grub2/grub.cfg;6.最后重启系统并再次运行uname-r确认内核版本是否生效。整个过程需

要配置PHP环境以支持MongoDB,核心步骤是安装并启用MongoDB的PHP驱动,使PHP应用能够与MongoDB数据库通信。1.安装MongoDBPHP驱动,推荐使用PECL安装,若无PECL则需先安装PHP开发包及相关编译工具;2.编辑php.ini文件,添加extension=mongodb.so(或.dll)以启用扩展;3.重启Web服务器或PHP-FPM服务使配置生效;4.通过phpinfo()或php-m验证扩展是否加载成功。常见问题包括PECL命令缺失、编译错误、php.ini

Identifythenewdiskusinglsblkorfdisk-ltolocatethecorrectdevicelike/dev/sdb.2.Optionallypartitionthediskwithfdisk/dev/sdb,createaprimarypartitionusingdefaultsettings,andwritechangeswithw,thenrunpartprobetoupdatethekernel.3.Createafilesystemusingmkfs-tx

安装和配置fail2ban在CentOS上并不复杂,主要包括以下步骤:1.使用yum安装fail2ban;2.手动启用并启动服务;3.创建jail.local文件进行自定义配置;4.设置SSH防御规则,包括启用sshd、指定封禁时间与重试次数;5.配置firewalld作为动作执行器;6.定期检查封禁IP及日志。Fail2ban通过监控日志检测异常登录行为并自动封禁可疑IP,其核心机制依赖于bantime(封禁时间)、findtime(统计窗口时间)和maxretry(最大失败次数)等关键参数的

卸载旧版本Docker避免冲突,2.安装yum-utils并添加官方Docker仓库,3.安装DockerCE、CLI和containerd,4.启动并启用Docker服务,5.运行hello-world镜像验证安装成功,6.可选配置非root用户运行Docker。

确保系统已加载bonding模块并确认网卡接口可用,使用modprobebonding和lsmod验证;2.创建/etc/sysconfig/network-scripts/ifcfg-bond0配置文件,设置DEVICE、TYPE、BONDING_MASTER、IP参数及BONDING_OPTS=mode=active-backupmiimon=100primary=ens33;3.配置物理网卡ens33和ens34的ifcfg文件,设置MASTER=bond0、SLAVE=yes并移除IP配

installcifs-utilSandOptionallySamba-clientusingyumordnf.2.CreateAmountPointLike/mnt/Windows-share.3.ManalymallalyMountlalyMountThewIndowsShareShareShareThareThareThareThareThareThareShareTemount-tcifscommandWithApprepreptions,可优先usissacredentialSfilefileforeforsecurity.4.storecercentienclesentirencilectienclesecentienclesecrecterencesecrecretencecrederlyssecurelyniin
