Ubuntu 12.04.1 LTS + PostgreSQL 9.1

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:

Ubuntu 12.04.1 LTS + PostgreSQL 9.1

MrNeo Chen (netkiller)陈景峰(BG7NYT)


中国广东省深圳市龙华新区民之街道溪山美地
518109
+86 13113668890
+86 755 29812080

版权 © 2011, 2012 http://netkiller.github.com

$Date: 2012-12-06 11:53:11 +0800 (Thu, 06 Dec 2012) $

1. Ubuntu 12.04.1 LTS

安装环境

PostgreSQL 9.1

$ sudo apt-get install postgresql
$ sudo apt-get install postgresql
		

更改postgres管理员用户密码

$ sudo passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
		

然后切换到postgres用户环境

$ su - postgres
Password:
Added user postgres.
		

进入psql客户款, PostgreSQL的psql命令相当于sqlplus,MySQL命令

$ psql
psql (9.1.6)
Type "help" for help.

postgres=#
		

退出\q

postgres=# \q
		

2. PostgreSQL 配置

su 到 postgres 用户

$ su - postgres
Password:
$ pwd
/var/lib/postgresql
$
		

备份配置文件,防止修改过程中损毁

cp /etc/postgresql/9.1/main/postgresql.conf /etc/postgresql/9.1/main/postgresql.conf.original
cp /etc/postgresql/9.1/main/pg_hba.conf /etc/postgresql/9.1/main/pg_hba.conf.original
		

2.1. postgresql.conf

启用tcp/ip连接,去掉下面注释,修改为你需要的IP地址,默认为localhost

listen_addresses = 'localhost'
			

如果有多个网络适配器可以指定 'ip' 或 '*' 任何接口上的IP地址都可能listen.

$ sudo vim /etc/postgresql/9.1/main/postgresql.conf

listen_addresses = '*'
			

2.2. pg_hba.conf

pg_hba.conf配置文件的权限需要注意以下,-rw-r----- 1 postgres postgres 4649 Dec 5 18:00 pg_hba.conf

$ ll /etc/postgresql/9.1/main/
total 52
drwxr-xr-x 2 postgres postgres  4096 Dec  6 09:40 ./
drwxr-xr-x 3 postgres postgres  4096 Dec  5 18:00 ../
-rw-r--r-- 1 postgres postgres   316 Dec  5 18:00 environment
-rw-r--r-- 1 postgres postgres   143 Dec  5 18:00 pg_ctl.conf
-rw-r----- 1 postgres postgres  4649 Dec  5 18:00 pg_hba.conf
-rw-r----- 1 postgres postgres  1636 Dec  5 18:00 pg_ident.conf
-rw-r--r-- 1 postgres postgres 19259 Dec  5 18:00 postgresql.conf
-rw-r--r-- 1 postgres postgres   378 Dec  5 18:00 start.conf
			

pg_hba.conf配置文件负责访问权限控制

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
			
TYPE

local 本地使用unix/socket 方式连接, host 使用tcp/ip socket 方式连接

DATABASE

数据库名.

USER

用户名.

ADDRESS

允许连接的IP地址,可以使用子网掩码.

METHOD

认真加密方式.

下面我们做一个简单测试,首先配置pg_hba。conf文件

$ sudo vi /etc/postgresql/9.1/main/pg_hba.conf
host    *			dba         0.0.0.0/0       md5
host    test		test        0.0.0.0/0       md5
			

运行创建数据,用户 的SQL语句

CREATE ROLE test LOGIN PASSWORD 'test' NOSUPERUSER NOINHERIT NOCREATEDB NOCREATEROLE;

CREATE DATABASE test WITH OWNER = test ENCODING = 'UTF8' TABLESPACE = pg_default;
			

进入psql

$ psql
psql (9.1.6)
Type "help" for help.

