使用yum安装postgresql 10 dev

本文详细介绍了如何在CentOS 7 64位系统上安装PostgreSQL 10数据库,包括创建用户、配置YUM存储库、安装PG RPM文件及初始化数据库等步骤。
环境centos 7 64位
数据库:pg10dev
参考网址:
https://yum.postgresql.org/news10snapshot-ready-for-testing.php
yum installation
https://wiki.postgresql.org/wiki/YUM_Installation

创建用户

[root@localhost ~]#useradd postgres

配置你的yum存储库

[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base] 和[updates] 区段之间添加:
exclude=postgresql*

安装pg的rpm文件

[root@localhost ~]# yum localinstall https://download.postgresql.org/pub/repos/yum/testing/10/redhat/rhel-7-x86_64/pgdg-centos10-10-1.noarch.rpm

安装pg数据库
[root@localhost ~]# yum list postgresql*

[root@localhost ~]# yum install postgresql10-server.x86_64
[root@localhost ~]# mkdir postgres /var/lib/pgsql/10/data
初始化数据库
[root@localhost ~]# /usr/pgsql-10/bin/postgresql10-setup initdb
Initializing database ... OK
 

[root@localhost ~]# su - postgres

[postgres@localhost ~]$ /usr/pgsql-10/bin/pg_ctl -D /var/lib/pgsql/10/data start

[postgres@localhost ~]$ /usr/pgsql-10/bin/psql -p 5432
psql (10devel)
输入 "help" 来获取帮助信息.

postgres=#

安装完成!

### 通过 Yum 在线安装数据库的方法 #### 1. 安装 MariaDB 数据库 MariaDB 是 CentOS 7 中默认的数据库管理系统。以下是具体的安装步骤: - 添加 MariaDB 的官方 Yum 源: ```bash vim /etc/yum.repos.d/mariadb.repo ``` 在文件中添加以下内容: ```ini [mariadb] name = MariaDB baseurl = https://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/ gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck=1 ``` - 清除缓存并生成新缓存: ```bash yum clean all yum makecache ``` - 开始安装 MariaDB: ```bash yum install mariadb-server mariadb -y ``` - 启动服务并将服务设置为开机自启: ```bash systemctl start mariadb systemctl enable mariadb ``` 以上过程适用于安装 MariaDB 数据库[^4]。 --- #### 2. 安装 MySQL 数据库 虽然 CentOS 7 默认提供的是 MariaDB,但如果需要安装 MySQL,可以按照以下步骤操作: - 下载并安装 MySQL 的官方 Yum 源: ```bash sudo yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm ``` - 修改 Yum 源配置文件以启用特定版本(例如 MySQL 5.7 或 8.0)。编辑 `/etc/yum.repos.d/mysql-community.repo` 文件,将目标版本下的 `enabled=1` 设置为开启状态。 - 安装 MySQL 社区版服务器: ```bash yum install mysql-community-server -y ``` - 启动 MySQL 并设置为开机自启: ```bash systemctl start mysqld systemctl enable mysqld ``` 注意,在某些情况下可能需要手动清理旧的 MariaDB 软件包以避免冲突[^3]。 --- #### 3. 安装 PostgreSQL 数据库 PostgreSQL 是另一种流行的开源关系型数据库。以下是其安装流程: - 安装 PostgreSQL 的官方 Yum 源: ```bash sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm ``` - 更新本地 Yum 缓存: ```bash yum update -y ``` - 安装 PostgreSQL 服务器及相关工具: ```bash yum install postgresql15-server postgresql15-contrib -y ``` - 初始化数据库集群: ```bash /usr/pgsql-15/bin/postgresql-15-setup initdb ``` - 启动 PostgreSQL 服务并设置为开机自启: ```bash systemctl start postgresql-15 systemctl enable postgresql-15 ``` 此方法支持在线安装最新稳定版本的 PostgreSQL 数据库[^2]。 --- #### 总结 不同的数据库有不同的安装方式,但核心思路一致:先配置对应的 Yum 源,再执行安装命令即可完成部署。对于 CentOS 用户来说,推荐优先考虑 MariaDB 和 PostgreSQL 这两类成熟的解决方案。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值