Thursday, March 20, 2014

RHEL 6 install Xvfb

xorg-x11-server-Xfvb is not in the standard RHEL 6 repositories.  If you wish to install it you will need to enable the repository.  Perform the following:-

# subscription-manager repos --enable rhel-6-server-optional-rpms
Repo rhel-6-server-optional-rpms is enabled for this system.
# yum search xvfb
Loaded plugins: product-id, security, subscription-manager
This system is receiving updates from Red Hat Subscription Management.
rhel-6-server-cf-tools-1-rpms                                       | 2.8 kB     00:00
rhel-6-server-optional-rpms                                         | 3.5 kB     00:00
rhel-6-server-optional-rpms/primary_db                              | 2.7 MB     00:00
rhel-6-server-rpms                                                  | 3.7 kB     00:00
rhel-6-server-rpms/primary_db                                       |  25 MB     00:03
==================================== N/S Matched: xvfb ====================================
xorg-x11-server-Xvfb.x86_64 : A X Windows System virtual framebuffer X server.

  Name and summary matches only, use "search all" for everything.
# yum install xorg-x11-server-Xvfb
Loaded plugins: product-id, security, subscription-manager
This system is receiving updates from Red Hat Subscription Management.
rhel-6-server-cf-tools-1-rpms                                       | 2.8 kB     00:00
rhel-6-server-optional-rpms                                         | 3.5 kB     00:00
rhel-6-server-rpms                                                  | 3.7 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package xorg-x11-server-Xvfb.x86_64 0:1.13.0-23.1.el6_5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================
 Package                Arch     Version               Repository                     Size
===========================================================================================
Installing:
 xorg-x11-server-Xvfb   x86_64   1.13.0-23.1.el6_5     rhel-6-server-optional-rpms   775 k

Transaction Summary
===========================================================================================
Install       1 Package(s)

Total download size: 775 k
Installed size: 1.9 M
Is this ok [y/N]: y
Downloading Packages:
xorg-x11-server-Xvfb-1.13.0-23.1.el6_5.x86_64.rpm                   | 775 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : xorg-x11-server-Xvfb-1.13.0-23.1.el6_5.x86_64                           1/1
rhel-6-server-rpms/productid                                        | 1.7 kB     00:00
  Verifying  : xorg-x11-server-Xvfb-1.13.0-23.1.el6_5.x86_64                           1/1

Installed:
  xorg-x11-server-Xvfb.x86_64 0:1.13.0-23.1.el6_5

Complete!

Monday, February 17, 2014

SSH tunnel using putty

In order to create an SSH tunnel from your Windows box to a remote Linux box do the following:-

Start up Putty and navigate to Connection --> SSH --> Tunnels and add in required port numbers (this example is for connecting to port 5901 on a remote server).  Don't forget to click the Add button:-









Then return to the Sessions and enter the Host Name (or IP address) of the target server.  Once you log on Putty will create a tunnel for you.

Don't forget you can save the above in Putty if you need to re-use it.

Friday, February 14, 2014

Convert line endings from dos to unix in vim

To convert line endings from dos to unix in vim open your file, then:-

:update
:e ++ff=dos
:setlocal ff=unix
:wq


Thursday, February 13, 2014

RPM commands


Query a package via rpm:
[root@sbt-centos tmp]# rpm -q openssh-server
openssh-server-5.3p1-84.1.el6.x86_64


Get information on a package
[root@sbt-centos tmp]# rpm -qi openssh-server
Name        : openssh-server               Relocations: (not relocatable)
Version     : 5.3p1                             Vendor: CentOS
Release     : 84.1.el6                      Build Date: Fri 22 Feb 2013 03:51:49 AM GMT
Install Date: Sat 12 Oct 2013 04:25:50 PM BST      Build Host: c6b9.bsys.dev.centos.org
Group       : System Environment/Daemons    Source RPM: openssh-5.3p1-84.1.el6.src.rpm
Size        : 667631                           License: BSD
Signature   : RSA/SHA1, Sat 23 Feb 2013 05:40:05 PM GMT, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.openssh.com/portable.html
Summary     : An open source SSH server daemon
Description :
OpenSSH is a free version of SSH (Secure SHell), a program for logging
into and executing commands on a remote machine. This package contains
the secure shell daemon (sshd). The sshd daemon allows SSH clients to
securely connect to your SSH server.


List files installed by a package
[root@sbt-centos tmp]# rpm -ql openssh-server
/etc/pam.d/ssh-keycat
/etc/pam.d/sshd
/etc/rc.d/init.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/usr/libexec/openssh/sftp-server
/usr/libexec/openssh/ssh-keycat
/usr/sbin/.sshd.hmac
/usr/sbin/sshd
/usr/share/doc/openssh-server-5.3p1
/usr/share/doc/openssh-server-5.3p1/HOWTO.ssh-keycat
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
/var/empty/sshd


List configuration files for a package
[root@sbt-centos tmp]# rpm -qc openssh-server
/etc/pam.d/ssh-keycat
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd

List documentation for a package
[root@sbt-centos tmp]# rpm -qd openssh-server
/usr/share/doc/openssh-server-5.3p1/HOWTO.ssh-keycat
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz



Show the change log for a package
[root@sbt-centos tmp]# rpm -q --changelog openssh-server 
* Thu Dec 13 2012 Petr Lautrbach <plautrba@redhat.com> 5.3p1-84.1
- Add a 'netcat mode' (ssh -W) (#860809)

* Mon Nov 12 2012 Petr Lautrbach <plautrba@redhat.com> 5.3p1-83
- fix the required authentications patch (#869903)

* Fri Oct 12 2012 Petr Lautrbach <plautrba@redhat.com> 5.3p1-82
- check return value of PK11_Authenticate in ssh-add -n (#782912)
- document available methods to RequiredAuthentications[12] (#821641)
- fix ssh-copy-id (#836650)

</snip>

List the installed packages in date order:-
[root@sbt-centos tmp]# rpm --last -qa | more
tigervnc-server-1.1.0-8.el6_5.x86_64          Wed 05 Feb 2014 04:26:45 PM GMT
tomcat6-6.0.24-62.el6.noarch                  Thu 30 Jan 2014 11:50:04 AM GMT
tomcat6-lib-6.0.24-62.el6.noarch              Thu 30 Jan 2014 11:50:03 AM GMT
tomcat6-el-2.1-api-6.0.24-62.el6.noarch       Thu 30 Jan 2014 11:50:03 AM GMT

Wednesday, February 5, 2014

Reduce LV and File System

At some point you may need to free up some LV space, but you will also need to reduce the underlying filesystem too.  Here's what to do...

Check the current space usage and see if any can be used:-

[root@sbt-centos ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_sbtcentos-lv_root
                       50G  3.9G   43G   9% /
tmpfs                 940M  372K  939M   1% /dev/shm
/dev/sda1             485M   91M  369M  20% /boot
/dev/mapper/vg_sbtcentos-lv_home
                       45G  3.6G   40G   9% /home
/dev/mapper/vg_sbtcentos-lv_data
                      985M   18M  918M   2% /data



Check the LV:-
 
[root@sbt-centos ~]# lvs
  LV      VG           Attr      LSize    Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_data vg_sbtcentos -wi-ao--- 1000.00m                                            
  lv_home vg_sbtcentos -wi-ao---   45.57g                                            
  lv_root vg_sbtcentos -wi-ao---   50.00g                                            
  lv_swap vg_sbtcentos -wi-ao---    3.94g                                            



It looks like /data has some free, lets reduce that.  Unmount it first:-

[root@sbt-centos ~]# umount /data/


Do an lvreduce, but don't forget the -r, this will resize the underlying filesystem at the same time:-

[root@sbt-centos ~]# lvreduce -L -512M /dev/vg_sbtcentos/lv_data -r
fsck from util-linux-ng 2.17.2
/dev/mapper/vg_sbtcentos-lv_data: 11/64000 files (0.0% non-contiguous), 8438/256000 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_sbtcentos-lv_data to 124928 (4k) blocks.
The filesystem on /dev/mapper/vg_sbtcentos-lv_data is now 124928 blocks long.

  Reducing logical volume lv_data to 488.00 MiB
  Logical volume lv_data successfully resized


Remount the filesystem:-
 
[root@sbt-centos ~]# mount /dev/vg_sbtcentos/lv_data /data/

And check space usage:-

[root@sbt-centos ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_sbtcentos-lv_root
                       50G  3.9G   43G   9% /
tmpfs                 940M  372K  939M   1% /dev/shm
/dev/sda1             485M   91M  369M  20% /boot
/dev/mapper/vg_sbtcentos-lv_home
                       45G  3.6G   40G   9% /home
/dev/mapper/vg_sbtcentos-lv_data
                      481M   17M  439M   4% /data
[root@sbt-centos ~]# lvs
  LV      VG           Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_data vg_sbtcentos -wi-ao--- 488.00m                                            
  lv_home vg_sbtcentos -wi-ao---  45.57g                                            
  lv_root vg_sbtcentos -wi-ao---  50.00g                                            
  lv_swap vg_sbtcentos -wi-ao---   3.94g  




Resize LV Swap space

Check out current size of volume group - is there enough space to extend the swap?

[root@sbt-centos ~]# vgs
  VG           #PV #LV #SN Attr   VSize  VFree
  vg_sbtcentos   1   3   0 wz--n- 99.51g    0 


 No free space on the VG.  So add another disk to the VG:-

[root@sbt-centos ~]# vgextend vg_sbtcentos /dev/sdb
  No physical volume label read from /dev/sdb
  Physical volume "/dev/sdb" successfully created
  Volume group "vg_sbtcentos" successfully extended



Check space has been added:-

[root@sbt-centos ~]# vgs
  VG           #PV #LV #SN Attr   VSize   VFree 
  vg_sbtcentos   2   3   0 wz--n- 100.50g 1020.00m



Check current swap size:-

[root@sbt-centos ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1878        523       1354          0         28        184
-/+ buffers/cache:        310       1568
Swap:         4031          0       4031



Turn off the swap device:-

[root@sbt-centos ~]# swapoff -v /dev/vg_sbtcentos/lv_swap
swapoff on /dev/vg_sbtcentos/lv_swap

Resize the LV that the swap lives on:-

[root@sbt-centos ~]# lvresize -L +512M /dev/vg_sbtcentos/lv_swap
  Extending logical volume lv_swap to 4.44 GiB
  Logical volume lv_swap successfully resized


Recreate the swapspace on the extended swap LV (note the UUID has changed, if you use UUID in /etc/fstab you'll have to amend accordingly):-

[root@sbt-centos ~]# mkswap /dev/vg_sbtcentos/lv_swap
mkswap: /dev/vg_sbtcentos/lv_swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 4653052 KiB
no label, UUID=3e5bd2cf-048e-4c8b-a631-a00ef6a5664a




And turn the swap device back on:-

[root@sbt-centos ~]# swapon -va
swapon on /dev/mapper/vg_sbtcentos-lv_swap
swapon: /dev/mapper/vg_sbtcentos-lv_swap: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/mapper/vg_sbtcentos-lv_swap: pagesize=4096, swapsize=4764729344, devsize=4764729344



And finally, show the new swap space:-

[root@sbt-centos ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1878        523       1354          0         28        184
-/+ buffers/cache:        310       1568
Swap:         4543          0       4543


Alternatively, if there's spare space on an LV it could be reduced and allocated to the swap LV.  See here http://linuxscrapbook.blogspot.co.uk/2014/02/reduce-lv-and-file-system.html

Monday, February 3, 2014

Resize swap Logical Volume

Check existing swap size:-

# free -m
# cat /proc/swaps


Disable swapping for the logical volume:-

# swapoff -v /dev/vg_001/lv_swap

Resize the LVM2 logical volume as required:-

# lvm lvresize /dev/vg_001/lv_swap -L +2G

Make the LV a swap drive:-

# mkswap /dev/vg_001/lv_swap

Enable the swap:-

# swapon -va

Check the new size of the swap:-

# free -m
# cat /proc/swaps