您的位置:首页 > 数据库 > SQL

azure linux虚拟机openlogic_centos7.0搭建postgresql数据库

2014-11-02 12:31 537 查看
近日,需要用到postgresql数据库。

我搭建的环境为:

azure平台,操作系统为azure平台自带的openlogic centos7.0。

搭建过程:

1,使用系统自带postgresql包。如果仅仅搭建postgresql数据库,仅仅安装postgresql server即可。

sudo yum install postgresql-server postgresql

2,安装完毕后,启动数据库,使用root权限。

--首先需要初始化数据库
postgresql-setup initdb
--设在开机自动启动
systemctl enable postgresql.service
--启动数据库
systemctl start postgresql.service

3,在安装postgresql server包时,会创建1个postgres 用户,该用户的uid 和gid 都是26,如果想使用非root用户su到postgres,需要设置它的密码。(该步骤可选)

4,切换到postgres用户,设置数据库用户postgres密码

#su  postgres
-bash-3.2$psql -U postgres
postgres=#alter user postgres with password 'new password';
postgres=#\q

5,配置postgresql,使其可以远程连接

下面两个文件默认目录为/var/lib/pgsql/data
--配置postgresql.conf文件
修改为
listen_addresses = '*'
--配置pg_hba.conf
添加
host    all             all             222.137.xxx.xxx/24              md5
分别为:host类型,数据库,用户,允许远程连接的ip地址,访问方法

6,开启防火墙端口5432

firewall-cmd --permanent --add-port=5432/tcp
systemctl restart firewalld

7,azure管理平台开启5432端口

8,现在,就可以使用客户端连接postgresql数据库服务器了。

user@host:~$ psql -h dns-name.chinacloudapp.cn -U postgres -W
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  azure postgresql centos7.0