Friday, October 24, 2014

CentOS 7 install PostgreSQL 9.2.7 with data files on SSD

CentOS 7 is much much newer than 6, highly recommended fro any new "Enterprise" build.

It came with the PostgreSQL is 9.2.7, the latest stable is 9.3.5 from PostgreSQL.org at this moment.
I say 9.2 is good enough for me considering the works RedHat has been done to make it fit.

To install it is super easy:

yum install postgresql-server.x86_64



Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 33 kB 00:00:00
(2/2): updates/7/x86_64/primary_db | 3.6 MB 00:00:00
Loading mirror speeds from cached hostfile
* base: centos.mirror.rafal.ca
* extras: mirror.netflash.net
* updates: centos.mirror.nexicom.net
Resolving Dependencies
--> Running transaction check
---> Package postgresql-server.x86_64 0:9.2.7-1.el7 will be installed
--> Processing Dependency: postgresql-libs(x86-64) = 9.2.7-1.el7 for package: postgresql-server-9.2.7-1.el7.x86_64
--> Processing Dependency: postgresql(x86-64) = 9.2.7-1.el7 for package: postgresql-server-9.2.7-1.el7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql-server-9.2.7-1.el7.x86_64
--> Running transaction check
---> Package postgresql.x86_64 0:9.2.7-1.el7 will be installed
---> Package postgresql-libs.x86_64 0:9.2.7-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================
Installing:
postgresql-server x86_64 9.2.7-1.el7 base 3.8 M
Installing for dependencies:
postgresql x86_64 9.2.7-1.el7 base 2.9 M
postgresql-libs x86_64 9.2.7-1.el7 base 229 k

Transaction Summary
=======================================================================================================================================
Install 1 Package (+2 Dependent packages)

Total download size: 6.9 M
Installed size: 32 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): postgresql-libs-9.2.7-1.el7.x86_64.rpm | 229 kB 00:00:00
(2/3): postgresql-9.2.7-1.el7.x86_64.rpm | 2.9 MB 00:00:00
(3/3): postgresql-server-9.2.7-1.el7.x86_64.rpm | 3.8 MB 00:00:00
---------------------------------------------------------------------------------------------------------------------------------------
Total 7.2 MB/s | 6.9 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : postgresql-libs-9.2.7-1.el7.x86_64 1/3
Installing : postgresql-9.2.7-1.el7.x86_64 2/3
Installing : postgresql-server-9.2.7-1.el7.x86_64 3/3
Verifying : postgresql-libs-9.2.7-1.el7.x86_64 1/3
Verifying : postgresql-server-9.2.7-1.el7.x86_64 2/3
Verifying : postgresql-9.2.7-1.el7.x86_64 3/3

Installed:
postgresql-server.x86_64 0:9.2.7-1.el7

Dependency Installed:
postgresql.x86_64 0:9.2.7-1.el7 postgresql-libs.x86_64 0:9.2.7-1.el7

Complete!


Mount the data directory on SSD

First check the permission:

ls -alt /var/lib/pgsql/
drwx------. 2 postgres postgres 6 Jun 10 03:49 backups
drwx------. 2 postgres postgres 6 Jun 10 03:49 data


Add in /etc/fstab:

/dev/mapper/VG_Backup-LV_Backup /var/lib/pgsql/backups xfs defaults 0 0
/dev/mapper/VG_SSD00-LV_SSD_Database /var/lib/pgsql/data xfs defaults 0 0


Mount it manually:

mount /var/lib/pgsql/data
mount /var/lib/pgsql/backups


Change the permission:

chown postgres:postgres /var/lib/pgsql/data
chown postgres:postgres /var/lib/pgsql/backups


And don't forget reboot check permission:

# ls -alt /var/lib/pgsql
total 8
drwxr-xr-x. 26 root root 4096 Oct 23 16:42 ..
drwx------. 4 postgres postgres 51 Oct 23 16:35 .
drwxr-xr-x. 2 postgres postgres 6 Oct 23 16:29 data
drwxr-xr-x. 2 postgres postgres 6 Oct 23 15:59 backups
-rw-r--r--. 1 postgres postgres 85 Jun 10 03:49 .bash_profile

