GVKun编程网logo

CentOS搭建内网离线yum仓库(以postgresql安装为例)(centos 离线yum源)

12

如果您想了解CentOS搭建内网离线yum仓库的相关知识,那么本文是一篇不可错过的文章,我们将对以postgresql安装为例进行全面详尽的解释,并且为您提供关于12.CentOS7下PostgreS

如果您想了解CentOS搭建内网离线yum仓库的相关知识,那么本文是一篇不可错过的文章,我们将对以postgresql安装为例进行全面详尽的解释,并且为您提供关于12.CentOS7下PostgreSQL安装过程、CentOS 6.3环境下yum安装PostgreSQL 9.3、CentOS 6.6通过yum 安装PostgreSQL 9.4、CentOS 6.9 下安装 PostgreSQL的有价值的信息。

本文目录一览:

CentOS搭建内网离线yum仓库(以postgresql安装为例)(centos 离线yum源)

CentOS搭建内网离线yum仓库(以postgresql安装为例)(centos 离线yum源)

内网yum仓库服务端配置

192.168.126.146 Web服务端主机,已安装有Nginx

  • 下载离线rpm包,参见Postgresql10离线安装方法

  • 创建repodata目录

[[email protected] html]# createrepo -pdo postgresql/x86_64/ postgresql/x86_64/
  • 将下载完成的rpm包存放到到repodata工作目录

  • 更新yum源,每次有新增的rpm包都需要执行更新

[[email protected] html]# createrepo --update /usr/share/Nginx/html/postgresql/x86_64/
  • 最终服务端目录如下所示,可能还需要添加相关依赖包,此处不作赘述,方法类似
[[email protected] html]# tree postgresql/
postgresql/
└── x86_64
    ├── pgdg-redhat-repo-42.0-4.noarch.rpm
    ├── pgdg-redhat-repo-latest.noarch.rpm
    └── repodata
        ├── 445ee0d2e31a019d6e1decf9485ef9a611c814c811c986812ccea999c4564872-primary.sqlite.bz2
        ├── 627e914a7e1d2dcad2bdaa75edd9730c2e4c0d2552a8ba400b0e21df5ce220db-other.xml.gz
        ├── 72d106452bea9d803f61c44ec8b0c06cc76e0abf1140b80002745330d4b1048b-other.sqlite.bz2
        ├── 86e85d2f38c54099bc474ca2567e49e8e3957659c9c776d6ccebd9cd64d90ae8-filelists.xml.gz
        ├── 974bc8888a0708d6bbfcd9404b21fffc256b11e77f40e6d2ab547673db05863d-primary.xml.gz
        ├── f2ad55ae551c06f1705eb388c105420f46306346ca90aee51fdbe79a2a853496-filelists.sqlite.bz2
        └── repomd.xml

2 directories,9 files

客户端配置

  • 192.168.126.145 客户端主机
  • 编写客户端.repo文件,如下
[[email protected] yum.repos.d]# cat test.repo 
[base]
name=base
baseurl=http://192.168.126.146/base
enable=1
gpgcheck=0

[upodates]
name=updates
baseurl=http://192.168.126.146/updates
enable=1  
gpgcheck=0

[test]
name=test
baseurl=http://192.168.126.146/test
enable=1  
gpgcheck=0
  • 重建缓存,即可
[[email protected] yum.repos.d]# yum clean all && yum makecache

参考链接

CentOS 7 yum 安装 Nginx
搭建私有YUM仓库_及_内网镜像站
centos7自建yum源 安装rpm
创建局域网内的离线 YUM 仓库
搭建本地离线yum仓库
RPM包制作及yum仓库搭建

12.CentOS7下PostgreSQL安装过程

12.CentOS7下PostgreSQL安装过程

CentOS7下Postgresql安装过程

装包

sudo yum install postgresql-server postgresql-contrib

说明:

  • 这种方式直接明了,其他方法也可以参考官网的安装介绍。centos是红帽系的。
  • postgresql主要有以下几个包:
    • postgresql-client:libraries and client binaries
    • postgresql-server:core database server
    • postgresql-contrib:additional supplied modules
    • postgresql-devel:libraries and headers for C language development
    • pgadmin3:pgAdmin III graphical administration utility
  • 作为服务器,只用装postgresql-server和postgresql-contrib