postgres=# CREATE ROLE test LOGIN PASSWORD 'test' NOSUPERUSER NOINHERIT NOCREATEDB NOCREATEROLE;
CREATE ROLE
postgres=# CREATE DATABASE test WITH OWNER = test ENCODING = 'UTF8' TABLESPACE = pg_default;
CREATE DATABASE
postgres=# \q
			

使用psql登录

			
$ psql -hlocalhost -Utest test
Password for user test:
psql (9.1.6)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

test=> \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 test      | test     | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)

test=>
			
			

3. 创建dba用户

创建一个远程维护数据库dba用户,具有创建数据库与创建用户的权限

CREATE USER dba PASSWORD 'dba' CREATEDB CREATEUSER;
CREATE ROLE
		

进入psql

$ psql
psql (9.1.6)
Type "help" for help.

postgres=# CREATE USER dba PASSWORD 'dba' CREATEDB CREATEUSER;
CREATE ROLE
postgres=# \q
		

使用psql登录

$ psql -hlocalhost -Udba postgres
Password for user dba:
psql (9.1.6)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

postgres=#
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
2月前
|
Kubernetes Ubuntu 应用服务中间件
在Ubuntu22.04 LTS上搭建Kubernetes集群
在Ubuntu22.04.4上安装Kubernetes v1.28.7,步骤超详细
327 1
在Ubuntu22.04 LTS上搭建Kubernetes集群
|
6月前
|
Ubuntu 关系型数据库 数据库
百度搜索:蓝易云【Ubuntu系统安装 PostgreSQL详细教程。】
现在,你已经成功在Ubuntu系统上安装了PostgreSQL,并创建了一个新的数据库和用户。你可以使用所创建的用户凭据连接到数据库并开始使用。记得根据你的具体需求进行进一步的配置和安全性调整。
251 2
|
Kubernetes 网络协议 Ubuntu
Kubeadm 快速搭建 k8s v1.19.1 集群(Ubuntu Server 20.04 LTS)
安装准备工作安装环境要求:角色 实验环境 生产环境 操作系统 master cpu/内存:2 Core/2G cpu/内存:2 Core/4G linux 内核 4.4+ node cpu/内存:1 Core/2G cpu/内存:4 Core/16G linux 内核 4.4+ 备注 Node:应根据需要运行的容器数量进行配置; Linux 操作系统基于 x86_64 架构的各种 Linux 发行版...
960 2
Kubeadm 快速搭建 k8s v1.19.1 集群(Ubuntu Server 20.04 LTS)
|
3月前
|
监控 Ubuntu
如何在 Ubuntu 22.04 LTS 上安装 Logwatch?
如何在 Ubuntu 22.04 LTS 上安装 Logwatch?
29 0
|
3月前
|
Ubuntu Java 数据库
如何在 Ubuntu 22.04 LTS 上安装和配置 OrientDB?
如何在 Ubuntu 22.04 LTS 上安装和配置 OrientDB?
34 1
如何在 Ubuntu 22.04 LTS 上安装和配置 OrientDB?
|
3月前
|
Ubuntu 编译器 C语言
如何在 Ubuntu 22.04 LTS 上安装 Spack?
【1月更文挑战第8天】
68 0
如何在 Ubuntu 22.04 LTS 上安装 Spack?
|
6月前
|
Ubuntu 数据安全/隐私保护
百度搜索:蓝易云【如何在 Ubuntu 22.04 LTS 上安装分区编辑器 GParted?】
希望这些步骤能够帮助您在Ubuntu 22.04 LTS上安装GParted并顺利使用它进行分区管理。
67 0
|
10月前
|
存储 Ubuntu 安全
在Ubuntu 22.04 LTS Jammy Linux 系统上安装MySQL
在Ubuntu 22.04 LTS Jammy Linux 系统上安装MySQL
1252 0
|
11月前
|
Ubuntu 关系型数据库 PostgreSQL
在ubuntu上安装postgresql 12
登录到postgresql的官方网站,选择相应的版本
257 0
|
11月前
|
Ubuntu 关系型数据库 网络安全
Ubuntu下安装Postgresql
Ubuntu22.04下安装Postgresql14
681 0