CentOS 7 Install Open-vm-tools for VMware ESXi


yum install open-vm-tools.x86_64



Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.mirror.rafal.ca
* extras: centos.mirror.nexicom.net
* updates: centos.mirror.nexicom.net
Resolving Dependencies
--> Running transaction check
---> Package open-vm-tools.x86_64 0:9.4.0-3.el7 will be installed
--> Processing Dependency: libicuuc.so.50()(64bit) for package: open-vm-tools-9.4.0-3.el7.x86_64
--> Processing Dependency: libicui18n.so.50()(64bit) for package: open-vm-tools-9.4.0-3.el7.x86_64
--> Processing Dependency: libicudata.so.50()(64bit) for package: open-vm-tools-9.4.0-3.el7.x86_64
--> Processing Dependency: libdnet.so.1()(64bit) for package: open-vm-tools-9.4.0-3.el7.x86_64
--> Running transaction check
---> Package libdnet.x86_64 0:1.12-13.1.el7 will be installed
---> Package libicu.x86_64 0:50.1.2-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================
Installing:
open-vm-tools x86_64 9.4.0-3.el7 base 429 k
Installing for dependencies:
libdnet x86_64 1.12-13.1.el7 base 31 k
libicu x86_64 50.1.2-11.el7 base 6.9 M

Transaction Summary
=======================================================================================================================================
Install 1 Package (+2 Dependent packages)

Total download size: 7.3 M
Installed size: 25 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): libdnet-1.12-13.1.el7.x86_64.rpm | 31 kB 00:00:00
(2/3): open-vm-tools-9.4.0-3.el7.x86_64.rpm | 429 kB 00:00:00
(3/3): libicu-50.1.2-11.el7.x86_64.rpm | 6.9 MB 00:00:00
---------------------------------------------------------------------------------------------------------------------------------------
Total 7.1 MB/s | 7.3 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libicu-50.1.2-11.el7.x86_64 1/3
Installing : libdnet-1.12-13.1.el7.x86_64 2/3
Installing : open-vm-tools-9.4.0-3.el7.x86_64 3/3
Verifying : libdnet-1.12-13.1.el7.x86_64 1/3
Verifying : open-vm-tools-9.4.0-3.el7.x86_64 2/3
Verifying : libicu-50.1.2-11.el7.x86_64 3/3

Installed:
open-vm-tools.x86_64 0:9.4.0-3.el7

Dependency Installed:
libdnet.x86_64 0:1.12-13.1.el7 libicu.x86_64 0:50.1.2-11.el7

Complete!



FYI: I found have to reboot the VM to get the info from vmware ESXi control center.

CentOS 7 add new SSD in LVM format XFS

Got sometime with CentOS 7 recently.

Try to add an New SSD into system.
I know to get the best performance should avoid LVM, but for easy extend I will using LVM here.

First make sure you are using newer fdisk (added SSD alignment support after 2.17), CentOS 7 came with 2.23.2.


# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xd6b73b64.

Command (m for help): p

Disk /dev/sdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xd6b73b64

Device Boot Start End Blocks Id System

Command (m for help): q


Create partition and change the flag to LVM (e8):


# fdisk -c -u /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xab948127.

Command (m for help): p

Disk /dev/sdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xab948127

Device Boot Start End Blocks Id System

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set

Command (m for help): p

Disk /dev/sdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xab948127

Device Boot Start End Blocks Id System
/dev/sdc1 2048 419430399 209714176 83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xab948127

Device Boot Start End Blocks Id System
/dev/sdc1 2048 419430399 209714176 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.



Create PV


# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created


Display PV

# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos_milliondollorserver-database
PV Size 15.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 3970
Free PE 0
Allocated PE 3970
PV UUID tY2Myw-m0hm-sscc-Qc8M-hOfJ-XNA6-fZUIxv

