linux 下安装 postgresql-9.3.1.tar.gz

一、 环境

centos6.0 minimal

postgresql-9.3.1.tar.gz

二、准备工作

  • 1将虚拟机网卡使用NAT模式,方便上网
  • 2关闭防火墙,可以查看02.centos常用操作.md

三、先安装 make, gcc ,gcc-c++,readline-devel ,zlib-devel 。如果已安装,可以忽略

这些都是依赖。
[root@linhp local]# yum -y install gcc [root@linhp local]# yum -y install gcc-c++ [root@linhp local]# yum -y install readline-devel [root@linhp local]# yum -y install zlib-devel [root@linhp postgresql-9.3.1]# yum -y install make

四、开始安装

4.1 解压 tar -zvxf postgresql-9.3.1.tar.gz

我的postgresql-9.3.1.tar.gz 安装包放在 /usr/local 下

[root@linhp local]# pwd
/usr/local
[root@linhp local]# tar -zvxf postgresql-9.3.1.tar.gz
...解压过程
[root@linhp local]# cd postgresql-9.3.1
[root@linhp postgresql-9.3.1]#

4.2 创建linux用户及密码

我的密码设置为123456

[root@linhp postgresql-9.3.1]# adduser postgres
[root@linhp postgresql-9.3.1]# passwd postgres
Changing password for user postgres.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@linhp postgresql-9.3.1]#

4.3 开始安装

[root@linhp postgresql-9.3.1]# pwd
/usr/local/postgresql-9.3.1
// 配置
[root@linhp postgresql-9.3.1]# ./configure --prefix=/usr/local/postgresql
// 编译
[root@linhp postgresql-9.3.1]# make
//安装
[root@linhp postgresql-9.3.1]# make install

4.4 配置环境变量

在环境变量 /etc/profile 最后加入

PATH=$PATH:/usr/local/postgresql/bin

