Automated shutdown of ESXi and VMs through Powershell

Estimated Reading Time: 3 minutes

My friend was running a cybercafe center. He has dozens of ESXi running 100 of VMs. He was using Dell Multi-UPS Management console to handle his small computer center. The very often power cut was ruining his business. He called up me to see there is a possible solution to handle graceful shutdown of VMs and then ESXi through the available tools and technique. This solution really helped us to handle the situation gracefully.

I just noted down the steps roughly and will not be late to share it with you:

1. Download the Dell Multi-UPS Management Console from http://www.dell.com/support/home/us/en/19/Drivers/DriversDetails?driverId=R318771

2. Execute DELL_MULTI-DEVICE_A00_R318771.exe and run the setup to install on Windows 2008 R2.

3. Once installed, try accessing it through:

http://127.0.0.1:4679/default.html

4. The default credential for the MUMC login is admin/admin

5.A quick scan is automatically performed and you will get to see the overall power devices available.

6. Click on Settings > Systems and enable shutdown as shown below

7. Click on Shutdown option and configure as shown below

The above shown is a sample entry. Change it as per your required IPs.

In our case, that’s :

Power Source: 192.168.1.99

Load Segment: Master Output

Login/password: admin/admin

Shutdown timer : 180 sec

Shutdown duration: 120 sec

Type: Script

Location: C:\scripts/Ajeet.bat

8. Save the settings

9. Now let’s create a required scripts one by one for shutting down ESXi and VMs.

Script 1:

location: C:\scripts\Ajeet.bat

Start shutdownvms.bat

Script 2:

location: C:\scripts\shutdownvms.bat

———- Start——–

PowerShell.exe C:\Scripts\shutdownallvms.ps1

———End————–

Script 3:

Location:C:\scripts\shutdownallvms.ps1

========= START =========

Add-Snappin “Vmware. Automation.Core”

Connect-VIServer IPADDRESS

# Get All the ESX Hosts

$ESXSRV = Get-VMHost

# For each of the VMs on the ESX hosts

Foreach ($VM in ($ESXSRV | Get-VM)){

# Shutdown the guest cleanly

$VM | Shutdown-VMGuest -Confirm:$false

}

# Set the amount of time to wait before assuming the remaining powered on guests are stuck

$waittime = 200 #Seconds

$Time = (Get-Date).TimeofDay

do {

# Wait for the VMs to be Shutdown cleanly

sleep 1.0

$timeleft = $waittime – ($Newtime.seconds)

$numvms = ($ESXSRV | Get-VM | Where { $_.PowerState -eq “poweredOn” }).Count

Write “Waiting for shutdown of $numvms VMs or until $timeleft seconds”

$Newtime = (Get-Date).TimeofDay – $Time

} until ((@($ESXSRV | Get-VM | Where { $_.PowerState -eq “poweredOn” }).Count) -eq 0 -or ($Newtime).Seconds -ge $waittime)

# Shutdown the ESX Hosts

$ESXSRV | Foreach {Get-View $_.ID} | Foreach {$_.ShutdownHost_Task($TRUE)}

Write-Host “Shutdown Complete”

===== END ========

10. Now its time to test drive the scripts. Just try running those script manually and confirm if those works or not.

11. Now time to test drive with UPS System menu option. Click on Shutdown option of MUMC and Click on Test Shutdown. The Script should work and power-on VMs and ESXi gradually.

12. Try creating the power-off situation and let UPS perform this activity of running the scripts to shutdown ESXi and VMs.

It really went flawless saving couple of rupees for my friend. He treated me the next day for the overall efforts and we rocked the party too 🙂

Installing Java Development Toolkit (JDK) on Linux

Estimated Reading Time: 4 minutes

Installing Java Development toolkit on Linux is always matter of difficulty since Oracle provides both RPM and tarballs in their official website. Installing RPM is pretty simple but installing through tarballs need sufficient environmental variable declaration which is little different from Windows Operating System.

javalinux

Follow the steps mentioned below to install java-1.6.

1.Download jdk-6u16-linux-x64.bin (From the URL mentioned in the prerequisites section) to /opt directory.

2.Change the permission of jdk-6u16-linux-x64.bin file to 755.

[root@bang opt]# chmod 755 jdk-6u16-linux-x64.bin

3.Execute the jdk-6u16-linux-x64.bin file to start installation.

[root@bang opt]# ./jdk-6u16-linux-x64.bin