--- Physical volume ---
PV Name /dev/sdb1
VG Name VG_Backup
PV Size 100.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25599
Free PE 0
Allocated PE 25599
PV UUID wNDnMs-vOAL-WwAX-0N6d-xzsJ-ap85-gDbnik

"/dev/sdc1" is a new physical volume of "200.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc1
VG Name
PV Size 200.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID o9Hvzz-YDy0-p8pa-aOhJ-nPtA-nNUX-kX1WzF


Create VG

# vgcreate VG_SSD00 /dev/sdc1
Volume group "VG_SSD00" successfully created


Create LV using all free space available on the VG just created


# lvcreate -l 100%FREE -n LV_SSD_Database VG_SSD00
Logical volume "LV_SSD_Database" created


Format in XFS

# mkfs.xfs /dev/VG_SSD00/LV_SSD_Database
meta-data=/dev/VG_SSD00/LV_SSD_Database isize=256 agcount=4, agsize=13106944 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=52427776, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=25599, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0


Found /dev/mapper for mounting:

# ls /dev/mapper/
centos_milliondollorserver--database-root control VG_SSD00-LV_SSD_Database
centos_milliondollorserver--database-swap VG_Backup-LV_Backup


Update /etc/fstab


# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Oct 22 20:44:00 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_milliondollorserver--database-root / xfs defaults 1 1
UUID=b6fc0e61-697f-42db-8be7-a6feabc8e85b /boot xfs defaults 1 2
/dev/mapper/centos_milliondollorserver--database-swap swap swap defaults 0 0
/dev/mapper/VG_Backup-LV_Backup /backup xfs defaults 0 0
/dev/mapper/VG_SSD00-LV_SSD_Database /var/ssd xfs defaults 0 0


Mount it:

# mount /var/ssd
# df -k


To check SSD alignment:
Looking at the Start Sector, should be 2048 not 63!


# fdisk -l -u /dev/sdc

Disk /dev/sdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xab948127

Device Boot Start End Blocks Id System
/dev/sdc1 2048 419430399 209714176 8e Linux LVM

Wednesday, October 22, 2014

Update WordPress to 4.0

Been busy on Life and Job, finally sit down and check my blog.

WOW, 4795 Comments!!!

11 Updates!!!

Just wget the latest from wordpress.org

wget https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
rsync -a ./wordpress/ /www/milliondollarserver.com/
service nginx restart


[poll id="4"]

CentOS 7 How to secure SSH service

Haven't got any time play with CentOS 7 since it launched.

Here are my steps to setup the SSH service on CentOS 7:

1.sudo

2.Configure SSH disable root remote login

vi /etc/ssh/sshd_config

PermitRootLogin no


3.Configure SSH to a bigger random port
Most of the "Port scanning Tools", start from lower ports number: 1,2,3...20,21,22,23...10000.
To make "My Friends"'s work a little bit hard.
To secure the ssh, simply give it an high random number like: 44022
vi /etc/ssh/sshd_config

Port 44022


4.Tell SELinux to pickup the new port
semanage port -a -t ssh_port_t -p tcp 44022


5.Update Firmwalld allow the new port
vi /usr/lib/firewalld/services/ssh.xml





SSH
Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.




Now restart the ssh and firmwalld daemons
# systemctl restart sshd.service
# firewall-cmd --reload


Reference: http://wiki.centos.org/HowTos/Network/SecuringSSH

[poll id="3"]

New debian SSD Server

Just build an new debian server with SSD installed, here is some optimization:

1.Disable swap

2.Enable dealine scheduler

apt-get install sysfsutils
echo "block/sda/queue/scheduler = deadline" >> /etc/sysfs.conf


test at reboot:

cat /sys/block/sda/queue/scheduler


3. Mounting SSD filesystems

# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/spool tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
# / was on /dev/sda2 during installation
UUID=9444b6b1-0be1-4c59-a383-7112156a6eeb / ext4 discard,noatime,nodiratime,errors=remount-ro 0 1
# /boot/efi was on /dev/sda1 during installation
UUID=5FA9-ED48 /boot/efi vfat defaults 0 1