Friday, October 4, 2013

Setup HAProxy Load Balancer on Ubuntu

Today I need to setup HAProxy Load Balance on Ubuntu. I think this month most of my task is on the clustering, load balance and HA. Last 2 weeks, I just finish my cluster for hyper-v. Luckily it's working very well.

Ok let go to the point...

1. Install HAProxy into Ubuntu Server.

# apt-get install haproxy

2. Change the HAProxy configuration. 

# nano etc/haproxy/haproxy.cfg

3. Add following text to file and save it

global
        log 127.0.0.1   daemon debug
        #log 127.0.0.1  local0
        #log 127.0.0.1  local1 notice
        #log loghost    local0 info
        stats socket /tmp/stats
        maxconn 4096
        pidfile /var/run/haproxy.pid
        #chroot /usr/share/haproxy
        #user haproxy
        #group haproxy
        daemon
        #debug
        #quiet

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 3000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000


listen  webcluster *:80
        mode http
        stats enable
        stats uri /stats           //default using http://web.domain.com/haproxy?stats
        stats auth admin:p@ssw0rd
        balance roundrobin
        option httpchk HEAD / HTTP/1.0
        option forwardfor
        cookie LSW_WEB insert
        option httpclose
        server  192.18.250.22 192.18.250.22:80 check inter 5000 fastinter 1000 fall 1 weight 1
        #server web1 192.18.250.22:80 weight 1 fastinter 5000 rise 2 fall 3
        server  192.18.250.23 192.18.250.23:80 check inter 5000 fastinter 1000 fall 1 weight 1
        #server web2 192.18.250.23:80 weight 1 fastinter 5000 rise 2 fall 3
        option  httpclose               # disable keep-alive
        option  checkcache              # block response if set-cookie & cacheable

        rspidel ^Set-cookie:\ IP=       # do not let this cookie tell our internal IP address

        #errorloc       502     http://192.168.114.58/error502.html
        #errorfile      503     /etc/haproxy/errors/503.http
        errorfile       400     /etc/haproxy/errors/400.http
        errorfile       403     /etc/haproxy/errors/403.http
        errorfile       408     /etc/haproxy/errors/408.http
        errorfile       500     /etc/haproxy/errors/500.http
        errorfile       502     /etc/haproxy/errors/502.http
        errorfile       503     /etc/haproxy/errors/503.http
        errorfile       504     /etc/haproxy/errors/504.http


3. Setting startup parameter for HAProxy set enabled as 1 to start HAproxy

# nano /etc/default/haproxy

4. Start HAProxy form command line

# /etc/init.d/haproxy start

5. Access Web user interface from browser

http://web.domain.com/stats




Thursday, October 3, 2013

Set Up an NFS Mount on Ubuntu


NFS (Network File System) Mounts

NFS mounts work to share a directory between several virtual servers. This has the advantage of saving disk space, as the home directory is only kept on one virtual private server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.

How to setup

An NFS mount is set up between at least two virtual servers. The machine hosting the shared network is called the server, while the ones that connect to it are called ‘clients’.

This tutorial requires 2 servers: one acting as the server and one as the client. We will set up the server machine first, followed by the client. The following IP addresses will refer to each one:

Master: 172.19.250.10
Client: 172.19.250.20


The system should be set up as root. You can access the root user by typing

# su-

Setting Up the NFS Server (master)

1. Download the Required Software (nfs-kernel-server)

Start off by using apt-get to install the nfs programs.

# apt-get install nfs-kernel-server portmap

2. Export the Shared Directory

The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.

Suppose we wanted to share two directories: /home and /var/nfs.

Because the /var/nfs/ does not exist, we need to do two things before we can export it.

First, we need to create the directory itself:

# mkdir /var/nfs/


Second, we should change the ownership of the directory to the user, nobody and the group, no group. These represent the default user through which clients can access a directory shared through NFS.

Go ahead and chown the directory:

# chown nobody:nogroup /var/nfs

or in mycase.. ownership base on my old setup


After completing those steps, it’s time to export the directories to the other VPS:

# nano /etc/exports


Add the following lines to the bottom of the file, sharing both directories with the client:

# /home 172.19.250.20(rw,sync,no_root_squash,no_subtree_check)

# /var/nfs 172.19.250.20(rw,sync,no_subtree_check)



These settings accomplish several tasks:

* rw: This option allows the client server to both read and write within the shared directory

* sync: Sync confirms requests to the shared directory only once the changes have been committed.

* no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.

* no_root_squash: This phrase allows root to connect to the designated directory


Once you have entered in the settings for each directory, run the following command to export them:

# exportfs -a


Setting Up the NFS Client


1. Download the Required Software (nfs-common)

Start off by using apt-get to install the nfs programs.

# apt-get install nfs-common portmap

2. Mount the Directories

Once the programs have been downloaded to the the client server, create the directories that will contain the NFS shared files

# mkdir -p /mnt/nfs/home

# mkdir -p /mnt/nfs/var/nfs



Then go ahead and mount them

# mount 172.19.250.10:/home /mnt/nfs/home

# mount 172.19.250.10:/var/nfs /mnt/nfs/var/nfs



You can use the df -h command to check that the directories have been mounted. You will see them last on the list.

# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda 20G 948M 19G 5% /

udev 119M 4.0K 119M 1% /dev

tmpfs 49M 208K 49M 1% /run

none 5.0M 0 5.0M 0% /run/lock

none 122M 0 122M 0% /run/shm

172.19.250.10:/home 20G 948M 19G 5% /mnt/nfs/home

172.19.250.10:/var/nfs 20G 948M 19G 5% /mnt/nfs/var/nfs



Additionally, use the mount command to see the entire list of mounted file systems.

# mount


Your list should look something like this:

/dev/sda on / type ext4 (rw,errors=remount-ro,barrier=0) [DOROOT]

proc on /proc type proc (rw,noexec,nosuid,nodev)

sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)

none on /sys/fs/fuse/connections type fusectl (rw)

none on /sys/kernel/debug type debugfs (rw)

none on /sys/kernel/security type securityfs (rw)

udev on /dev type devtmpfs (rw,mode=0755)

devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)

tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)

none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)

none on /run/shm type tmpfs (rw,nosuid,nodev)

rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)

172.19.250.10:/home on /mnt/nfs/home type nfs (rw,vers=4,addr= 172.19.250.10,clientaddr=172.19.250.20)

172.19.250.10:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,vers=4,addr=12.34.56.78,clientaddr=172.19.250.20)



Testing the NFS Mount


Once you have successfully mounted your NFS directories, you can test that they work by creating files on the Client and checking their availability on the Server.

Create a file in each directory to try it out:

# touch /mnt/nfs/home/example /mnt/nfs/var/nfs/example


You should then be able to find the files on the Server in the /home and /var/nfs directories.

# ls /home

# ls /var/nfs/



You can ensure that the mount is always active by adding the directories to the fstab file on the client. This will ensure that the mounts start up after the server reboots.

# nano /etc/fstab

++++++++++++++++++++++++
172.19.250.10:/home /mnt/nfs/home nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

172.19.250.10:/var/nfs /mnt/nfs/var/nfs nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

+++++++++++++++++++++++++++

You can learn more about the fstab options by typing in:

# man nfs


Any subsequent restarts will include the NFS mount—although the mount may take a minute to load after the reboot You can check the mounted directories with the two earlier commands:

# df -h

# mount


Removing the NFS Mount

Should you decide to remove a directory, you can unmount it using the umount command:

# cd

# umount /directory name



You can see that the mounts were removed by then looking at the filesystem again.

# df -h

You should find your selected mounted directory gone.

Monday, September 16, 2013

Hyper-V Cluster

Ok... This is my new task after taking my confinement leave.. I almost forget the linux command and windows skill. Huhuhu... But I just need 1 week to recover back my skill... and I think we as human also need DRS (Desaster Recovery System)... So, if anything happen in our brain.. we can restore it back.. huhuhu..

Actually this Hyper-V Cluster is not very hard to do. It is simple if you understand how cluster is working.

The step is same as below refference:

1. Name of the Virtual Switch SHOULD same for both cluster... host1 and host2.
Description: Validate that all specified nodes share the same set of network resource pools and virtual switches.
Gathering information about network resource pools used by servers running Hyper-V.
Node
Network Resource Pools
Virtual Ethernet Switches
host1.contoso.com
'Storage_net', 'Internal_IW', 'Segment250', 'DMZ-SCVMM', 'Client-Management-Network'
host2.contoso.com
'Segment250', 'HP NC373i Multifunction Gigabit Server Adapter #42 - Virtual Switch'

