‏הצגת רשומות עם תוויות centos. הצג את כל הרשומות
‏הצגת רשומות עם תוויות centos. הצג את כל הרשומות

יום שלישי, 25 במרץ 2014

Hide the Apache Web Server Version number with ServerSignature and ServerTokens directives

You can easily hide Apche (httpd) version number and other information. There are two config directives that controls Apache version. The ServerSignature directive adds a line containing the Apache HTTP Server server version and the ServerName to any server-generated documents, such as error messages sent back to clients. ServerSignature is set to on by default. The ServerTokens directive controls whether Server response header field which is sent back to clients includes a description of the generic OS-type of the server as well as information about compiled-in modules. By setting this to Prod you only displays back Apache as server name and no version number displayed back.
Open your httpd.conf file using text editor such as vi:
vi httpd.conf
Append/modify config directive as follows:
ServerSignature Off
ServerTokens Prod
Save and close the file. Restart Apache web server:
# /etc/init.d/httpd restart

Thanks to nixCraft from cyberciti

יום ראשון, 23 במרץ 2014

CentOS policy routing

Over the years working in LAN networking there are several situations that dictate a host/server have multiple IP addresses on the same or different, physical or logical, devices.  For instance, connecting to a private management-only network/vlan, offering connectivity to a inside network on a private NIC, etc etc.


This scenario often causes two somewhat annoying behaviours:

1) the return traffic often is sourced from the “primary” IP address of the host/server, most often the one that is on the subnet associated with the default gateway
2) a surprising number of alleged “network administrators” seem to think having multiple gateways (one for each IP address of course )  is a good idea.  Well, over the years I have come across this situation and, in every case, this has obviously  NEVER WORKED.  

Situation #2 can only be fixed by education and occasionally the dismissal of the “IT” person for someone more qualified.  As for situation #1, RedHat/CentOS supports viaiproute2 the ability to make traffic rules, ensuring that IP traffic is sourced by a particular IP in cases you can define.  Great!  Multiple NIC or logical interface routing on Linux is possible! (and yes, it involves having multiple gateways, but not stupidly and blindly adding them in the routing table….)
It is very simple to implement and involves the steps below.  As an example, lets assume we created a management VLAN (VLAN4) and want to add an logical interface on a server in that VLAN to access it internally.  We will be using 10.0.10.0/28 as an inside network.

Step 1: Create a VLAN interface

This creates the necessary interface on VLAN4 from primary physical interface eth0:
vi /etc/sysconfig/network-scripts/ifcfg-eth0.4
DEVICE=eth0.4
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
IPV6INIT=no
IPADDR=10.0.10.2
NETMASK=255.255.255.240
NETWORK=10.0.10.0
VLAN=yes

Step 2: Create a iproute2 table for that management network

Edit /etc/iproute2/rt_tables to add a new entry and give it a arbitrary (unused ;) ) name:
vi /etc/iproute2/rt_tables
#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
200     MGMT
Note that between 200 and MGMT is a tab character.

Step 3: Create a default route for that network

vi /etc/sysconfig/network-scripts/route-eth0.4
default table MGMT via 10.0.10.1
this creates a default route for the MGMT/10.0.10.0/28 network to 10.0.10.1 which is your inside routing intelligence.

Step 4: Create routing rule for 10.0.10.2

To ensure that traffic received on 10.0.10.2 is utilizing the MGMT network only as a source address, a rule must be defined to enable this:
vi /etc/sysconfig/network-scripts/rule-eth0.4
from 10.0.10.2 table MGMT

and thats it!  restart your network:
/etc/rc.d/init.d/network restart

Using iproute2 commands, we can check that what we did works (as well as using wireshark ;) )

[root@server network-scripts]# ip rule show
0:      from all lookup local
32765:  from 10.0.10.2 lookup MGMT
32766:  from all lookup main
32767:  from all lookup default
 
[root@server network-scripts]# ip route show
10.0.10.0/28 dev eth0.4  proto kernel  scope link  src 10.0.10.2
66.1.1.0/25 dev eth0  proto kernel  scope link  src 66.1.1.12
169.254.0.0/16 dev eth0  scope link  metric 1002
169.254.0.0/16 dev eth0.4  scope link  metric 1006
default via 66.1.1.125 dev eth0

Note: this also would work with a second physical interface, for instance to utilize a second NIC card instead of a VLAN logical interface, substitute all use of eth0.4 for eth1.
Thanks to: ChrisConn

יום רביעי, 26 בפברואר 2014

Setup NFS Server On CentOS 6.X

