近日,须要用到postgresql数据库。sql
我搭建的环境为:shell
azure平台,操做系统为azure平台自带的openlogic centos7.0。数据库
搭建过程:
centos
1,使用系统自带postgresql包。若是仅仅搭建postgresql数据库,仅仅安装postgresql server便可。bash
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,须要设置它的密码。(该步骤可选)app
4,切换到postgres用户,设置数据库用户postgres密码tcp
#su postgres -bash-3.2$psql -U postgres postgres=#alter user postgres with password 'new password'; postgres=#\q
5,配置postgresql,使其能够远程链接post
下面两个文件默认目录为/var/lib/pgsql/data --配置postgresql.conf文件 修改成 listen_addresses = '*' --配置pg_hba.conf 添加 host all all 222.137.xxx.xxx/24 md5 分别为:host类型,数据库,用户,容许远程链接的ip地址,访问方法
6,开启防火墙端口5432ui
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