Processing information about network resource pools used by servers running Hyper-V.
Node 'host1.contoso.com' is missing a virtual Ethernet switch 'HP NC373i Multifunction Gigabit Server Adapter #42 - Virtual Switch' that is present on at least one other node. Either remove the virtual Ethernet switch from all nodes or ensure that it is present on all nodes.
Node 'host2.contoso.com' is missing a virtual Ethernet switch 'Client-Management-Network' that is present on at least one other node. Either remove the virtual Ethernet switch from all nodes or ensure that it is present on all nodes.
Node 'host2.contoso.com' is missing a virtual Ethernet switch 'DMZ-SCVMM' that is present on at least one other node. Either remove the virtual Ethernet switch from all nodes or ensure that it is present on all nodes.
Node 'host2.contoso.com' is missing a virtual Ethernet switch 'Internal_IW' that is present on at least one other node. Either remove the virtual Ethernet switch from all nodes or ensure that it is present on all nodes.
Node 'host2.contoso.com' is missing a virtual Ethernet switch 'Storage_net' that is present on at least one other node. Either remove the virtual Ethernet switch from all nodes or ensure that it is present on all nodes.

2. Version error. Then you have to update both server so both have same version. 

Result:
Both host was install with virtual machine, eg: vm_host1.contoso.com at host1.contoso.com and vm_host2.contoso.com at host2.contoso.com. Then, I shutdown the host1.contoso.com. You can see the motion of vm_host1.contoso.com is moving from host1.contoso.com to host2.contoso.com. It is a great result... i guest :) .. Done.. 


Thursday, June 20, 2013

Configure Server NTP Server Windows

  1. Stop the time service
    net stop w32time
  2. Set the manual peer list external servers
    w32tm /config /syncfromflags:manual /manualpeerlist:"asia.pool.ntp.org"
  3. Set the connection as reliable
    w32tm /config /reliable:yes
  4. Start the time service back up
    net start w32time
  5. Test the configururation
    w32tm /query /configuration
  6. Check time source
    w32tm /query /source

Tuesday, April 23, 2013

FreeBSD: Upgrade from 8.2 to 9.0

To check the freebsd version;
#uname -a
-if generic, you can use this step.. :)

You can use this command to upgrade to latest release FreeBSD 9.0:

# freebsd-update -r 9.0-RELEASE upgrade

You might see following error:
The update metadata is correctly signed, but failed an integrity check. Cowardly refusing to proceed any further.

This error indicate that it cannot accept % and @ characters which appear in FreeBSD 9. To overcome this, run following command:

# sed -i '' -e 's/=_/=%@_/' /usr/sbin/freebsd-update

Now start the upgrade process:

# freebsd-update -r 9.0-RELEASE upgrade

Accept all prompted values and follow the wizard. This process downloads all files and patches required for upgrade so it takes time. You might need to press ‘Enter’ once to check /etc/hosts file. Once complete, run following command to start installing the updates:

To quit from vi:  type :q

Then it will asked you to run /usr/sbin/freebsd_update install 

The system must now be rebooted with the newly installed kernel before the non-kernel components are updated.

# reboot

After the process completed, the system will ask you to build back all your application which installed using ports. Once done, you need to rerun again the above command to complete the upgrade process and you should something like below:

# freebsd-update install 
Installing updates... Done

Your update should be completed now. To check the new version, run following command:
# uname -r 
9.0-RELEASE

BUT.. then my apache cannot start... OHHH NOOO... 

here is the error:
Performing sanity check on apache22 configuration:
httpd: Syntax error on line 105 of /usr/local/etc/apache22/httpd.conf: Cannot load /usr/local/libexec/apache22/libphp5.so into server: Shared object "libz.so.5" not found, required by "libphp5.so"

Edit this file
# ee /etc/libmap.conf

libz.so.5  libz.so

then... you can restart the apache /usr/local/etc/rc.d/apache22 restart


Monday, April 15, 2013

"Kerberos" authentication failed while trying to access EMC or EMS

My colleague have this problem when she want to access EMC Microsoft Exchange: 


After I check the problem, I could see that she don't have this folder.

C:\Users\{user}\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\server.domain.com

So, I copied mine but she still cannot access.

Then, I go to this folder and delete the Exchange Management Console file.
C:\users\\AppData\Roaming\Microsoft\MMC\Exchange Management Console
Close EMC and reopen it.

And its working... hahaha.. very good... :) 

Thursday, April 4, 2013

Reset Password For Wordpress and VB in Mysql


WORDPRESS
  1. Get an MD5 hash of your password.
  2. Visit md5 Hash Generator, or...
  3. Create a key with Python. or...
  4. On Unix/Linux:
  5. Create file wp.txt with the new password in it (and *nothing* else)
  6. md5sum wp.txt
  7. rm wp.txt
  8. "mysql -u root -p" (log in to MySQL)
  9. enter your mysql password
  10. "use (name-of-database)" (select WordPress database)
  11. "show tables;" (you're looking for a table name with "users" at the end)
  12. "SELECT ID, user_login, user_pass FROM (name-of-table-you-found)" (this gives you an idea of what's going on inside)
  13. "UPDATE (name-of-table-you-found) SET user_pass="(MD5-string-you-made)" WHERE ID = (id#-of-account-you-are-reseting-password-for)" (actually changes the password)
  14. "SELECT ID, user_login, user_pass FROM (name-of-table-you-found)" (confirm that it was changed)
  15. (type Control-D, to exit mysql client)

Eg: 
UPDATE `wparb_users` SET `user_pass` = MD5('passwordbaru' ) WHERE `wparb_users`.`user_login` = "admin" 


VBULLETIN

Eg:

UPDATE user set password = MD5(concat(MD5(''), user.salt)) WHERE userid =  

Tuesday, April 2, 2013

CVS is Deprecated at FreeBSD.org (and so is cvsup!)

Today I'm starting doing my server preventive maintenance. I usually using cvsup to update package in FreeBSD and today, I received error:
So, the solution is using portsnap.
Here is the step :
1. Download a compressed snapshot of the Ports Collection
# portsnap fetch
2.When running Portsnap for the first time, extract the snapshot
# portsnap extract
3. cd
-> since it will reset your node point.

Then you can still use the port upgrade command as usual :)

Tuesday, March 26, 2013

Equivalence Dell, HP and IBM


Here is some equivalence spec with different brand:

Dell EqualLogic storage
--> HP P4000 (LeftHand)
--> IBM: none available

Dell PowerVault MD storage
--> HP P2000
--> IBM DS3500

Dell PowerEdge R720 server
--> HP Proliant DL380p G8
--> IBM x3650 M4

Thursday, March 21, 2013

Upgrading VBulletin v5 beta 26 to v5.0.0

My head nearly crash... need extra RAM to support more task..

It is really headache day when I need to spend for 2 days to upgrade VBulletin v5 Beta 26. In the development environment, I manage to upgrade it without no problem. But when I upgrade it at live environment here is the error that I received:

Unexpected Text:{?xml version="1.0" encoding="windows-1252"?}
There are too many post which having the same problem but nothing solve my problem. Arghh... I really forgot to check the log error... And that is the tips to solved this problem. Finally I manage to solve it by adding this: 

Log error : Allowed memory size of 134217728 bytes exhausted (tried to allocate 54669 bytes) in /home/snappy/public_html/vB5/core/includes/class_diff.php

Old Code
function compress_row($row) 
   { 
    return gzcompress(implode('|', $row), 9); 
    } 
---------------------------------------------------------- 
New Code
function compress_row($row) 
    {
     ini_set('memory_limit','512M');
     return gzcompress(implode('|', $row), 9); 
     }

Refference : http://www.vbulletin.com/forum/forum/vbulletin-5-connect/vbulletin-5-upgrades/423983-php-memory-error-during-upgrade



Tuesday, March 5, 2013

Mount New Hardisk in Ubuntu


Mount New Hardisk

  1. Mount New Hardisk via virtual or physical
  2. Restart the server.

Determine Drive Information
# lshw -C disk
 It will display the hardisk that you mount


Command Line Partitioning

  1. Initiate fdisk with the following command:# fdisk /dev/sdb
  2. m  then you can see the menu as below
  3. choose n -> add new partition
  4. then choose p -> for primary partition
  5. then choose 1 -> Since this will be the only partition on the drive, number 1. Enter "1" and enter
  6. Now that the partition is entered, choose option "w" to write the partition table to the disk. Type "w" and enter.

Command Line Formatting
Use "ext3" if the drive will only be used with Ubuntu. For file-sharing between Ubuntu and Windows, you should use "fat32."
# mkfs -t ext3 /dev/sdb1

Create A Mount Point


















# cd /      ---> go to root path
# mkdir data

OR
# mkdir /data

Mount driver
#nano /etc/fstab

-> add another line with new logical name and directory. 


# mount -a
# df -h 

if duplicate name... you can unmount and mount it back.
# unmount -a 

Monday, February 25, 2013

Installing PHP and Configure with IIS


  1. Download the latest version of PHP from http://windows.php.net/download/
  2. Extract at C:/php
  3. Download php manager to make your life easier http://phpmanager.codeplex.com/releases/view/69115
    note: You can refer how to use the php manager from  http://phpmanager.codeplex.com/wikipage?title=Managing%20PHP%20installations%20with%20PHP%20Manager%20user%20interface
  4. Installing Microsoft Drivers 3.0 for PHP for SQL Server are PHP 5 extensions that allows for the reading and writing of SQL Server data from within PHP scripts.


 

Wednesday, January 30, 2013

Failed to install .NET Framework 3.5 in Windows 8 or in Windows Server 2012

Problem
When you try to install .NET Framework 3.5 on machines with Microsoft Windows Server 2012 or Windows 8 you may receive the following error:



Cause

When you start installing .NET Framework 3.5 from Add features, Windows will tries to connect to Windows Update to download the required information for .NET Framework. And if your machine/server had no internet connection or unable to connect with Windows update service, this issue may occur.

According to Microsoft support, in Windows 8 and Windows Server 2012 .NET Framework is a Feature on Demand, the binaries and other files associated with the feature are not included.
Solution
Steps for Windows 8
Insert the Windows 8 installation media
Open Command Prompt as an administrator, run the following command:

# Dism /online /enable-feature /featurename:NetFx3 /All /Source:D:\sources\sxs /LimitAccess

Where D: is drive letter for the DVD drive or for the Windows 8 installation.





Steps for Windows 2012
Insert the Windows Server 2012 installation media.
Use Windows PowerShell and run the following command:

# Install-WindowsFeature –name NET-Framework-Core –source D:\sources\sxs

Where D: is drive letter for the DVD drive or for the Windows 2012 installation.





Refference :  http://www.ms-csm.com/sccm/?p=496

Thursday, January 17, 2013

How to present/mount New Hard Disk in a FreeBSD Server

The sysinstall utility is used for installing and configuring FreeBSD systems including hard disks. sysinstall offers options to partition and label a new disk using its easy to use menus. Login as root user. Run sysinstall and enter the Configure menu. Within the FreeBSD Configuration Menu, scroll down and select the Fdisk option:

# sysinstall


Select Configure and press [enter]


Select Fdisk and press [enter]


Choose da1 da1 (x)  -> Ok [enter]
ps: da0 -> already use in root at 1st installation. So, use da1 for new disk


Choose A( Use Entire Disk) ->then choose Q(finish)

Choose Label -> Ok

Choose C (Create) -> ps: Make sure the disk at da1 ->
Choose all -> select fs (File System) -> /data

---------------------------------------------------------> OPEN NEW SESSION--->find next step
Choose W (write) -> yes -> Q(finish)

Next step before Write disklabel
Edit /etc/fstab to add an entry for your new disk
#ee /etc/fstab
-> Copy line with FStype (ufs)
-> Change Device same as in Disklabel Editor (Part) and  Mountpoint as in Disklabel Editor (Mount)
Then Back -> to Disklabel Editor in previous windows to write and save


Done.... and may check your disk using #df -h



Tuesday, January 8, 2013

Disconnect Users From a Remote Desktop


qwinsta
qwinsta is the command; server is a sub command calling the server; and serverIP is the IP of the server you are connecting to. An example server IP could be 17.255.10.1.
A list will display the session ID you need to create the disconnect. The ID value will be next to the "STATE" value of Active. For this article we will say that the ID number of the session is 4. This active connection is what needs to be disconnected.

# qwinsta /server serverIP
eg: qwinsta /server 172.255.10.1

rwinsta 

rwinsta command is essentially resetting the session, the server will now see this and disconnect the user. SessionID is the value we found in the previous step. The full command should read as follows:

# rwinsta /server serverIP sessionID
eg: rwinsta /server 172.255.10.1 4