Sun Microsystems, Inc. Binary Code License Agreement

for the JAVA 2 PLATFORM STANDARD EDITION DEVELOPMENT KIT 6.0

SUN MICROSYSTEMS, INC. (“SUN”) IS WILLING TO LICENSE THE

SOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITION

THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS BINARY

CODE LICENSE AGREEMENT AND SUPPLEMENTAL LICENSE TERMS

(COLLECTIVELY “AGREEMENT”). PLEASE READ THE AGREEMENT

CAREFULLY. BY DOWNLOADING OR INSTALLING THIS SOFTWARE, YOU

ACCEPT THE TERMS OF THE AGREEMENT. INDICATE ACCEPTANCE BY

SELECTING THE “ACCEPT” BUTTON AT THE BOTTOM OF THE

AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY ALL THE

TERMS, SELECT THE “DECLINE” BUTTON AT THE BOTTOM OF THE

AGREEMENT AND THE DOWNLOAD OR INSTALL PROCESS WILL NOT

CONTINUE.

1. DEFINITIONS. “Software” means the identified above in

binary form, any other machine readable materials

(including, but not limited to, libraries, source files,

header files, and data files), any updates or error

corrections provided by Sun, and any user manuals,

programming guides and other documentation provided to you

by Sun under this Agreement. “General Purpose Desktop

Computers and Servers” means computers, including desktop,

laptop and tablet computers, or servers, used for general

computing functions under end user control (such as but not

specifically limited to email, general purpose Internet

browsing, and office suite productivity tools). The use of

Software in systems and solutions that provide dedicated

functionality (other than as mentioned above) or designed

for use in embedded or function-specific software

applications, for example but not limited to: Software

embedded in or bundled with industrial control systems,

wireless mobile telephones, wireless handheld devices,

kiosks, TV/STB, Blu -ray Disc devices, telematics and

network control switching equipment, printers and storage

management systems, and other related systems are excluded

from this definition and not licensed under this Agreement.

“Programs” means Java technology applets and applications

intended to run on the Java Platform Standard Edition (Java

SE) ptaform on Java-enabled General Purpose Desktop

Computers and Servers.

4.Press the Tab key until you reach the End of License Agreement Screen

5.Type yes and hit Enter key

6.It will installs jdk-1.6.0_16

F. Source Code. Software may contain source code that,

unless expressly licensed for other purposes, is provided

solely for reference purposes pursuant to the terms of this

Agreement. Source code may not be redistributed unless

expressly provided for in this Agreement.

G. Third Party Code. Additional copyright notices and

license terms applicable to portions of the Software are set

forth in the THIRDPARTYLICENSEREADME.txt file. In addition

to any terms and conditions of any third party

opensource/freeware license identified in the

THIRDPARTYLICENSEREADME.txt file, the disclaimer of warranty

and limitation of liability provisions in paragraphs 5 and 6

of the Binary Code License Agreement shall apply to all

Software in this distribution.

H. Termination for Infringement. Either party may

terminate this Agreement immediately should any Software

become, or in either party’s opinion be likely to become,

the subject of a claim of infringement of any intellectual

property right.

I. Installation and Auto-Update. The Software’s

installation and auto-update processes transmit a limited

amount of data to Sun (or its service provider) about those

specific processes to help Sun understand and optimize them.

Sun does not associate the data with personally identifiable

information. You can find more information about the data

Sun collects at http://java.com/data/.

For inquiries please contact: Sun Microsystems, Inc., 4150

Network Circle, Santa Clara, California 95054, U.S.A.

(LFI#143333/Form ID#011801)

Do you agree to the above license terms? [yes or no]

yes

Unpacking…

Checksumming…

0

0

Extracting…

UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).

inflating: jdk-6u16-linux-x64-rpm

Preparing… #################################### [100%]

1:jdk #################################### [100%]

Done.

#

7.Add below lines in /etc/profile file to define JAVA_HOME and its PATH

export JAVA_HOME=/usr/java/jdk-1.6.0_16

export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:

8. Verify the java installation by running the following command in the new window.`

[root@bang opt]# java -version

java version “1.6.0_16”

Java(TM) SE Runtime Environment (build 1.6.0_16-b01)

Java HotSpot(TM) 64-Bit Server VM (build 14.2-b01, mixed mode)

[root@bangvbapp opt]#

How to setup Domain Name Server (DNS) on Linux?

Estimated Reading Time: 4 minutes

It has been long I was thinking of writing something about DNS(Domain Name Server). DNS is a database of the IP to Name and Name to IP conversion.I went through lots of tutorials related to DNS but couldnt satisfy myself unless and until I started writing commands and configuring files for the initial setup.After lot of tweaking and command line I was able to setup a simple DNS server.

dns_process

Lets travel into the world of DNS.

I have a RHEL 4 Machine ready with bind packages installed.The Minimal requirement are:

[root@localhost ~]# rpm -qa bind*

bind-libs-9.2.4-24.EL4

bind-utils-9.2.4-24.EL4

bind-9.2.4-24.EL4

bind-chroot-9.2.4-24.EL4

bind-devel-9.2.4-24.EL4

bind-libs-9.2.4-24.EL4

[root@localhost ~]#

The IP Details of my Machine are:

[root@localhost ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:16:17:C6:BE:47

inet addr:10.14.77.33 Bcast:10.14.77.127 Mask:255.255.255.128

inet6 addr: fe80::216:17ff:fec6:be47/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:36287 errors:0 dropped:0 overruns:0 frame:0

TX packets:19141 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:5408275 (5.1 MiB) TX bytes:2370680 (2.2 MiB)

Interrupt:201

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:18714 errors:0 dropped:0 overruns:0 frame:0

TX packets:18714 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:10174891 (9.7 MiB) TX bytes:10174891 (9.7 MiB)

[root@localhost ~]#

The Exact Steps I followed are mentioned Below:

1. Open a file /etc/hosts and make it look like this:

[root@localhost ~]# cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1 localhost.localdomain localhost

[root@localhost ~]#

2.Edit the file /etc/resolv.conf:

[root@localhost ~]# cat /etc/resolv.conf

; generated by /sbin/dhclient-script

search tuxbuddy.raina.com

nameserver 10.14.77.33

[root@localhost ~]#

3. Run this Command:

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=dhcp

HWADDR=00:16:17:C6:BE:47

ONBOOT=yes

TYPE=Ethernet

PEERDNS=no

[root@localhost ~]#

4. Follow this step:

[root@localhost etc]# pwd

/var/named/chroot/etc

[root@localhost etc]# vi named.conf

//

// named.conf for Red Hat caching-nameserver

//

options {

directory “/var/named”;

dump-file “/var/named/data/cache_dump.db”;

statistics-file “/var/named/data/named_stats.txt”;

/*

* If there is a firewall between you and nameservers you want

* to talk to, you might need to uncomment the query-source

* directive below. Previous versions of BIND always asked

* questions using port 53, but BIND 8.1 uses an unprivileged

* port by default.

*/

// query-source address * port 53;

};

//

// a caching only nameserver config

//

controls {

inet 127.0.0.1 allow { localhost; } keys { rndckey; };

};

zone “.” IN {

type hint;

file “named.ca”;

};

zone “tuxbuddy.raina.com” IN {

type master;

file “tuxbuddy.raina.com.zone”;

allow-update { none; };

};

zone “33.77.14.10.in-addr.arpa” IN {

type master;

file “10.14.77.33.zone”;

allow-update { none; };

};

zone “localhost” IN {

type master;

file “localhost.zone”;

allow-update { none; };

};

zone “0.0.127.in-addr.arpa” IN {

type master;

file “named.local”;

allow-update { none; };

};

zone “0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa” IN {

type master;

file “named.ip6.local”;

allow-update { none; };

};

zone “255.in-addr.arpa” IN {

type master;

file “named.broadcast”;

allow-update { none; };

};

zone “0.in-addr.arpa” IN {

type master;

file “named.zero”;

allow-update { none; };

};

include “/etc/rndc.key”;

Save the file.

5.Edit the Database Files:

[root@localhost named]# pwd

/var/named/chroot/var/named

[root@localhost named]#vi tuxbuddy.raina.com

$TTL 86400

@ IN SOA station1.tuxbuddy.raina.com. root.station1.tuxbuddy.raina.com. (

2009091100; Serial

28800 ; Refresh

14400 ; Retry

3600000 ;Expire

0 ) ; Negative

@ IN NS station1.tuxbuddy.raina.com.

@ IN A 10.14.77.33

station1.tuxbuddy.raina.com. IN A 10.14.77.33

www IN A 10.14.77.33

ftp IN A 10.14.77.33

pop IN A 10.14.77.33

www1 IN CNAME station1.tuxbuddy.raina.com.

www2 IN CNAME station2.tuxbuddy.raina.com.

www.station1.tuxbuddy.raina.com IN A 10.14.77.33

Innovation2.groupinfra.com. IN A 10.14.16.215

@ IN MX 10 station1.tuxbuddy.raina.com.

station1 IN MX 10 station1.tuxbuddy.raina.com.

~

[root@localhost named]#

6. Edit this file too:

[root@localhost named]# pwd

/var/named/chroot/var/named

[root@localhost named]#

[root@localhost named]# cat 10.14.77.33.zone

$TTL 86400

@ IN SOA station1.tuxbuddy.raina.com. root.station1.tuxbuddy.raina.com. (

4 10800 3600 604800 86400 )

IN NS station1.tuxbuddy.raina.com.

33.77.14.10.IN-ADDR.ARPA. IN PTR station1.tuxbuddy.raina.com.

[root@localhost named]#

JUST REMEMBER DONT MISS ANY . during the configuration.

DNS IS VERY SENSITIVE TO SINGLE SIGN.

Thats ALL !!!

YOUR SIMPLE DNS SERVER IS READY.

Testing the DNS SERVER

[root@localhost named]# dig -x 10.14.77.33

; <<>> DiG 9.2.4 <<>> -x 10.14.77.33

;; global options: printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48322 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;33.77.14.10.in-addr.arpa. IN PTR ;; ANSWER SECTION: 33.77.14.10.in-addr.arpa. 86400 IN PTR station1.tuxbuddy.raina.com. ;; AUTHORITY SECTION: 33.77.14.10.in-addr.arpa. 86400 IN NS station1.tuxbuddy.raina.com.

;; ADDITIONAL SECTION:

station1.tuxbuddy.raina.com. 86400 IN A 10.14.77.33

;; Query time: 1 msec

;; SERVER: 10.14.77.33#53(10.14.77.33)

;; WHEN: Wed Oct 7 07:28:30 2009

;; MSG SIZE rcvd: 114

[root@localhost named]#

Just See..Your IP is resolving to Hostname and vice versa.

Other Way to see if things work or not !!

[root@localhost named]# host 10.14.77.33

33.77.14.10.in-addr.arpa domain name pointer station1.tuxbuddy.raina.com.

[root@localhost named]#

These too,

[root@localhost named]# host www

www.tuxbuddy.raina.com has address 10.14.77.33

[root@localhost named]#

How to test Multicast Packet Filtering?

Estimated Reading Time: 2 minutes

Today morning I started my day testing with Multicast Packet Filtering. I had buntu 12.04.1 and CentOS 6.5 in my VM running over ESX 5.5.I decided to make CentOS as Client and Ubuntu as server for the setup.

iperf-client-server
First of all, I downloaded iperf as I had no YUM working at my internal lab.
Its simple to install,download the package and install. Luckily, I dint get any dependency hell.

On Ubuntu Box:

SERVER MACHINE
=====================================

sudo iperf -s -u -B 224.0.65.68 -i 1
————————————–

server listening on UDP port 5001
Binding to local address 224.0.65.68
Joining multicast group 224.0.65.68
UDP Buffer size: 120 Kbytes(default)
——————————————

[ 3] local 224.0.65.688 port 5001 connected with 10.112.173.86 port 38577
[ 3] 0.0.-1.0 sec 128 KBytes 1.05 Mbits/sec 0.228 ms 0/ 89 (0%)

On CenTOS Box(Client):

iperf -c 224.0.65.68 -u -T 5 -t 5
———————————-
Client connecting to 224.0.65.68, UDP port 5001
sending 1470 byte datagrams
setting multicast TTL to 5
UDP buffer size: 126 KBytes(default)
——————————————
[ 3] local 10.112.173.86 port 38577 connected with 224.0.65.68 port 5001
[ 3] 0.0- 5.0 sec 642 Kbytes 1.05 Mbits/sec
[ 3] Sent 447 datagrams

1.It clearly shows that multicast address is 224.0.65.68.
e.g. server> iperf -s -u -B -i 1

This will have the iperf servers listening for datagram (-u) from the address (-B multicast address), with a periodic interval of 1s (-i 1)

2. Configure the client VM, connecting to the multicast group address and setting the TTL (-T, –ttl) as needed
e.g. client> iperf -c -u -T 5 -t 5

This will have the client connected to the multicast address (-c multicast address), with a TTL of 5 (-T 5), sending data for 5 seconds
NOTE: Use tcpdump or ethereal on server VMs to capture and analyze IP packets and ensure its validity.

Run the test for 120 sec.

That’s it..
You Have just finally tested Multicast packet Filtering.

Understanding /proc/cpuinfo

Estimated Reading Time: 4 minutes

A hyperthreaded processor has the same number of function units as an older, non-hyperthreaded processor. It just has two execution contexts, so it can maybe achieve better function unit utilization by letting more than one program execute concurrently. On the other hand, if you’re running two programs which compete for the same function units, there is no advantage at all to having both running “concurrently.” When one is running, the other is necessarily waiting on the same function units.

cpu

A dual core processor literally has two times as many function units as a single-core processor, and can really run two programs concurrently, with no competition for function units.

A dual core processor is built so that both cores share the same level 2 cache. A dual processor (separate physical cpus) system differs in that each cpu will have its own level 2 cache. This may sound like an advantage, and in some situations it can be but in many cases new research and testing shows that the shared cache can be faster when the cpus are sharing the same or very similar tasks.

In general Hyperthreading is considered older technology and is no longer supported in newer cpus. Hyperthreading can provide a marginal (10%) for some server workloads like mysql, but dual core technology has essentially replaced hyperthreading in newer systems.

A dual core cpu running at 3.0Ghz should be faster then a dual cpu (separate core) system running at 3.0Ghz due to the ability to share the cache at higher bus speeds.

The examples below details how we determine what kind of cpu(s) are present.

The kernel data Linux exposes in /proc/cpuinfo will show each logical cpu with a unique processor number. A logical cpu can be a hyperthreading sibling, a shared core in a dual or quad core, or a separate physical cpu. We must look at the siblings, cpu cores and core id to tell the difference.

If the number of cores = the number of siblings for a given physical processor, then hyperthreading is OFF.

/bin/cat /proc/cpuinfo | /bin/egrep ‘processor|model name|cache size|core|sibling|physical’

Example 1: Single processor, 1 core, no Hyperthreading

processor : 0
model name : AMD Duron(tm) processor
cache size : 64 KB

Example 2: Single processor, 1 core, Hyperthreading is enabled.

Notice how we have 2 siblings, but only 1 core. The physical cpu id is the same for both: 0.

processor : 0
model name : Intel(R) Pentium(R) 4 CPU 2.80GHz
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
processor : 1
model name : Intel(R) Pentium(R) 4 CPU 2.80GHz
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1

Example 3. Single socket Quad Core

Notice how each processor has its own core id. The number of siblings matches the number of cores so there are no Hyperthreading siblings. Also notice the huge l2 cache – 6 MB. That makes sense though, when considering 4 cores share that l2 cache.

processor : 0
model name : Intel(R) Xeon(R) CPU E5410 @ 2.33GHz
cache size : 6144 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 4
processor : 1
model name : Intel(R) Xeon(R) CPU E5410 @ 2.33GHz
cache size : 6144 KB
physical id : 0
siblings : 4
core id : 1
cpu cores : 4
processor : 2
model name : Intel(R) Xeon(R) CPU E5410 @ 2.33GHz
cache size : 6144 KB
physical id : 0
siblings : 4
core id : 2
cpu cores : 4
processor : 3
model name : Intel(R) Xeon(R) CPU E5410 @ 2.33GHz
cache size : 6144 KB
physical id : 0
siblings : 4
core id : 3
cpu cores : 4

Example 3a. Single socket Dual Core

Again, each processor has its own core so this is a dual core system.

processor : 0
model name : Intel(R) Pentium(R) D CPU 3.00GHz
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
processor : 1
model name : Intel(R) Pentium(R) D CPU 3.00GHz
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2

Example 4. Dual Single core CPU, Hyperthreading ENABLED

This example shows that processer 0 and 2 share the same physical cpu and 1 and 3 share the same physical cpu. The number of siblings is twice the number of cores, which is another clue that this is a system with hyperthreading enabled.

processor : 0
model name : Intel(R) Xeon(TM) CPU 3.60GHz
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
processor : 1
model name : Intel(R) Xeon(TM) CPU 3.60GHz
cache size : 1024 KB
physical id : 3
siblings : 2
core id : 0
cpu cores : 1
processor : 2
model name : Intel(R) Xeon(TM) CPU 3.60GHz
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
processor : 3
model name : Intel(R) Xeon(TM) CPU 3.60GHz
cache size : 1024 KB
physical id : 3
siblings : 2
core id : 0
cpu cores : 1

Example 5. Dual CPU Dual Core No hyperthreading

Of the 5 examples this should be the most capable system processor-wise. There are a total of 4 cores; 2 cores in 2 separate socketed physical cpus. Each core shares the 4MB cache with its sibling core. The higher clock rate (3.0 Ghz vs 2.3Ghz) should offer slightly better performance than example 3.

processor : 0
model name : Intel(R) Xeon(R) CPU 5160 @ 3.00GHz
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
processor : 1
model name : Intel(R) Xeon(R) CPU 5160 @ 3.00GHz
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
processor : 2
model name : Intel(R) Xeon(R) CPU 5160 @ 3.00GHz
cache size : 4096 KB
physical id : 3
siblings : 2
core id : 0
cpu cores : 2
processor : 3
model name : Intel(R) Xeon(R) CPU 5160 @ 3.00GHz
cache size : 4096 KB
physical id : 3
siblings : 2
core id : 1
cpu cores : 2

Hope you find it useful for your interview preparation.

How to setup vsFTP server on Linux?

Estimated Reading Time: 1 minute

FTP refers to File Transfer Protocol. By default, Red Hat supports vsftp. If you do minimal RHEL installation, you mightn’t have vsftp related RPM packages installed.

ftp

To setup an anonymous ftp server on Red Hat Enterprise Linux, follow these steps:

1. Verify that the vsftpd package is installed.

#rpm -qa |grep vsftpd

If it is not installed, the install it as follows:

RHEL 3 and 4

# up2date -i vsftpd

RHEL 5
# yum install vsftpd

2. Verify the localhost line in /etc/hosts looks like the following:

127.0.0.1 localhost.localdomain localhost

3. Next configure the vsftpd.conf file. NOTE: Back up the vsftpd.conf file

# cd /etc/vsftpd
# cp vsftpd.conf ./vsftpd.conf.ORIG

Using an editor, open the file vsftpd.conf. Uncomment the line
anonymous_enable=YES. Save and quit the vsftpd.conf file.

4. Start the vsftpd service

# service vsftpd start

5. To have the vsftpd service persistent across reboot:

# chkconfig vsftpd on

6. To test the configuration run the following commands:

# ftp localhost

Login with:
username: anonymous
password: root@local

This should show an ftp prompt. Type ‘bye’ to exit to the command prompt.
NOTE: ports 20 and 21 must be opened on the firewall.

How to increae Swap space under Linux

Estimated Reading Time: 2 minutes

“Can Linux be installed without swap space?”.

This question was asked to me on one of Linux System admin interview. It might confuse anyone who is still fresher and have no hands-on experience with swap terminology.But the reality is “Yes”. But if you did this, you should be ready to cope up with your Linux box next time you put extra load on your box.It will crash someday.Its always recommended to provide extra space for swap partition.Swap is only used when you have maximum load.

atemyram
This article discuss how to increase the swap space through adding swap file on Linux machine.

Lets proceed with the requisite steps to add swap file as shown below:

Lets use dd command to create swapfile. Then you need to use mkswap command to set up a Linux swap area on a device or in a file.

a) Log in as root user.

b) Run this command to create 512MB swap file (1024 * 512MB = 524288 block size):

  1. dd if=/dev/zero of=/swapf1 bs=1024 count=524288

c) Set up a Linux swap area:

  1. mkswap /swapf1

d) Activate /swapfile1 swap space immediately:

  1. swapon /swapf1

e) To activate /swapf1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:

  1. vi /etc/fstab

Then,append following line:

/swapf1 swap swap defaults 0 0

So next time Linux comes up after reboot, it enables the new swap file for you automatically.

Verifying if the swap is activated or not?

$ free -m

Hope the article proves useful for everyone who wants an extra swap space therein.

How to setup Centralized Logging System on Linux?

Estimated Reading Time: 2 minutes
I was just hanging around blogs until I cam across one nice piece of setting up centralized Logging setup.I thought to try it out of mine and here is the output:Syslog is a fantastic facility for logging on Linux machines. Lets say you have a small number of servers, and want to log them all to one central syslog server. Here we’ll describe a simple configuration.
syslog-2
1) Setup the syslog serverOn the system you want to use as the syslog server, edit the file /etc/sysconf/syslog, and add ‘-r’ as follows:

  1. Options to syslogd
  2. -m 0 disables ‘MARK’ messages.
  3. -r enables logging from remote machines
  4. -x disables DNS lookups on messages recieved with -r
  5. See syslogd(8) for more details

SYSLOGD_OPTIONS=”-m 0 -r”

  1. Options to klogd
  2. -2 prints all kernel oops messages twice; once for klogd to decode, and
  3. once for processing with ‘ksymoops’
  4. -x disables all klogd processing of oops messages entirely
  5. See klogd(8) for more details

KLOGD_OPTIONS=”-x”

Initially I added -x because I thought it would use networked DNS. But as I am logging all from local servers, all of which are defined in /etc/hosts, it doesn’t actually go to the network for name lookup. And, having the name of the system in the log file is nice.

Now, restart syslog, and confirm that syslog is listening on port 514 (the syslog port):

root@ajeet:/root>/etc/init.d/syslog restart
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
root@ajeet:/root>netstat -an|grep 514
udp 0 0 0.0.0.0:514 0.0.0.0:*

2) Now, configure your client:

For simplicity, I added a line in the /etc/hosts file to add the name ‘loghost’ to the other names I am using for my logging server. This is actually beneficial – because I can move my syslog server to another host – and I only have to modify the hosts file…

Next, edit the /etc/syslog.conf file. I added 1 simple line to log all informational messages to the remote loghost:

*.info @loghost

Note: separate all columns with the tab character, not space.

Finally restart syslog on the client with /etc/init.d/syslog restart.

To test, you can use the command line logging facility called logger. On the client I type:

root@tuxbuddy:/etc>logger foobar

And on the server I see:

root@ajeet:/root>tail -f /var/log/messages

Jun 28 21:17:29 tubxuddy bemo: fooba

Hence, the centralized logging server is Ready !!!

How to create password-less SSH for Linux

Estimated Reading Time: 2 minutes

Sometimes you might need setting up Password-less SSH for running script or for application where you dont want to use password everytime. Here is a quick method to setup password-less SSH.

SSH_Dock_Icon_by_eternicode

Lab Scenerio:

Machine1: 192.168.160.194

Machine2: 192.168.160.197

a. Run this command on Machine1:

#ssh-keygen -t rsa

It will show you this output. Just press Enter throughout the queries asked.

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

40:f0:87:19:23:47:1e:ef:65:7b:5d:05:b0:fa:48:81 root@puppet-server.test.com

The key’s randomart image is:

+–[ RSA 2048]—-+

| ooB …..|

| * B . . .|

| * E + . .|

| + o + . . |

| S + . . |

| . + |

| . . |

| |

| |

+—————–+

b. Let’s copy the key to remote Machine2:

#ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.160.197

root@192.168.160.197’s password:

It will show you the following output.

Now try logging into the machine, with “ssh ‘root@192.168.160.197′”, and check in:

.ssh/authorized_keys

to make sure we haven’t added extra keys that you weren’t expecting.

c. Now passwordless SSH is ready. Just test by typing this:

#ssh 192.168.160.197

Installing SMARTFOX Server Pro on Debian

Estimated Reading Time: 2 minutes

SmartFoxServer is a massive multiplayer platform for building games, MMO communities, virtual worlds, realtime multiplayer games.

smartfox-10

To setup SFS, in short on Linux platform like Debian, one can follow the below steps:

Download the SmartFox Server Pro 1.6.6 fromhttp://smartfoxserver.com/download/get/77/SFSPRO_linux64_1.6.6.tar.gz link.

smart-2

1. Open a terminal window and move to the folder where you have downloaded the file.
2. Type “gzip -d filename.tar.gz” to extract the .tar file (where “filename” is the name of the downloaded file) as shown in the screenshot.
3. Type “tar xf filename.tar” to extract the files.
4. Move inside the uncompressed folder and type ./install

smart-3

smart-4

To start the server move to the {installation-directory}/SFS_PRO_1.6.6/Server folder and type ./sfs start

smart-5

The complete list of commands is the following:

./sfs start Start the server
./sfs stop Stop the server
./sfs restart Restart the server
./sfs status Show the current status of the server ( running / not running etc… )

Installing SmartFoxServer as a Linux daemon:

smart-6

Hope it helps !!!