初始化

sudo postgresql-setup initdb

说明:

  • 根据红帽系的策略,Postgresql安装完成后,相应的服务不会自动启动,数据库也不会自动初始化,初始化操作需要手动进行。

修改pg_hba.conf

sudo vim /var/lib/pgsql/data/pg_hba.conf

插入一行:host all all 0.0.0.0/0 md5

说明:

  • 配置文件目录可能带版本号,比如pgsql/9.5/data这种,自己找一下。
  • hba means host-based authentication
  • 默认情况下,Postgresql不允许password authentication,不允许非localhost的主机,不允许远程登录。(所谓默认情况就是Postgresql刚装好时候conf文件里写的情况。)
  • 插入的那一行,格式为CONNECTIONTYPE DATABASE USER ADDRESS METHDO
  • 字段含义、各字段可选值、配置方式直接参考conf文件的注释。
  • 提一句,ADDRESS那里自己配一下,不要太放开了,md5即用密码认证身份登录。

修改postgresql.conf

sudo vim /var/lib/pgsql/data/postgresql.conf

改一行:listen_addresses = '*'

说明:

  • postgresql.conf文件中涉及诸如:最大连接数、监听地址,监听端口、日志、内存、硬盘等等各种设置。文件注释详细,自己按需修改,用不到的先不做了解。
  • 监听地址原值为localhost,这时只能本机访问,改成*或0.0.0.0或逗号分隔字符串都行。
  • 很多值是change requires restart,需要重启postgresql-9.5服务(要带版本号)。

重启postgresql服务

systemctl restart postgresql-9.5.service

或者sudo service postgresql-9.5 restart

说明:

  • 重启服务使之前修改的配置生效。

注意事项

  • 安装目录/var/lib/pgsql及目录下文件或文件夹的可读、可写、可操作统统只开放给用户postgres
  • 文件不能操作时,请sudo su - postgres切换到postgres用户进行操作,千万不要改动默认的文件权限,否则会导致postgresql服务无法启动。
  • 在终端输入psql命令时,常常会遇到下面这个错。这个错有两个解决方式:
    • 重启postgresql服务。
    • 删掉/usr/local/var/postgres/postmaster.pid文件。

      psql: Could not connect to server: No such file or directory
          Is the server running locally and accepting
          connections on Unix domain socket "/tmp/.s.PGsql.5432"?

  • postgres的默认密码为空,上面弄好以后记得改密码。
    • sudo su - postgres
    • psql
    • ALTER USER postgres PASSWORD '123456';

CentOS 6.3环境下yum安装PostgreSQL 9.3

CentOS 6.3环境下yum安装PostgreSQL 9.3

PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系

postgresql 是一种非常复杂的对象-关系型数据库管理系统(ordbms),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统。有些特性甚至连商业数据库都不具备。这个起源于伯克利(bsd)的数据库研究计划目前已经衍生成一项国际开发项目,并且有非常广泛的用户。

下面记录CentOS 6.3环境下yum安装Postgres 9.3的简要过程。

------------------------------------华丽丽的分割线------------------------------------

PostgreSQL缓存详述

Windows平台编译 PostgreSQL

Ubuntu下LAPP(Linux+Apache+PostgreSQL+PHP)环境的配置与安装

Ubuntu上的phppgAdmin安装及配置

CentOS平台下安装PostgreSQL9.3

PostgreSQL配置Streaming Replication集群

------------------------------------华丽丽的分割线------------------------------------

1.查看已安装的包

# rpm -qa|grep postgres

如果已经存在

//卸载

 # rpm -e postgresql92-server-9.2.4-1PGDG.rhel6.i686

# rpm -e postgresql92-contrib-9.2.4-1PGDG.rhel6.i686

# rpm -e postgresql92-9.2.4-1PGDG.rhel6.i686

# rpm -e postgresql92-libs-9.2.4-1PGDG.rhel6.i686

2. yum 安装

yum install
 yum install postgresql93-server postgresql93-contrib

//初始化
 service postgresql-9.3 initdb

开启
 service postgresql-9.3 start或者

/etc/init.d/postgresql-9.3 start

查看安装结果
 
