How to install sublime on CentOS

To install sublime we will first need to download it from the repository using the wget command:
wget http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3065_x64.tar.bz2
Once the archive has been downloaded, we’ll need to execute sudo tar -vxjf sublime_text_3_build_3065_x64.tar.bz2 to unpack its contents in the current directory. If you want to find out more about archiving and compressing files in Linux, read this article:

How to install sublime
I’ll move the directory to /opt because this is where I store all of the software installed. To achieve this result, execute mv sublime_text_3 /opt/.
Now we’ll have to create a symbolic link so we can launch the application much faster:
sudo ln -s /opt/sublime_text_3/sublime_text /usr/bin/sublime3
To create a shortcut on the CentOS server if you are using a Unity Desktop environment, you’ll need to create a file in /usr/share/applications/. I’ve created a file named sublime.desktop in which I’ve added the following entries:
[Desktop Entry]
Name=Sublime3
Exec=sublime3
Terminal=false
Icon=/opt/sublime_text_3/Icon/48×48/sublime-text.png
Type=Application
Categories=TextEditor;IDE;Development
X-Ayatana-Desktop-Shortcuts=NewWindow
 
[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n
TargetEnvironment=Unity
Sublime on CentOS
The shortcut has been added to the applications menu, all that’s left to do now is to start and enjoy sublime:
How to install Sublime on Linux

How to configure an NFS mount on CentOS

In this article I will show you how to configure a NFS mount on CentOS machines. I’ve used this technology when sharing a folder between multiple web servers that were hosting a single web application. This method is useful because a folder is mounted on multiple servers and deployments can be made on a single machine while changes will be replicated between all nodes, thus you decrease the number of mistakes that can occur.
For this demonstration I will be using two CentOS Virtual Machines hosted in my VMware testing environment. To create a NFS mount we need at least two machines: the server (which hosts the directory) and the client (which mounts the specified directory). We’ll start configuring these two components:
  • NFS Server
We’ll need to install the nfs-util and its library package by executing the following command:

yum install nfs-utils nfs-utils-lib
NFS depends on the rpcbind service so make sure you start this service by typing service rpcbind start. You can then verify its status by executing service rpcbind status:

NFS mount
Start the NFS service with the same command then verify its status (you can also use ps -aux | grep nfs):
CentOS NFS mount
 

In /var/www/ I’ve created a new folder named web.ppscu.com which will be mounted on the client.
The /etc/exports file is used to specify which file systems will be exported to remote machines. I’ll add the following entry in the exports file:
/var/www/web.ppscu.com 192.168.61.135(rw,sync,no_root_squash,no_subtree_check)

You can check out the parameters available in the exports file on this page.
Once the entry has been added to the file, we’ll need to export the directory using the exportfs -a command.
  • NFS client

Install the necessary packages by typing yum install nfs-utils nfs-utils-lib

Create the folder to be mounted on the client machine:
mkdir -p /var/www/web.ppscu.com
Now we can safely mount the shared folder by using the following command:
mount 192.168.61.136:/var/www/web.ppscu.com/ /var/www/web.ppscu.com/ where 192.168.61.136 is the IP address of the NFS server.
umount /var/www/web.ppscu.com/ is used to remove a mount from a CentOS machine.
Note that the directory will be connected to the server until it’s rebooted. To create a persistent mount point, we’ll need to edit the /etc/fstab file and add the following line:
192.168.61.136:/var/www/web.ppscu.com/  /var/www/web.ppscu.com/   nfs   auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
Linux file system table
We can verify that the directory was mounted successfully by typing df -h:
How to configure a NFS mount
Another way in which we can check out the mount point is by typing mount without parameters:
NFS mount point
mount -a is used to force the OS to reload and mount all the entries added in the  /etc/fstab file
You can also try to create a file in the specified folder with the touch file_name command and then verify if you are able to see it from the client.
That’s about it for this article folks, I hope you’ll find it useful.

Granting rights to multiple databases on MySQL

To grant a user rights to perform actions on several databases with similar names we can use a pattern and with a single command perform all the needed operations. Suppose you have a DBA server with multiple databases and you want to grant rights to a single user on databases ending with _openfire. To achieve this result you would use a command similar to:
grant select on `%_openfire`.* to ‘user1’@’%’ identified by ‘”12wqasxzedc3;
 
select – the permissions granted to the user
% – is used to specify for any value that precedes _openfire
‘user1’@’%’ – specifies that for user1, the permissions for %_openfire will be propagated to all tables within those databases (specified with @)
identified by – set the password for that username
To visualize the databases, use the following command:
show databases;
Now we can view the newly added permissions, note that mysql automatically creates hashes from passwords so you will not be able to see them:
mysql> show grants for ‘user1‘@’%’;
+——————————————————————————————————-+
| Grants for user1@%                                                                                   |
+——————————————————————————————————-+
| GRANT USAGE ON *.* TO ‘user1‘@’%’ IDENTIFIED BY PASSWORD ‘*F4A2073C8F87C6D1CB45E206228335EE95D6E7A2’ |
| GRANT SELECT ON `%_openfire`.* TO ‘user1‘@’%’                                                        |
+——————————————————————————————————-+
MySQL stores the the results of GRANT and CREATE USER statements in memory. To release the cached memory you need to use the flush privileges; command after using the grant statement. If you don’t run this command after you’ve set the permissions, they will be flushed once the server is rebooted.

Determine size of directories in Linux

Use the du command to determine the size of multiple directories within the Linux file system. It supports multiple parameters but I usually prefer using it as follows:
du -sch *
-c, –total
              produce a grand total
-s, –summarize
              display only a total for each argument
-h, –human-readable
              print sizes in human readable format (e.g., 1K 234M 2G)
 
Determine size of directories in Linux
du –max-depth=1 -B M | sort -n
–max-depth=N
              print the total for a directory (or file, with –all) only if it is N or fewer levels below the command line argument;  –max-depth=0 is the same as  –sum-marize
-B, –block-size=SIZE  
              use SIZE-byte blocks  M (megabytes)
Sort with -n is used to  compare according to string numerical value
 
Determine size of directories in CentOS

How to install fabric on CentOS

In this short article I will show you how to install fabric, a useful tool that can be used to automatize the way you execute ssh commands over multiple machines (from fabfile):
Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
Multiple software must be installed before you can successfully use fabric:
  • Install python-devel : execute yum install python-devel
Install python-devel on CentOS
  • Install epel-release: execute yum install epel-release
Install epel-release on CentOS
Alternatively you can use wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm to download the packge and then execute rpm -ivh epel-release-6-8.noarch.rpm to install it. Note that if you are located behind a proxy, you will need to set a proxy on your CentOS machine.
  • Now we’ll need to install python-pip by executing yum install -y python-pip, if you receive an error saying something like: Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again, then you will need to edit the epel.repo file. Execute vim /etc/yum.repos.d/epel.repo to open this configuration file in a text editor. Now comment mirrorlist section and uncomment baseurl:
EPEL repository on CentOS
  • You can now execute yum update to perform a full update on the Operating System and then try again with the python-pip install. You’ll have to execute pip install paramiko==1.10 and if you receive a timeout error similar to the image below, configure a https proxy (export https_proxy=proxy.ppscu.com:3128) and then retry the install:
Install python-pip on CentOS
  • To complete the install operation execute pip install fabric and wait for the download/install operation to complete:
How to install fabric on CentOS

Setting Proxy Server for CentOS machine

Linux offers several possibilities when setting a proxy server on a CentOS machine. You can configure a proxy server for a single bash shell, for all users that have access on the machine or for specific user.

  • Configuring proxy server for a single bash shell: export http_proxy=http://proxy-server:port/

$ export http_proxy=http://192.168.1.10:3128/
$ export http_proxy=http://proxy.ppscu.com:3128/

The exported environment variable can be visualized by executing env or env | grep proxy:

[root@Linux-VM init.d]# env
HOSTNAME=Linux-VM
SELINUX_ROLE_REQUESTED=
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=192.168.61.1 53544 22
SELINUX_USE_CURRENT_RANGE=
SSH_TTY=/dev/pts/0
http_proxy=http://proxy.ppscu.com:3128/
USER=root

  • Configuring proxy server for all users: edit /etc/profile file

Use your desired text editor and add one of the following lines to the profiles file

export http_proxy=http://proxy.ppscu.com:3128/
export http_proxy=http://username:password@http://proxy.ppscu.com:3128/
  • Configuring proxy server for specific user: edit either ~/.bash_profile or $HOME/.bash_profile
Edit either one of these two files and add the following line
export http_proxy=http://username:password@http://proxy.ppscu.com:3128/

Extend logical volume on CentOS

In this article we will learn how to extend a logical volume on a Linux machine. Note that I’m using a VM hosted in my VirtualBox environment so you should cover this article with a similar configuration. Before we proceed to the actual configuration steps make sure that the physical disk has been added to the Virtual Machine and the disk is detected by the OS.
To view the available physical disks type pvdisplay:
Linux LVM
The fields shown in the command’s output are the following:
physical volume device name: /dev/sda2
volume group name: vg_linuxvm
physical volume size: 19.51 GiB / not usable 3.00 MiB
physical extent size: 4.00 MiB – refers to the size of blocks that an be allocated on the disk
total number physical extent: 4994 – the total number of blocks from the hard drive
free number physical extent: 0 – number of blocks not allocated on the disk
allocated number of physical extents: 4994
physical volume unique id: GyF1nY-s4rK-DaIV-bMRX-mNP8-4NMf-RJYYdk
Execute fdisk -l to view the available physical disks, physical partitions and logical partitions:
Format disk on CentOS
As you can see from the command’s output, my current disk /dev/sda with 21,5 GB contains two partitions: /dev/sda1 and /dev/sda2. Note that the second partition has the ID set to 8e which indicates Linux LVM.
Execute df -h to view the current setup of the Virtual Machine:
Disk free command
The system may or may not detect the newly added physical disk if you type fdisk -l again. Note that your server may have multiple host bus adapters, to rescan your HBAs, execute the following command:
echo “Channel Target LUN” > /sys/class/scsi_host/hostX/scan
where:
X is the HBA number
C in the channel on the HBA
T is the SCSI target ID
LUN number
View available HBAs by navigating to /sys/class/scsi_host/.
To force your machine to rescan on one HBA on all channels, all targets and LUNs, execute the following command:
echo “- – -” > /sys/class/scsi_host/host0/scan
If your disk is still not recognized, execute the same command for the rest of HBAs:
echo “- – -” > /sys/class/scsi_host/host1/scan
echo “- – -” > /sys/class/scsi_host/host2/scan
Host bus adapter on Linux servers
Now execute fdisk -l to see if the disk was indeed detected by the machine:
logical volume manager for the Linux kernel
My VM has now detected a secondary physical disk named /dev/sdb with a size of 21.5 GB. Now will partition our newly added disk by executing fdisk /dev/sdb:
Partition physical disks on Linux servers
Press n to  add a new partition then press either e for extended or p for primary partition. Create a primary partition, set the partition number and the first and last cylinders. Once the partition has been created, press p when returned to the fdisk menu to view the newly created partition on the physical disk:
How to format Linux physical disk
Remember that our /dev/sda2 partition had a 8e (Linux LVM) ID so to extend this partition we’ll need to set the same ID on our disk. Press t when in fdisk menu to change a partition’s system id, l to view the list codes and then type the needed partition ID:
Linux physical disk partition ID
If you now press p again you will see that the partition ID has been changed to 8e (Linux VM):
CentOS physical disk partition ID
To write changes to disk press w. Execute fdisk -l to to view the changes applied to the disk:
How to extend logical volumes on CentOS
Now we’ll need to create a physical volume for our new  /dev/sdb1 partition. To achieve this result execute pvcreate /dev/sdb1. Then type pvdisplay to view the newly created physical volume:
Linux physical volume
On the physical volumes we attach volume groups. Note that you can assign multiple physical volumes to a volume group. Type vgdisplay to view the existing volume groups:
Display volumes groups on CentOS
As you can see from the command’s output, my volume group is named vg_linuxvm. You can create a new volume group on a physical volume by executing vgcreate name physical_volumes just like in the following example: vgcreate volume_group1 /dev/sdb4 /dev/sdc3
Use pvscan to rescan for physical volumes and view the newly created one:
How to scan physical volumes
To extend the vg_linuxvm volume group, we’ll have to execute the vgextend vg_linuxvm /dev/sdb1 command. After this operation is completed, type pvdisplay again to see if the VG name has been allocated to the /dev/sdb1 physical volume:
Physical volumes on Linux servers
Now execute vgdisplay to view the new size of the vg_linuxvm volume group:
Display CentOS volume groups
On top of the volume groups we create the logical volumes, you can view them by executing lvdisplay command:
View logical volumes on Linux servers
We can extend the logical volume to a certain size or use the whole /dev/sdb1 partition:
lvextend -L+18G /dev/vg_linuxvm/lv_root
or
lvextend /dev/vg_linuxvm/lv_root /dev/sdb1
Extend logical volume on CentOs
The last thing we’ll have to do is resize the file system on the /dev/vg_linuxvm/lv_root logical volume so the newly added size is recognized by the Operating System. Execute resize2fs /dev/vg_linuxvm/lv_root and then df -h to see how the logical volume size has increased:
Resize file system command on CentOs
The operation has now been completed and the logical volume has been extended. To summarize this operation you will need to remember that there are four layers when talking about extending a logical volume: hard drives / disk partitions / physical volumes / volume groups and logical volumes. You add a new physical disk to a machine, you assign one or more partitions on that physical disk then you create physical volumes from a particular partition. The physical volumes created are assigned to one volume group (you can assign multiple physical volumes to a single volume group) and from the volume groups we create the logical volumes. You can view this hierarchy by executing lsblk:
Linux logical volumes