lvm – shrink lvm partition size

[root@rhelA ~]# findmnt
TARGET                       SOURCE                       FSTYPE      OPTIONS
/                            /dev/mapper/vg_rhela-lv_root ext4        rw,relatime,seclabel,barrier=1,data=ordered
├─/proc                      proc                         proc        rw,relatime
│ ├─/proc/bus/usb            /proc/bus/usb                usbfs       rw,relatime
│ └─/proc/sys/fs/binfmt_misc                              binfmt_misc rw,relatime
├─/sys                       sysfs                        sysfs       rw,relatime,seclabel
├─/selinux                                                selinuxfs   rw,relatime
├─/dev                       devtmpfs                     devtmpfs    rw,relatime,seclabel,size=946208k,nr_inodes=236552,mode=755
│ └─/dev                     devtmpfs                     devtmpfs    rw,relatime,seclabel,size=946208k,nr_inodes=236552,mode=755
│   ├─/dev/pts               devpts                       devpts      rw,relatime,seclabel,gid=5,mode=620,ptmxmode=000
│   └─/dev/shm               tmpfs                        tmpfs       rw,relatime,seclabel
├─/boot                      /dev/sda1                    ext4        rw,relatime,seclabel,barrier=1,data=ordered
├─/home                      /dev/mapper/vg_rhela-lv_home ext4        rw,relatime,seclabel,barrier=1,data=ordered
├─/misc                      /etc/auto.misc               autofs      rw,relatime,fd=7,pgrp=1649,timeout=300,minproto=5,maxproto=5,indirect
└─/net                       -hosts                       autofs      rw,relatime,fd=13,pgrp=1649,timeout=300,minproto=5,maxproto=5,indirect

[root@rhelA ~]# umount /home

[root@rhelA ~]# e2fsck -f /dev/mapper/vg_rhela-lv_home 
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg_rhela-lv_home: 656/4300800 files (17.8% non-contiguous), 4124861/17188864 blocks

[root@rhelA ~]# e2fsck -fy /dev/mapper/vg_rhela-lv_home 
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg_rhela-lv_home: 656/4300800 files (17.8% non-contiguous), 4124861/17188864 blocks

[root@rhelA ~]# resize2fs /dev/mapper/vg_rhela-lv_home 25G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_rhela-lv_home to 6553600 (4k) blocks.
The filesystem on /dev/mapper/vg_rhela-lv_home is now 6553600 blocks long.