NFS, Network File System, is a server-client protocol used for sharing files between linux/unix to unix/linux systems. NFS enables you to mount a remote share locally. You can then directly access any of the files on that remote share.
nfs
Scenario
In this how-to I use two systems running with CentOS 6.5, but it will work on all CentOS / RHEL / Scientific Linux 6.x distros.
NFS Server IP Address: 192.168.1.250/24
NFS Client IP Address: 192.168.1.251/24
1. Install NFS in Server system
# yum install nfs* -y
 2. Start NFS service
# service rpcbind start
# chkconfig rpcbind on
hkconfig nfs on
# service nfs start
#
c
3. Install NFS in Client System
# yum install nfs* -y
4. Start NFS service
# service rpcbind start
# chkconfig rpcbind on
hkconfig nfs on
# service nfs start
#
c
5. Create shared directories in server
Create a shared directory named ‘/var/unixmen_share’ in server and let the client users to read and write files in that directory.
# mkdir /var/unixmen_share
# chmod 755 /var/unixmen_share/
6. Export shared directory on NFS Server
Edit file /etc/exports,
# vi /etc/exports
Add the entry as shown below.
/var/unixmen_share/     192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
 where,
/var/unixmen_share  – shared directory
192.168.1.0/24           – IP address range of clients
rw                               – Writable permission to shared folder
sync                            – Synchronize shared directory
no_root_squash          – Enable root privilege
no_all_squash             – Enable user’s authority
7. Restart the NFS service.
# service nfs restart
 8. Mount the share directory in client
Create a mount point to mount the share directory ‘var/unixmen_local’ which we created in the earlier step 5.
# mkdir /var/nfs_share
 Mount the share from server to client as shown below
# mount -t nfs 192.168.1.250:/var/unixmen_share/ /var/nfs_share/
mount.nfs: Connection timed out
Probably it will show a connection timed out error which means that the firewall is blocking NFS server. To allow NFS server to access from outbound, goto NFS server system and add the as shown below in the ‘etc/sysconfig/iptables’ file.
# vi /etc/sysconfig/iptables
Append the following lines shown in red colour.
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 32803 -j ACCEP
T
-A INPUT -m state --state NEW -m tcp -p tcp --dport 875 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 662 -j ACCEP
T
INPUT ACCEPT [0:0]
::FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
tate ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j
-A INPUT -m state --
sACCEPT
-A INPUT -i lo -j ACCEPT
tcp -p tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with
-A INPUT -m state --state NEW -m
icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Now restart the iptables service.
# service iptables restart
Again mount the share in client system with command:
# mount -t nfs 192.168.1.250:/var/unixmen_share/ /var/nfs_share/
Now the NFS share will mount without any connection timed out error.
9. Verify NFS
Verify the share from the server is mounted or not using ‘mount’ command.
# mount
Sample output:
/dev/mapper/vg_client-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
devpts on /dev/pts type devpt
sysfs on /sys type sysfs (rw) s (rw,gid=5,mode=620)
:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) none on /proc/sys
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_ u/fs/binfmt_misc type binfmt_misc (rw)
rpc_pipefs (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.1.250:/var/unixmen_share/ on /var/nfs_share type nfs (rw,vers=4,addr=192.168.1.250,clientaddr=192.168.1.251)
10.  Automount the Shares
To mount the shares automatically instead of mounting them manually at every reboot, add the following lines shown in red colour in the ‘/etc/fstab’ file of your client system.
# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Mar 3 22[root@client unixmen]:10:15 2013
#
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/vg_client-lv_root / ext4 defaults 1 1
/
defaults 1 2 /dev/mapper/vg_client-lv_swap swap swap defaults 0 0
UUID=1aa7d041-056b-48f4-a773-f713759e981f /boot ext4
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
192.168.1.250:/var/unixmen_share/ /var/nfs_share/ nfs rw,sync,hard,intr 0 0
Reboot the client system and check the share whether it is automatically mounted or not.
# mount
Sample output:
/dev/mapper/vg_client-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
devpts on /dev/pts type devpt
sysfs on /sys type sysfs (rw) s (rw,gid=5,mode=620)
:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) none on /proc/sys
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_ u/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.1.250:/var/unixmen_share/ on /var/nfs_share type nfs (rw,vers=4,addr=192.168.1.250,clientaddr=192.168.1.251)
Thanks to: sk from unixmen

יום ראשון, 2 בפברואר 2014

Change Timezone in CentOS

First, make a backup of the existing localtime file. It’s always good practice to make backups of original config files.

# mv /etc/localtime /etc/localtime.bak

Next, create the link:

# ln -s /usr/share/zoneinfo/Asia/Jerusalem /etc/localtime

Now you just need to test your change. Run “date” from the command line, and ensure that the appropriate time, date, and timezone are reported.

יום שלישי, 21 בינואר 2014

