quarta-feira, 15 de março de 2017

How to install PostgreSQL 9.6 on Ubuntu/Debian/Linux

1. Introduction

This post gathers information about install PostgreSQL 9.6 on Ubuntu Server

2. Step-by-Step


  • Follow step by step from reference https://raonyguimaraes.com/how-to-install-postgresql-9-6-on-ubuntudebianlinux-mint/
  • Complete steps from reference http://askubuntu.com/questions/831292/how-to-install-postgresql-9-6-on-any-ubuntu-version

    $ sudo apt-get update
    $ sudo apt-get install postgresql-9.6
    $ sudo passwd postgres # password = postgres
    $ sudo service postgresql start


  • Test PostgreSQL database connection method peer

    $ su postgres # passwd = postgres


  • Create a PostgreSQL sample database called "database_name"

    $ createdb database_name
    $ psql -d database_name
    database_name=# \q


  • Configure PostgreSQL to allow remote IP address to access PostgreSQL

    $ exit # default user
    $ sudo cp /etc/postgresql/9.6/main/pg_hba.conf /etc/postgresql/9.6/main/pg_hba.conf.bkp.2017-03-15
    $ sudo cp /etc/postgresql/9.6/main/postgresql.conf /etc/postgresql/9.6/main/postgresql.conf.bkp.2017-03-15
    $ sudo vim /etc/postgresql/9.6/main/pg_hba.conf
        :
        host    all             all             10.0.2.0/24            md5
        :
    $ sudo vim /etc/postgresql/9.6/main/postgresql.conf
        :
        listen_addresses = '*'        
        :
    $ sudo service postgresql stop
    $ sudo service postgresql start
    $ sudo service postgresql status


  • Create a PostgreSQL database user called "admin" identified by password "admin"

    $ su postgres # passwd = postgres
    $ psql
    database_name=# CREATE USER admin WITH PASSWORD 'admin';
    database_name=# GRANT postgres TO admin;
    database_name=# \q
    $ psql -h 127.0.0.1 -d database_name -U admin # passwd = admin
    database_name=# \q
    $ psql -h 10.0.2.15 -d database_name -U admin # passwd = admin
    database_name=# \q


3. References




segunda-feira, 13 de março de 2017

How To Setup Ruby on Rails with Postgres

1. Introduction

This post gathers information about setting up Ruby on Rails with Postgres.


2. Step-by-Step

2.1. CentOs required library for Postgres 9.6



# yum install postgresql96-devel
# yum install postgresql96-libs

2.2. Install gem Postgres

# gem install pg -- --with-pg-config=/usr/pgsql-9.6/bin/pg_config


3. References




How to install RAILS on CentOs 7

1. Introduction

This post gathers information about install RAILS on CentOs 7.


2. References




How to connect to PostgreSQL using Python

1. Introduction

This post gathers information about configuring Python to connect to PostgreSQL database.

2. Step-by-Step

2.1. Install Python and Pip on SO Base

2.1.1. ONLY FOR CENTOS 7: Install required packages: Python Pip

# yum install epel-release
# cd /tmp
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum -y update
# yum -y install python-pip
# pip install --upgrade pip


2.1.2. ONLY FOR UBUNTU: Install Python 2.7 and Pip

# sudo apt-get update
# sudo apt-get install python2.7
# sudo apt install python-pip
# pip install --upgrade pip


2.2. Install psycopg2

# pip install psycopg2


2.3. Install pygresql

# pip install pygresql



3. Reference




Installing PostgreSql 9.6 into CentOs

1. Introduction

This post gathers information about install PostgreSql into Centos 7.

2. Step-by-Step

2.1. Configure YUM repository

# vim /etc/yum.repos.d/CentOS-Base.repo
    :
[base]
    :
exclude=postgresql*

[update]
    :
exclude=postgresql*

# yum list postgresql*
# yum install postgresql96-server


2.2. Get RPM file and run

# wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
# rpm -iUvh pgdg-centos96-9.6-3.noarch.rpm


2.3. Install PostgreSql

# yum -y install postgresql96 postgresql96-server postgresql96-contrib postgresql96-libs


2.4. Configure PostgreSql auto estart

# systemctl enable postgresql-9.6


2.5. Initialize database

# service postgresql-9.6 initdb


2.6. Start PostgreSql and check

# systemctl start postgresql-9.6


2.7. Connect to PostgreSql

# su - postgres
Last login: Sun Mar 12 21:29:21 -03 2017 on pts/1
-bash-4.2$ psql
psql (9.6.2)
Type "help" for help.

postgres=#


2.8. List databases and query system catalog

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres postgres=CTc/postgres
(3 rows)

postgres=#  select schemaname, count(*) from pg_tables group by schemaname;
     schemaname     | count
--------------------+-------
 information_schema |     7
 pg_catalog         |    55
(2 rows)


2.9. Locating PostgreSql configuration file "pg_hba"

# su - postgres
# env | grep "PGDATA"
PGDATA=/var/lib/pgsql/9.6/data
# ls -l /var/lib/pgsql/9.6/data/pg*.conf
-rw-------. 1 postgres postgres 4224 Mar 12 21:27 /var/lib/pgsql/9.6/data/pg_hba.conf


2.10. Configure PostgreSql remote access


  • Change "ident" for "md5"

# vi /var/lib/pgsql/9.6/data/pg_hba.conf
  :
#host    all             all             127.0.0.1/32            ident
host    all             all             127.0.0.1/32            md5
  :


3. References




sábado, 15 de outubro de 2016

Installing Docker on CentOs 6

1. Introduction

This post shows how to install "Docker" on a CentOS 6.x system.


2. Step-by-Step

2.1. Check if processosr suports Docker

  • Docker does not support 32 bits processors
  • Docker is supported by Kernel 3.8 or higher


[root@localhost install-docker]# uname -a
Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost install-docker]#


2.2. Install Docker using official scripts from official 

[root@localhost ~]# mkdir install-docker
[root@localhost ~]# cd install-docker/
[root@localhost install-docker]# wget -qO- https://get.docker.com | sh
+ sh -c 'sleep 3; yum -y -q install docker-engine'

warning: rpmts_HdrFromFdno: Header V4 RSA/SHA1 Signature, key ID 2c52609d: NOKEY
Importing GPG key 0x2C52609D:
 Userid: "Docker Release Tool (releasedocker) <docker@docker.com>"
 From  : https://yum.dockerproject.org/gpg

If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker your-user

Remember that you will have to log out and back in for this to take effect!

[root@localhost install-docker]#


2.3. Start Docker service and configure to startup

[root@localhost install-docker]# service docker status
docker is stopped
[root@localhost install-docker]# service docker start
Starting cgconfig service:                                 [  OK  ]

Starting docker:                                           [  OK  ]

[root@localhost install-docker]# chkconfig docker



2.4. Using Docker basic commands

  • Docker version
[root@localhost install-docker]# docker --version
Docker version 1.7.1, build 786b29d



  • Is there any container running? And what about created containger but not running?
[root@localhost install-docker]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost install-docker]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost install-docker]#


  • Searching images from containers of 'centos' and 'debian'