[root@rhelA ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_rhela
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               119.51 GiB
  PE Size               4.00 MiB
  Total PE              30594
  Alloc PE / Size       30594 / 119.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               DOXFrI-vdc8-KjtT-qN4N-oGj3-Yf8K-suupSe

[root@rhelA ~]# lvreduce -L 25G /dev/vg_rhela/lv_home 
  WARNING: Reducing active logical volume to 25.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
  Size of logical volume vg_rhela/lv_home changed from 65.57 GiB (16786 extents) to 25.00 GiB (6400 extents).
  Logical volume lv_home successfully resized
[root@rhelA ~]# resize2fs /dev/mapper/vg_rhela-lv_home 
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 6553600 blocks long.  Nothing to do!

[root@rhelA ~]# mount /dev/mapper/vg_rhela-lv_home /home

[root@rhelA ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhela-lv_root
                       50G  4.2G   43G   9% /
tmpfs                 940M  296K  939M   1% /dev/shm
/dev/sda1             477M   42M  410M  10% /boot
/dev/mapper/vg_rhela-lv_home
                       25G   15G  8.7G  63% /home

[root@rhelA ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_rhela
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               119.51 GiB
  PE Size               4.00 MiB
  Total PE              30594
  Alloc PE / Size       20208 / 78.94 GiB
  Free  PE / Size       10386 / 40.57 GiB
  VG UUID               DOXFrI-vdc8-KjtT-qN4N-oGj3-Yf8K-suupSe

Advertisements

lvm – extend expand size

# show all after crate fdisk command -----------------------------------
[root@localhost ~]# pvdisplay
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               31.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              8066
  Free PE               0
  Allocated PE          8066
  PV UUID               bdaYMp-UQB8-bSFf-UGk1-TYhP-mow6-SLNkuQ
   
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  --- Physical volume ---
  PV Name               unknown device
  VG Name               rhel
  PV Size               468.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              119807
  Free PE               119807
  Allocated PE          0
  PV UUID               Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD
   
  "/dev/sda3" is a new physical volume of "468.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               468.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               3ycy21-P5OL-YKYu-zz4c-wnCB-hsx6-vYnaDt

[root@localhost ~]# vgdisplay
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  --- Volume group ---
  VG Name               rhel
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                1
  VG Size               499.50 GiB
  PE Size               4.00 MiB
  Total PE              127873
  Alloc PE / Size       8066 / 31.51 GiB
  Free  PE / Size       119807 / 468.00 GiB
  VG UUID               TRdEsL-YK5v-0iG7-fMvI-XPyy-Rzpb-LxFbgb
   
[root@localhost ~]# pvscan
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  PV /dev/sda2        VG rhel            lvm2 [31.51 GiB / 0    free]
  PV unknown device   VG rhel            lvm2 [468.00 GiB / 468.00 GiB free]
  PV /dev/sda3                           lvm2 [468.00 GiB]
  Total: 3 [967.50 GiB] / in use: 2 [499.50 GiB] / in no VG: 1 [468.00 GiB]

# remove missing from vg ------------------------------------------------
[root@localhost ~]# vgreduce --removemissing --force rhel
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  PV Rbyn39-R43F-9dIL-D598-ARv6-HN6C-UNsCzD not recognised. Is the device missing?
  Wrote out consistent volume group rhel

[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               31.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              8066
  Free PE               0
  Allocated PE          8066
  PV UUID               bdaYMp-UQB8-bSFf-UGk1-TYhP-mow6-SLNkuQ
   
  "/dev/sda3" is a new physical volume of "468.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               468.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               3ycy21-P5OL-YKYu-zz4c-wnCB-hsx6-vYnaDt
   
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               rhel
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               31.51 GiB
  PE Size               4.00 MiB
  Total PE              8066
  Alloc PE / Size       8066 / 31.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               TRdEsL-YK5v-0iG7-fMvI-XPyy-Rzpb-LxFbgb

# create pv ------------------------------------------------------------
[root@localhost ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               31.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              8066
  Free PE               0
  Allocated PE          8066
  PV UUID               bdaYMp-UQB8-bSFf-UGk1-TYhP-mow6-SLNkuQ
   
  "/dev/sda3" is a new physical volume of "468.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               468.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               fl2Lhs-kIpW-9qH9-VS9Y-2xA0-uKr0-GUYZLm

# extend vg ------------------------------------------------------------
[root@localhost ~]# vgextend /dev/rhel /dev/sda3
  Volume group "rhel" successfully extended

[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               rhel
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               499.50 GiB
  PE Size               4.00 MiB
  Total PE              127873
  Alloc PE / Size       8066 / 31.51 GiB
  Free  PE / Size       119807 / 468.00 GiB
  VG UUID               TRdEsL-YK5v-0iG7-fMvI-XPyy-Rzpb-LxFbgb

# show lv size ---------------------------------------------------------
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/rhel/swap
  LV Name                swap
  VG Name                rhel
  LV UUID                X0Th3D-SZty-2rDO-JGm3-zuOw-ydoi-QXrzRG
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-05-17 01:55:54 +0700
  LV Status              available
  # open                 2
  LV Size                3.02 GiB
  Current LE             772
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/rhel/root
  LV Name                root
  VG Name                rhel
  LV UUID                kWHVMz-X2Tl-b3vT-vNWG-NSSs-Ihq4-C4vxiD
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-05-17 01:55:54 +0700
  LV Status              available
  # open                 1
  LV Size                28.49 GiB
  Current LE             7294
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

# extend lv size -------------------------------------------------------
[root@localhost ~]# lvextend /dev/rhel/root /dev/sda3
  Extending logical volume root to 496.49 GiB
  Logical volume root successfully resized

# show the new size ----------------------------------------------------
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/rhel/swap
  LV Name                swap
  VG Name                rhel
  LV UUID                X0Th3D-SZty-2rDO-JGm3-zuOw-ydoi-QXrzRG
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-05-17 01:55:54 +0700
  LV Status              available
  # open                 2
  LV Size                3.02 GiB
  Current LE             772
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/rhel/root
  LV Name                root
  VG Name                rhel
  LV UUID                kWHVMz-X2Tl-b3vT-vNWG-NSSs-Ihq4-C4vxiD
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-05-17 01:55:54 +0700
  LV Status              available
  # open                 1
  LV Size                496.49 GiB
  Current LE             127101
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

# show with df ---------------------------------------------------------
[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   29G  5.2G   24G  19% /
devtmpfs               123G     0  123G   0% /dev
tmpfs                  123G  128K  123G   1% /dev/shm
tmpfs                  123G  8.9M  123G   1% /run
tmpfs                  123G     0  123G   0% /sys/fs/cgroup
/dev/sda1              497M  119M  379M  24% /boot
/dev/sr0               3.5G  3.5G     0 100% /run/media/exsys/RHEL-7.0 Server.x86_64

#the size only 29GB

# using resize2fs to make use of this space ----------------------------
[root@localhost ~]# resize2fs /dev/rhel/root 
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/rhel/root
Couldn't find valid filesystem superblock.

# ok error next using xfs_growfs to get free space ---------------------------
[root@localhost ~]# xfs_growfs /dev/rhel/root 
meta-data=/dev/mapper/rhel-root  isize=256    agcount=4, agsize=1867264 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=7469056, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=3647, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7469056 to 130151424

# check lagi -----------------------------------------------------------
[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root  497G  5.2G  492G   2% /
devtmpfs               123G     0  123G   0% /dev
tmpfs                  123G  128K  123G   1% /dev/shm
tmpfs                  123G  8.9M  123G   1% /run
tmpfs                  123G     0  123G   0% /sys/fs/cgroup
/dev/sda1              497M  119M  379M  24% /boot
/dev/sr0               3.5G  3.5G     0 100% /run/media/exsys/RHEL-7.0 Server.x86_64

debian 9 – install mariadb 10.x

# apt-get install software-properties-common
# apt-get install dirmngr
# apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
# add-apt-repository 'deb [arch=amd64] http://www.ftp.saix.net/DB/mariadb/repo/10.1/debian stretch main'
# apt-get update
# apt-get install mariadb-server
# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb

centos 69 – install wkhtmltopdf

# get source with wget
wget https://bitbucket.org/wkhtmltopdf/wkhtmltopdf/downloads/wkhtmltox-0.13.0-alpha-7b36694_linux-centos6-amd64.rpm
# install with yum to get dependecy
yum install wkhtmltox-0.13.0-alpha-7b36694_linux-centos6-amd64.rpm -y

# if error need xvfb
yum search xvfb
yum install xorg-x11-server-Xvfb
echo "export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb" >> /etc/profile
source /etc/profile
xvfb-run wkhtmltopdf https://g3n1k.wordpress.com g3n1k.pdf

# if the fonts become reactangle
# copy all your font to /usr/share/fonts
ls /usr/share/fonts/
fc-cache
yum install -y ghostscript

mysql – master to master replication

https://www.digitalocean.com/community/tutorials/how-to-set-up-mysql-master-master-replication

“MySQL replication is the process by which a single data set, stored in a MySQL database, will be live-copied to a second server. This configuration, called “master-slave” replication, is a typical setup. Our setup will be better than that, because master-master replication allows data to be copied from either server to the other one. This subtle but important difference allows us to perform mysql read or writes from either server. This configuration adds redundancy and increases efficiency when dealing with accessing the data.”

mysql01: 192.168.2.36

$ echo "192.168.2.36	mysql01" >> /etc/hosts
$ echo "192.168.2.37	mysql02" >> /etc/hosts
$ sudo apt-get install mysql-server mysql-client -y
$ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

#bind-address = mysql01
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
binlog_do_db = example
#binlog_ignore_db = include_database_name

$ mysql -u root -p

mysql> create user 'replicator'@'%' identified by 'password';
Query OK, 0 rows affected (0.01 sec)

mysql> grant replication slave on *.* to 'replicator'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 |      154 | example      |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

# get the log file and log post in server2

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host='mysql02', master_user='replicator', master_password='password', master_log_file='mysql-bin.000003',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql02: 192.168.2.37

$ echo "192.168.2.36	mysql01" >> /etc/hosts
$ echo "192.168.2.37	mysql02" >> /etc/hosts
$ sudo apt-get install mysql-server mysql-client -y
$ sudo nano /etc/mysql/mysql.conf.d/mysql02.cnf

bind-address = mysql02
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
binlog_do_db = example
#binlog_ignore_db = include_database_name

$ sudo service mysql restart

mysql> create user 'replicator'@'%' identified by 'password'; 
Query OK, 0 rows affected (0.01 sec)

mysql> grant replication slave on *.* to 'replicator'@'%'; 
Query OK, 0 rows affected (0.00 sec)

mysql> create database example; 
Query OK, 1 row affected (0.01 sec)

mysql> change master to master_host = "192.168.0.104", master_user = "replicator", master_password = "password", master_log_file = "mysql-bin.000001", master_log_pos = 607;
Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host='mysql01', master_user='replicator', master_password='password', master_log_file='mysql-bin.000003',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 |      154 | example      |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host='mysql01', master_user='replicator', master_password='password', master_log_file='mysql-bin.000003',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

Doing test write from mysql01

mysql > use example;

mysql> create table example.testuser(id int, name varchar(20));

mysql > INSERT INTO `testuser` (`id`, `name`) VALUES (1, 'indra sadik');

mysql > INSERT INTO `testuser` (`id`, `name`) VALUES (2, 'indradhi');

mysql > select * from `testuser`;

mysql> select * from example.testuser;
+------+-------------+
| id   | name        |
+------+-------------+
|    1 | indra sadik |
|    2 | indradhi    |
+------+-------------+
2 rows in set (0.00 sec)

mysql>

Doing test write from mysql02

mysql > use example;

mysql> select * from example.testuser;
+------+-------------+
| id   | name        |
+------+-------------+
|    1 | indra sadik |
|    2 | indradhi    |
+------+-------------+
2 rows in set (0.00 sec)

mysql > INSERT INTO `testuser` (`id`, `name`) VALUES (3, 'denly');

mysql> select * from example.testuser;
+------+-------------+
| id   | name        |
+------+-------------+
|    1 | indra sadik |
|    2 | indradhi    |
|    3 | denly       |
+------+-------------+
3 rows in set (0.00 sec)

Doing test read from mysql01

mysql> select * from example.testuser;
+------+-------------+
| id   | name        |
+------+-------------+
|    1 | indra sadik |
|    2 | indradhi    |
|    3 | denly       |
+------+-------------+
3 rows in set (0.00 sec)

postgresql – pointing postgresql data to new location

Database grow over time, it out growing the space on their partition located.
in redhat 6.7, the default partition for “/” its 50GB and the rest going to “/home” partition.
when you default install postgresql-9.5 it would located in “/opt” which include in “/” partition.
for database production 50GB it’s so small. so i want change the data folder to “/home” which have TB space.

#status postgres
$ /etc/init.d/postgresql-9.5 status
pg_ctl: server is running (PID: 6309)
/opt/PostgreSQL/9.5/bin/postgres "-D" "/opt/PostgreSQL/9.5/data"

# stop postgres
$ service postgresql-9.5 stop
$ /etc/init.d/postgresql-9.5 status
pg_ctl: no server running

# change variable
$ nano /opt/PostgreSQL/9.5/pg_env.sh

export PGDATA=/opt/PostgreSQL/9.5/data
change to
export PGDATA=/home/pg_data

# create dir
$ mkdir -p /home/pg_data

# doing rsync
$ rsync -azP /opt/PostgreSQL/9.5/data/ /home/pg_data/

# just make sure
$ mv /opt/PostgreSQL/9.5/data /opt/PostgreSQL/9.5/data_bak

# backup service script
$ mkdir -p ~/backup/ && mv /etc/rc.d/init.d/postgresql-9.5 ~/backup/

# download postgresql-9.5 file
$ wget https://raw.githubusercontent.com/g3n1k/exsys/master/postgresql-9.5

# move postgresql-9.5 to /etc/rc.d/init.d/
$ mv postgresql-9.5 /etc/rc.d/init.d/

# start postgresql
$ service postgresql-9.5 start

# status postgresql
$ service postgresql-9.5 status
pg_ctl: server is running (PID: 13282)
/opt/PostgreSQL/9.5/bin/postgres "-D" "/home/pg_data"