Install REMI Repository On RHEL / CentOS / Linux 6.x

Let see how to add REMI repository which is created and maintained by a French guy named Remi Collect. 

REMI repository is free to use and is very stable.

Install REMI Repository On RHEL / CentOS
Please be mindful that you should use REMI repository along with EPEL repository. Otherwise you may end up with dependency problem sometimes.

On Enterprise Linux 6 i386 or x86_64:
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# rpm -Uvh remi-release-6.rpm
# for RHEL only
# rhn-channel --add --channel=rhel-$(uname -i)-server-optional-6
On Enterprise Linux 5 i386 or x86_64:
# wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
# rpm -Uvh remi-release-5.rpm
Enable REMI repository
Edit file remi.repo,
# vi /etc/yum.repos.d/remi.repo
Find the line enabled =0 and change it to 1 to enable REMI repository.
[...]
enabled=1
[...]
Save and close the file.
Now list out the installed repositories with command:
# yum repolist
Sample output:
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirror.leapswitch.com
extras: mirror.leapswitch.c
 * epel: epel.mirror.net.in
 *
om
 * remi: mirror.smartmedia.net.id
id                              
 * updates: mirror.leapswitch.com
rep
o                    repo name                                                                                       status
base                                                     CentOS-6 - Base                                                                                 4,802
epel                                                     Extra Packages for Enterprise Linux 6 - i386                                                    8,385
extras                                                   CentOS-6 - Extras                                                                                  12
remi                                                     Les RPM de remi pour Enterprise Linux 6 - i386                                                  1,362
updates                                                  CentOS-6 - Updates                                                                                211
repolist: 14,772

Thank to : 
http://www.unixmen.com/install-remi-repository-rhel-centos-scientific-linux-6-x-5-x-fedora-20-19-18/


Install EPEL Repository On RHEL / CentOS / linux 6.x

EPEL stands for Extra Packages for Enterprise Linux. It is a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux such as Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL). EPEL repository has more than 8000 packages and it was started by some Fedora contributors mainly for using Fedora packages they maintain on RHEL and it’s derivatives.
EPEL works closely with Fedora project and uses the same guidelines, rules, policies, and infrastructure, as far as possible. EPEL packages are usually based on their Fedora counterparts and will never conflict with or replace packages in the base Enterprise Linux distributions. It can be used by any Linux user to install packages that exist in Fedora and were not included in a RHEL version .
Adding EPEL Repository to RHEL / CentOS /  Linux 6.x
EPEL is available as rpm, therefore you can install it on your system. You don’t have to manually add any entries on /etc/yum.repos.d/ directory of your system. Since it is available as noarch rpm, you can install it on both 32 and 64 bit systems. I tested this how-to on CentOS 6.5, however it will work on all 6.x versions.

Download the latest EPEL rpm and install it as shown below.
# wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -Uvh epel-release-6-8.noarch.rpm
Adding EPEL Repository to RHEL / CentOS / Scientific Linux 5.x
First go to the EPEL repository download page. Download the latest EPEL rpm and install it as shown below.
# wget http://epel.mirror.net.in/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -Uvh epel-release-5-4.noarch.rpm
Now list out the installed repositories using command:
# yum repolist
Sample output:

Loaded plugins: fastestmirror, security Determining fastest mirrors  * base: mirror.leapswitch.com  * epel: epel.mirror.net.in  * extras: mirror.leapswitch.com  * updates: mirror.leapswitch.com repo id                                                   repo name                                                                                      status base                                                      CentOS-6 - Base                                                                                4,802 epel                                                      Extra Packages for Enterprise Linux 6 - i386                                                   8,385 extras                                                    CentOS-6 - Extras                                                                                 12 updates                                                   CentOS-6 - Updates                                                                               211 repolist: 13,410

Thanks to: http://www.unixmen.com/install-epel-repository-rhel-centos-scientific-linux-6/

יום שני, 16 בדצמבר 2013

Resizing a GPT partition with a ext4 filesystem [CentOS / RedHat]