[root@localhost install-docker]# docker search centos
NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                          The official build of CentOS.                   2733      [OK]
ansible/centos7-ansible         Ansible on Centos7                              89                   [OK]
jdeathe/centos-ssh              CentOS-6 6.8 x86_64 / CentOS-7 7.2.1511 x8...   41                   [OK]
jdeathe/centos-ssh-apache-php   CentOS-6 6.8 x86_64 / Apache / PHP / PHP M...   21                   [OK]
nimmis/java-centos              This is docker images of CentOS 7 with dif...   16                   [OK]
million12/centos-supervisor     Base CentOS-7 with supervisord launcher, h...   12                   [OK]
gluster/gluster-centos          Official GlusterFS Image [ CentOS7 +  Glus...   12                   [OK]
torusware/speedus-centos        Always updated official CentOS docker imag...   8                    [OK]
nickistre/centos-lamp           LAMP on centos setup                            7                    [OK]
kinogmt/centos-ssh              CentOS with SSH                                 6                    [OK]
nathonfowlie/centos-jre         Latest CentOS image with the JRE pre-insta...   4                    [OK]
centos/mariadb55-centos7                                                        3                    [OK]
consol/sakuli-centos-xfce       Sakuli end-2-end testing and monitoring co...   2                    [OK]
centos/tools                    Docker image that has systems administrati...   2                    [OK]
timhughes/centos                Centos with systemd installed and running       1                    [OK]
harisekhon/centos-java          Java on CentOS (OpenJDK, tags jre/jdk7-8)       1                    [OK]
harisekhon/centos-scala         Scala + CentOS (OpenJDK tags 2.10-jre7 - 2...   1                    [OK]
darksheer/centos                Base Centos Image -- Updated hourly             1                    [OK]
centos/redis                    Redis built for CentOS                          1                    [OK]
blacklabelops/centos            CentOS Base Image! Built and Updates Daily!     1                    [OK]
grayzone/centos                 auto build for centos.                          0                    [OK]
repositoryjp/centos             Docker Image for CentOS.                        0                    [OK]
smartentry/centos               centos with smartentry                          0                    [OK]
ustclug/centos                   USTC centos                                    0                    [OK]
januswel/centos                 yum update-ed CentOS image                      0                    [OK]
[root@localhost install-docker]#
[root@localhost install-docker]#
[root@localhost install-docker]#
[root@localhost install-docker]# docker search debian
NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
debian                         Debian is a Linux distribution that's comp...   1724      [OK]
neurodebian                    NeuroDebian provides neuroscience research...   29        [OK]
jesselang/debian-vagrant       Stock Debian Images made Vagrant-friendly ...   9                    [OK]
armbuild/debian                ARMHF port of debian                            8                    [OK]
eboraas/debian                 Debian base images, for all currently-avai...   6                    [OK]
frekele/debian                 docker run --rm --name debian frekele/debian    2                    [OK]
reinblau/debian                Debian with usefully default packages for ...   2                    [OK]
datenbetrieb/debian            minor adaption of official upstream debian...   1                    [OK]
1maa/debian                    Debian base image                               1                    [OK]
servivum/debian                Debian Docker Base Image with Useful Tools      1                    [OK]
maxexcloo/debian               Base image built on Debian with init, Supe...   1                    [OK]
lephare/debian                 Base debian images                              1                    [OK]
webhippie/debian               Docker images for debian                        1                    [OK]
eeacms/debian                  Docker image for Debian to be used with EE...   1                    [OK]
lucasbarros/debian             Basic image based on Debian                     1                    [OK]
smartentry/debian              debian with smartentry                          0                    [OK]
konstruktoid/debian            Debian base image                               0                    [OK]
mariorez/debian                Debian Containers for PHP Projects              0                    [OK]
fike/debian                    Debian Images with language locale installed.   0                    [OK]
vcatechnology/debian           A Debian image that is updated daily            0                    [OK]
visono/debian                  Docker base image of debian 7 with tools i...   0                    [OK]
nimmis/debian                  This is different version of Debian with a...   0                    [OK]
icedream/debian-jenkinsslave   Debian for Jenkins to be used as slaves.        0                    [OK]
ustclug/debian                 debian image for docker with rustic mirror      0                    [OK]
pl31/debian                    Debian base image.                              0                    [OK]



  • My first containers
Run ( launch ) your 'debian' container, and at first update your SO (this may takes a while on first time you run this image), check your IP, and exit or loggof or ctrl+d. Notice that when you exit container, this does not exist anymore!!! 





3. References