zoukankan      html  css  js  c++  java
  • postgresql10.5安装

    1.下载源码安装包

    wget https://ftp.postgresql.org/pub/source/v10.5/postgresql-10.5.tar.gz

    2.创建pg的用户主、组

    [root@test2019030517 postgresql-10.5]# useradd postgres

    [root@test2019030517 postgresql-10.5]# groupadd postgres

    [root@test2019030517 postgresql-10.5]# passwd postgres

    3.解压、进入目录

    [root@test2019030517 postgresql-10.5]# tar zxvf postgresql-10.5.tar.gz

    [root@test2019030517 postgresql-10.5]# cd postgresql-10.5

    4.创建postgreSQL的安装目录

    [root@test2019030517 postgresql-10.5]# mkdir /ecapp/postgresql

    5.下载依赖包

    [root@test2019030517 postgresql-10.5]# yum -y install -y readline-devel

    [root@test2019030517 postgresql-10.5]#yum install -y systemtap-sdt-devel.x86_64

    yum install perl-ExtUtils-Embed -y

    yum install zlib zlib-devel -y

    yum install openssl openssl-devel -y

    yum install pam pam-devel -y

    yum install libxml2 libxml2-devel -y

    yum install libxslt libxslt-devel -y

    yum install tcl tcl-devel

    6.预编译#-prefix是指定postgreSQL安装路径

    [root@test2019030517 postgresql-10.5]# ./configure --prefix=/ecapp/postgresql 

    --with-perl --with-tcl --with-python --with-openssl

    7.编译安装

    [root@test2019030517 postgresql-10.5]# make

    [root@test2019030517 postgresql-10.5]# make install

    显示这个说明成功

     PostgreSQl installation complete

    8.安装contrib目录下的一些工具,是第三方组织的一些工具代码,建议安装

    [root@test2019030517 postgresql-10.5]# cd contrib

    [root@test2019030517 contrib]# make && make install

    9.创建相关目录

    ♦数据目录

    [root@test2019030517 contrib]# mkdir -p /ecapp/postgresql/data

    ♦日志目录

    [root@test2019030517 contrib]# mkdir -p /ecapp/postgresql/logs

    赋予postgres用户相关文件夹权限

    chown -R postgres:postgres /ecapp/postgresql

    10.配置环境变量

    [root@test2019030517 postgresql-10.5]# cat /etc/profile.d/pgsql.sh

    export PATH=$PATH:/ecapp/postgresql/bin/

    [root@test2019030517 postgresql-10.5]# source /etc/profile.d/pgsql.sh

    11.启动数据库

    [root@test2019030517 postgresql-10.5]# su postgres

    初始化数据库

    [postgres@test2019030517 postgresql-10.5]$ initdb -D /ecapp/postgresql/data/

    启动服务

    pg_ctl -D /ecapp/postgresql/data -l /ecapp/postgresql/logs/logfile start

    连接数据库

    [postgres@test2019030517 postgresql-10.5]$ psql

    创建数据库

    postgres=# create database test;

    创建表

    postgres=# create table t_user (id integer, name text);

    插入测试数据

    postgres=# insert into t_user values (1,'joke');

    查询数据

    postgres=# select * from t_user;

    退出psql窗口

    postgres-# q

    12.修改监听所有网络以及数据库连接数以及port

    $ vim /usr/local/postgresql/data/postgresql.conf

     60 listen_addresses = '*'          # what IP address(es) to listen on;

     65 max_connections = 100                   # (change requires restart)

    普通用户

    13.修改远程访问

    $ vim /usr/local/postgresql/data/pg_hba.conf

    #在文件的最下方加上下面的这句话

    host    all         all         0.0.0.0/0             trust

    如下

    $ tail -n 6 /usr/local/postgresql/data/pg_hba.conf

    # replication privilege.

    local   replication      all                                         trust

    host    replication     all             127.0.0.1/32          trust

    host    replication     all             ::1/128                 trust

    host    all                all              0.0.0.0/0              trust

    第一列是连接方式,local是通过本地的socket套接字连接,host是通过ip地址连接。

    第二列是目标数据库

    第三列是用户

    第四列是授权ip

    第五列是认证方式

    认证方式共有11种,最常接触的是peeridentpassword

    peer:是指postgresql所在操作系统上的用户登录。peer方式简单来说就是当前系统用户和登录到postgresql的用户名相同,就可以登录。

    Ident:与peer类似,只不过peer只能在postgresql本地进行登录,ident则是可以跨主机使用。

    Password:使用用户(角色)和密码登陆,这里说的角色就是mysql的用户。

    14.防火墙开启端口

    # 切换root用户

    su - root

    # 防火墙 允许5432 端口<br>iptables -I INPUT -p tcp --dport 5432 -j ACCEPT

    15.重启postgreSQL服务

    [root@test2019030517 postgresql-10.5]# su - postgres

    $ pg_ctl -D /ecapp/postgresql/data/ -l /ecapp/postgresql/logs/logfile restart

    停止服务命令

    $ pg_ctl -D /usr/local//postgresql/data/ -l /usr/local/postgresql/logs/logfile stop

    16.设置开机自启动

    切换到root用户

    [postgres@test2019030517 ~]$ su root

    找到解压后源码包里面的一个linux文件

    # chmod a+x /data/postgresql-10.5/contrib/start-scripts/linux

    复制linux文件到/etc/init.d目录下,更名为postgresql

    # cp /data/postgresql-10.5/contrib/start-scripts/linux /etc/init.d/postgresql

    17.修改/etc/init.d/postgresql文件的两个变量

    31 # Installation prefix<br>32 prefix=/usr/local/postgresql

    33

    34 # Data directory

    35 PGDATA="/usr/local/postgresql/data"

    37 # Who to run the postmaster as, usually "postgres".  (NOT "root")

    38 PGUSER=postgres

    18.执行service postgresql start,可以启动PostgreSQL服务

    启动

    [root@database2019030517 postgresql]# service postgresql start

    停止

    [root@database2019030517 postgresql]# service postgresql stop

    查看状态

    [root@database2019030517 postgresql]# service postgresql status

    19.设置postgresql服务开机自启动

    [root@test2019030517 postgres]# chkconfig --add postgresql

    [root@test2019030517 postgres]# chkconfig --level 2345 postgresql on

    [root@test2019030517 postgres]# chkconfig --list

    20.postgresql在原有参数的基础上进行在编译

    pg_config --configure #查看参数

    在原有参数基础上加上新的参数进行预编译./configure

    make && make install

    做之前在测试环境上运行一遍试一下,编译完重启一下就好了

  • 相关阅读:
    关于celery踩坑
    关于git的分批提交pull requests流程
    SymGAN—Exploiting Images for Video Recognition: Heterogeneous Feature Augmentation via Symmetric Adversarial Learning学习笔记
    AFN—Larger Norm More Transferable: An Adaptive Feature Norm Approach for Unsupervised Domain Adaptation学习笔记
    Learning to Transfer Examples for Partial Domain Adaptation学习笔记
    Partial Adversarial Domain Adaptation学习笔记
    Partial Transfer Learning with Selective Adversarial Networks学习笔记
    Importance Weighted Adversarial Nets for Partial Domain Adaptation学习笔记
    Exploiting Images for Video Recognition with Hierarchical Generative Adversarial Networks学习笔记
    improved open set domain adaptation with backpropagation 学习笔记
  • 原文地址:https://www.cnblogs.com/charon2/p/11314872.html
Copyright © 2011-2022 走看看