rpm -aq| grep postgres

可以看到
 
[root@i-87-575-VM vmuser]# rpm -aq| grep postgres
 postgresql93-libs-9.3.4-1PGDG.rhel6.x86_64
 postgresql93-contrib-9.3.4-1PGDG.rhel6.x86_64
 postgresql93-9.3.4-1PGDG.rhel6.x86_64
 postgresql93-server-9.3.4-1PGDG.rhel6.x86_64

说明已经安装好了。

3.测试
  [root@i-87-575-VM vmuser]# su - postgres
 -bash-4.1$ psql -l
 默认密码为空,我们需要修改为指定的密码,这里设定为’postgres’。
 -bash-4.1$ psql
 
PostgreSQL 数据库默认会创建一个postgres的数据库用户作为数据库的管理员,,默认密码为空,我们需要修改为指定的密码,这里设定为’postgres’。
 # ALTER USER postgres WITH PASSWORD ''postgres'';
 # select * from pg_shadow ;

更加详细的信息可以参考

本文永久更新链接地址:

linux

CentOS 6.6通过yum 安装PostgreSQL 9.4

CentOS 6.6通过yum 安装PostgreSQL 9.4

最近再写python程序,需要用到postgresql,所以要安装postgresql数据库。

下面是安装步骤:

一、在/etc/yum.repos.d/CentOS-Base.repo 中的[base],[updates]中都增加:exclude=postgresql*


二、引入 Postgresql 9.4 Repository 官方的安装源

网址是:http://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-6.6-x86_64/pgdg-centos94-9.4-2.noarch.rpm

如果这个网址显示404 Not Found,可以进入到http://download.postgresql.org/pub/repos/yum/9.4/redhat 目录之后,一步一步点进去,找到你要下载的那个rpm包的链接。

rpm -Uvh http://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-6.6-x86_64/pgdg-centos94-9.4-2.noarch.rpm

三、安装
yum install postgresql94 postgresql94-server postgresql94-contrib

四、初始化Postgresql数据库
service postgresql-9.4 initdb 

五、设置开机自启动
service postgresql-9.4 start
chkconfig postgresql-9.4 on

六、修改监听地址、端口

/var/lib/pgsql/9.4/data/postgresql.conf 中 把注释符号去掉,显示如下:

listen_address='*'
port=5432

七、增加操作系统用户
[root@wc1 ~]# adduser pgdbuser

八、创建postgresql数据库中的用户

在安装完postgresql数据库之后,会有一个默认的用户postgres,切换到postgres用户,然后执行psql命令,连接postgresql,然后再创建pgdbuser用户,最后退出

[root@wc1 ~]# su - postgres
-bash-4.1$ psql
psql (9.4.11)
Type "help" for help.
                                        ^
postgres=# create user pgdbuser  with superuser login password 'pgdbuser';
CREATE ROLE
postgres=# \q

九、修改/var/lib/pgsql/9.4/data/pg_hba.conf文件如下:

其中ident是linux系统下postgresql默认的local认证方式,通过操作系统用户映射的数据库用户,不需要输入密码,就可以登录。

而md5,不需要在操作系统层建立对应的同名的用户。

# TYPE  DATABASE        USER            ADDRESS                 METHOD

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

修改之后要重启服务:

[root@wc1 Desktop]# service postgresql-9.4 restart
Stopping postgresql-9.4 service:                           [  OK  ]
Starting postgresql-9.4 service:                           [  OK  ]

十、登录postgresql

由于都是需要密码验证登录,所以当前os用户为root,需要指定登录的数据库、用户,然后按照提示输入密码后登陆。

接下来,创建数据库,显示当前数据库,切换到新建的库,创建表,插入数据,查询数据。

[root@wc1 Desktop]# psql -d postgres -U pgdbuser
Password for user pgdbuser: 
psql (9.4.11)
Type "help" for help.

postgres=# create database test;
ERROR:  database "test" already exists
postgres=# create database xxx;
CREATE DATABASE
postgres=# select current_database();
 current_database 
------------------
 postgres
(1 row)

postgres=# \c xxx
You are Now connected to database "xxx" as user "pgdbuser".
xxx=# create table tb(id int);
CREATE TABLE
xxx=# insert into tb values(1);
INSERT 0 1
xxx=# select * from tb;
 id 