[root@linhp postgresql]# cd /usr/local/postgresql
[root@linhp postgresql]# ls
bin include lib share
[root@linhp postgresql]# vi /etc/profile
在文件最后加入:PATH=$PATH:/usr/local/postgresql/bin 然后刷新环境变量,即时生效
[root@linhp postgresql]# source /etc/profile
输出环境变量,查看是否设置成功
[root@linhp postgresql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/java/jdk1.8.0_91/bin:/opt/java/jdk1.8.0_91/jre/bin:/root/bin:/opt/java/jdk1.8.0_91/bin:/opt/java/jdk1.8.0_91/jre/bin:/usr/local/postgresql/bin

4.5 初始化数据库

[root@linhp postgresql]# pwd
/usr/local/postgresql
[root@linhp postgresql]# mkdir data
[root@linhp postgresql]# ls
bin data include lib share
[root@linhp postgresql]# chown postgres:postgres /usr/local/postgresql/data/
[root@linhp postgresql]# su postgres
[postgres@linhp postgresql]$ /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/```

4.6 复制并修改配置文件(修改存放数据目录)

切换到root
复制安装目录下的linux文件到/etc/init.d/中,并将linux名称重命名为postgresql
[root@linhp postgresql-9.3.1]# cp /usr/local/postgresql-9.3.1/contrib/start-scripts/linux /etc/init.d/postgresql
编辑复制出来的文件,修改下图中的位置即可
[root@linhp postgresql-9.3.1]# vi /etc/init.d/postgresql

[root@linhp postgresql-9.3.1]# chmod +x /etc/init.d/postgresql

4.7 启动数据库,和设置开机自启

[root@linhp postgresql-9.3.1]# /etc/init.d/postgresql start
Starting PostgreSQL: ok
[root@linhp postgresql-9.3.1]# chkconfig postgresql on
[root@linhp postgresql-9.3.1]#

4.8 创建数据库操作的历史文件

创建文件,并授予postgres权限

[root@linhp postgresql-9.3.1]# touch /usr/local/postgresql/.pgsql_history
[root@linhp postgresql-9.3.1]# chown postgres:postgres /usr/local/postgresql/.pgsql_history
[root@linhp postgresql-9.3.1]#

4.9 测试数据库是否创建成功,并且连接数据库

使用 \q 即可退出数据库连接

[root@linhp postgresql-9.3.1]# su postgres
[postgres@linhp postgresql-9.3.1]$ createdb test
[postgres@linhp postgresql-9.3.1]$ psql test
psql (9.3.1)
Type "help" for help. test=# \q
[postgres@linhp postgresql-9.3.1]$

到此,数据库已经安装成功。

五、修改数据库外网访问

Linux 修改PostgreSQL外部访问白名单

先关闭防火墙,或者开放5432端口

主要修改两个配置文件

[root@linhp postgresql-9.3.1]# find / -name pg_hba.conf
[root@linhp postgresql-9.3.1]# find / -name postgresql.conf

5.1 先关闭数据库服务

关闭数据库服务
[postgres@linhp postgresql-9.3.1]$ su
Password:
[root@linhp postgresql-9.3.1]# /etc/init.d/postgresql stop
Stopping PostgreSQL: ok
[root@linhp postgresql-9.3.1]#

5.2 修改pg_hba.conf

将默认的

host all all 127.0.0.1/32 trust

修改为

host all all 192.168.1.1/32 trust #IP全匹配

host all all 192.168.1.1/24 trust #IP匹配前三段

host all all 0.0.0.0/0 trust #全部允许

5.3修改postgresql.conf

listen_addresses 默认是注释掉的,打开即可

修改默认的

listen_addresses = 'localhost'

listen_addresses = '*'

如果需要修改端口,可以修改 listen_addresses下一行

5.4 重启postgresql服务

/etc/init.d/postgresql start

5.5 测试本地连接 ( 这里我修改了端口为5444)

[postgres@linhp postgresql-9.3.1]$ psql -h 127.0.0.1 -d postgres -U postgres -p 5444psql
psql (9.3.1)
Type "help" for help. postgres=#

linux(centos6) 下安装 postgresql-9.3.1.tar.gz的更多相关文章

  1. Linux下安装解压版(tar.gz)MySQL5.7

            最近尝试在Linux中安装了解压版MySQL,期间查阅了许多博客.很多博客看得我很懵逼,因此记录下自己的安装过程,方便后续查阅.         环境说明:CentOs7.2 一.清理 ...

  2. 如何在Ubuntu下安装”.deb“、”.bin“、”.tar.gz“、”.tar.bz2“格式的软件包!

    今天在Ubuntu11.10中安装Google chrome浏览器是遇到了问题,下载好的“.deb”格式的安装文件google-chrome-stable.deb双击后或者右键快捷菜单选择 Synap ...

  3. liunx下安装mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

    1.解压准备一个赶紧的环境,然后安装mysql. 2.cd到/usr/local/目录下,修改文件名为mysql 修改完目录名以后我们cd到mysql下,建立一个data目录命令:cd mysql/ ...

  4. centos6.5安装jdk(解压tar.gz)

    0.说明 下载jdk文件包jdk-7u79-linux-x64.tar.gz. 1.环境清理(系统自带的OpenJDK) 1.1 查看OpenJDK的安装包 $ rpm -qa |grep java ...

  5. Java入门——在Linux环境下安装JDK并配置环境变量

    Java入门——在Linux环境下安装JDK并配置环境变量 摘要:本文主要说明在Linux环境下JDK的安装,以及安装完成之后环境变量的配置. 使用已下载的压缩包进行安装 下载并解压 在Java的官网 ...

  6. Linux下安装PostgreSQL 转载linux社区

    Linux下安装PostgreSQL [日期:2016-12-25] 来源:Linux社区  作者:xiaojian [字体:大 中 小]   在Linux下安装PostgreSQL有二进制格式安装和 ...

  7. CentOS 6.9下安装PostgreSQL

    操作系统:CentOS6.9_x64 PostgreSQL官方网址: https://www.postgresql.org/ 安装数据库 使用如下命令: yum install postgresql- ...

  8. centos6下安装dedecms

    几经波折,终于安装成功!!! 一.centos6下安装WDCP 1.连接linux 在百度直接搜索下载xshell,通过ssh连接 2.安装wdcp 下载安装wget http://dl.wdlinu ...

  9. linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)

     linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...

随机推荐

  1. pandas 入门(2)

    from pandas import Series, DataFrame, Index import numpy as np from numpy import nan as NA obj = Ser ...

  2. ARM汇编1

    一. 指令和伪指令 1.1. 指令 a. (汇编)指令是CPU机器指令的助记符,经过编译后会得到一串10组成的机器码,可以由CPU读取执行. 1.2. 伪指令 b. (汇编)伪指令本质上不是指令(只是 ...

  3. AcWing 802. 区间和

    (https://www.acwing.com/problem/content/804/) 假定有一个无限长的数轴,数轴上每个坐标上的数都是0. 现在,我们首先进行 n 次操作,每次操作将某一位置x上 ...

  4. HTML+CSS ,原型

    此图是别人所作

  5. 【CF321E】+【bzoj5311】贞鱼

    决策单调性 + WQS二分 我们首先列出转移式: \(f[i]=Min(f[j]+Sum[j+1 , i])\) 首先我们考虑如果让一段区间的小鱼在一起的代价怎么预处理,我们可以对于一个上三角矩阵求个 ...

  6. 问题 C: 序列交换

    问题 C: 序列交换 时间限制: 1 Sec  内存限制: 128 MB提交: 914  解决: 48[提交] [状态] [命题人:jsu_admin] 题目描述 给一个 1 到 n 的排列,每次可以 ...

  7. 问题 I: 夫子云游

    问题 I: 夫子云游 时间限制: 1 Sec  内存限制: 128 MB提交: 319  解决: 219[提交] [状态] [命题人:jsu_admin] 题目描述 改编自猫腻所著的同名小说<将 ...

  8. centos解决Could not find a version that satisfies the requirement pip3 (from versions: none)及No matching distribution found for pip3问题

    python环境:python 3.8 报错信息: WARNING: pip is configured with locations that require TLS/SSL, however th ...

  9. Spring boot集成Swagger,并配置多个扫描路径

    Spring boot集成Swagger,并配置多个扫描路径 1:认识Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目 ...

  10. StringBuffer 和 StringBuilder 总结

    StringBuffer 和 StringBuilder 介绍 大多数情况下, StringBuffer 的速度要比 String 快: StringBuilder 要比StringBuffer快:S ...