1. Run parted on your device: parted /dev/sdX
2. Change display unit to sectors: unit s
3. Print current partition table and note the start sector for your partition: p
4. Delete your partition (won't delete the data or filesystem): rm <number>
5. Recreate the partition with the starting sector from above: mkpart primary <start> <end>
6. Exit parted: quit
7. Check the filesystem: sudo e2fsck -f /dev/sdXX
8. Resize filesystem: sudo resize2fs /dev/sdXX

Creating a Partition Size Larger Than 2TB [CentOS / RedHat]

You cannot create a Linux partition larger than 2 TB using the fdisk command. The fdisk won't create partitions larger than 2 TB. 

Here is an example how to create partition with 3.21 TB size:

1. fdisk -l /dev/sdb
2. parted /dev/sdb
3. (parted) mklabel gpt
4. (parted) unit TB
5. (parted) mkpart primary 0.00TB 3.21TB
6. (parted) print
7. mkfs.ext4 /dev/sdb1
8. # mkdir /data
   # mount /dev/sdb1 /data
   # df -H

יום ראשון, 16 ביוני 2013

How to generate CPU load?


Sometimes, system administrators are asked to generate 'dummy' load on CPU to test the load vs performance. Here is a short example which shows how to generate load per CPU or per Core basis (actually threads):



 # perl -e 'while (--$ARGV[0] and fork) {}; while () {}' 4


The last digit "4" in this case indicates how many CPUs or threads or cores you want to load by this method. This indeed is a good idea to test the CPU performance when some of the threaded/virtual CPUs are loaded.

When I gave the above command, in other terminal window for same server, I can observe something like this:

# mpstat 5
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0    0   0   10   213  105   17    0    0    0    0    38    0   2   0  98
  1    0   0    0     1    0    0    0    0    0    0     0    0   0   0 100
  2    0   0    0     2    0    2    0    0    0    0     0    0   0   0 100
  3    0   0    0     1    0    0    0    0    0    0     0    0   0   0 100
  4    0   0    0     2    0    2    0    0    0    0     5    0   0   0 100
  5    0   0    3     4    0    6    0    0    0    0     0    0   0   0 100
  6    0   0    1    13    6   11    0    0    0    0     0    0   0   0 100
  7    0   0    4     3    0    4    0    0    0    0    10    0   0   0 100
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0   21   7  139   227  118   18    9    0    1    0    53   85   1   0  14
  1    4   0    7     9    0   16    0    4    0    0     4    1   1   0  98
  2   10   0    0     8    0    5    5    0    1    0     1   85   0   0  15
  3    0   1   34     7    0   11    0    1    0    0     3    0   0   0 100
  4    6   0    0     6    0    2    4    0    0    0     4   84   0   0  16
  5    7   0    0     2    0    1    0    1    1    0     1    0   0   0 100
  6   10   0    4    12    5    3    5    0    0    0     1   85   0   0  15
  7    0   0   21    16    0   31    0    0    0    0    10    0   0   0 100
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0    0   0   30   207  106    0    8    0    0    0     0  100   0   0   0
  1    0   0    0     9    0   15    0    1    0    0    23    0   1   0  99
  2    0   0    0     6    0    0    5    0    0    0     0  100   0   0   0
  3    0   0    3     8    0   13    0    1    0    0    12    0   0   0 100
  4    0   0    0     6    0    0    5    0    0    0     0  100   0   0   0
  5    0   0    0     2    0    0    0    0    0    0     0    0   0   0 100
  6    0   0    1    10    3    2    7    0    0    0     0  100   0   0   0
  7    0   0    0     1    0    0    0    0    0    0     0    0   0   0 100
^C


The 'top' command output in this case will look like following:
# top
last pid:   698;  load avg:  1.61,  0.44,  0.19;       up 25+19:31:24                                                                             10:59:01
34 processes: 29 sleeping, 5 on cpu
CPU states: 49.8% idle, 50.0% user,  0.2% kernel,  0.0% iowait,  0.0% swap
Memory: 8192M phys mem, 6680M free mem, 4099M total swap, 4099M free swap

   PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
   694 root       1   0    0 6368K 3256K cpu/0    0:35 12.50% perl
   696 root       1   0    0 6360K 1672K cpu/7    0:35 12.45% perl
   697 root       1   0    0 6360K 1672K cpu/1    0:35 12.45% perl
   695 root       1   0    0 6360K 1800K cpu/6    0:35 12.14% perl
   698 root       1  59    0 2944K 2104K cpu/3    0:00  0.03% top
   679 root       1  59    0   10M 3576K sleep    0:00  0.00% sshd
   119 root      24  59    0 4576K 4232K sleep    1:25  0.00% nscd
     9 root      15  59    0   10M 9704K sleep    0:42  0.00% svc.configd
   238 root       4  59    0 7888K 4664K sleep    0:29  0.00% inetd
     7 root      12  59    0   13M 9904K sleep    0:34  0.00% svc.startd
   302 root      16  59    0   15M 9400K sleep    0:27  0.00% fmd
   202 root       1  59    0 1360K 1176K sleep    0:04  0.00% utmpd
   183 daemon     1  59    0 2848K 2360K sleep    0:11  0.00% rpcbind
   253 root       3  59    0 7464K 3160K sleep    0:08  0.00% automountd
     1 root       1  59    0 2512K 1920K sleep    0:05  0.00% init