----
  1
(1 row)

xxx=# 

如果把修改/var/lib/pgsql/9.4/data/pg_hba.conf,把第一个md5改成ident,那么登录时候,需要切换到上面创建的操作系统用户:pgdbuser,然后就可以直接登录。
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     ident
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5            
# IPv6 local connections:
host    all             all             ::1/128                 md5
重启服务。
登录:
[root@wc1 Desktop]# psql -d postgres -U pgdbuser
psql: FATAL:  Peer authentication Failed for user "pgdbuser"
[root@wc1 Desktop]# su - pgdbuser
[pgdbuser@wc1 ~]$ psql -d postgres
psql (9.4.11)
Type "help" for help.

postgres=# \c xxx
You are Now connected to database "xxx" as user "pgdbuser".
xxx=# select * from tb;
 id 
----
  1
(1 row)

xxx=# 

CentOS 6.9 下安装 PostgreSQL

CentOS 6.9 下安装 PostgreSQL

操作系统:CentOS6.9_x64

PostgreSQL 官方网址: https://www.postgresql.org/

安装数据库

使用如下命令:

yum install postgresql-server -y

设置开机启动:

chkconfig postgresql on

初始化数据库

service postgresql initdb 

启动数据库:

service postgresql start

安装后,默认生成一个名为 postgres 的数据库和一个名为 postgres 的数据库用户。这里需要注意的是,同时还生成了一个名为 postgres 的 Linux 系统用户。

CentOS6.9_x64 默认安装的是 8.4 版本的 psql,如果需要其它版本,可以参考官方文档:

https://www.postgresql.org/download/linux/redhat/

这里附上 CentOS6.9_x64 下的安装脚本 :

yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
yum install postgresql96
yum install postgresql96-server

service postgresql-9.6 initdb
chkconfig postgresql-9.6 on
service postgresql-9.6 start

配置数据库

添加新用户和新数据库

adduser psqladmin

su - postgres

psql CREATE USER useradmin WITH PASSWORD
''123456''; CREATE DATABASE testdb OWNER useradmin; GRANT ALL PRIVILEGES ON DATABASE testdb to useradmin;

修改 postgres 的数据库密码

\password postgres

开启远程访问:

cd /var/lib/pgsql/data/

postgresql 默认情况下,远程访问不能成功,如果需要允许远程访问,需要修改两个配置文件,说明如下:

  1. postgresql.conf

将该文件中的 listen_addresses 项值设定为 “*”,在 9.0 Windows 版中,该项配置已经是 “*” 无需修改。

  1. pg_hba.conf

在该配置文件的 host all all 127.0.0.1/32 md5 行下添加以下配置,或者直接将这一行修改为以下配置

host all all 0.0.0.0/0 md5

如果不希望允许所有 IP 远程访问,则可以将上述配置项中的 0.0.0.0 设定为特定的 IP 值。

使用数据库

sql 语句示例代码

使用 public schema:

create table students (
    id bigserial primary key,
    name varchar(20) NOT NULL
);

insert into students values (1,''stu1'');
select * from students ;
drop table students ;

使用自定义 schema :

create schema my_schema;

create table my_schema.students (
    id bigserial primary key,
    name varchar(20) NOT NULL
);

insert into my_schema.students values (1,''stu1'');

select * from my_schema.students ;

python 访问示例代码

https://github.com/mike-zhang/pyExamples/blob/master/databaseRelate/psqlOpt/psqlTest1.py

centos6.9 自带的 python 安装 pyscopg2 库 : yum install python-psycopg2

好,就这些了,希望对你有帮助。

本文 github 地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2017/20170711_centos6.9 下安装 PostgreSQL.rst

欢迎补充

sql 语句示例代码

使用 public schema:

今天关于CentOS搭建内网离线yum仓库以postgresql安装为例的介绍到此结束,谢谢您的阅读,有关12.CentOS7下PostgreSQL安装过程、CentOS 6.3环境下yum安装PostgreSQL 9.3、CentOS 6.6通过yum 安装PostgreSQL 9.4、CentOS 6.9 下安装 PostgreSQL等更多相关知识的信息可以在本站进行查询。

本文标签: