Sunday, June 24, 2012

MOODLE: Authentication Issue- CAS Login

Case: After Setting CAS & LDAP in Moodle, Admin/ local user cannot login anymore to Moodle.

Solution Step:
---------------

1. Go to database server.
2. Check setting in table mdl_config_plugins. Compare with existing running moodle db.
    #  SELECT * FROM mdl_config_plugins WHERE PLUGIN LIKE '%auth/cas%'


3. Change manually, db setting for mdl_config.
    #  UPDATE mdl_config SET VALUE = 'manual'  WHERE id='3'; 


4. Try open the site again and click Login.
    The local user may login now. But CAS user cannot.
    Login as moodle admin.

5. Go to CAS Setting Location:
    Settings > Site administration > Plugins > Authentication > Manage authentication

    ** Compare the setting with running moodle site.
        Found problem: 
cn dn setting in distinguish field.
        CAS   -  Need to put 
cn dn setting in Context field.
        LDAP -  Put 
cn dn setting in distinguish field.



6. Fix cn dn setting in CAS and LDAP.
    
Settings > Site administration > Plugins > Authentication > Manage authentication

   * Save setting for both.



7. Test open the site again and click Login.
    Now the login page back to normal. User can choose either to login using CAS or other user.

   * Thanks to Sis. Azlinda for the fast investigation & solution has been taken. Caiyok!!



.

MYSQL: How to set/configure/check backup using crontab

Case: In Ubuntu Server

Normally crontab file locate here:
# nano  /etc/crontab

The rules for crontab can refer in crontab file (backup.sh file)
:
PATH=/usr/local/sbin


or in command line

# m   h  dom mon dow user    command
   00 22   *      *      *   root    sh /usr/local/sbin/automysqlbackup.sh

** 00 22  is time to run the autobackup. The time can be change anytime if needed.


Check the rules in .sh file
# nano  /usr/local/sbin/automysqlbackup.sh

**Important Configuration:

# Username to access the MySQL server e.g. dbuser
USERNAME=dbuser

# Username to access the MySQL server e.g. password
PASSWORD=passworddb

# Host name (or IP address) of MySQL server e.g localhost
DBHOST=10.XX.XX.XX

# List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
DBNAMES="dbname1 mysql"
#DBNAMES="all"

# Backup directory location e.g /backups
BACKUPDIR="/mnt/archives/backupdb/alimcloud/"

:
# Email Address to send mail to? (user@domain.com)
MAILADDR="email@domain.com.my"

** Just remain default setting for others.

.


Thursday, June 21, 2012

UBUNTU: How to change hostname in new clone server?

Change the hostname on a running Linux system

On any Linux system you can change its hostname with the command ‘hostname‘.
#hostname

without any parameter it will output the current hostname of the system.

#hostname --fqd

it will output the fully qualified domain name (or FQDN) of the system.


#hostname NEW_NAME

it will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations).
Permanent hostname change on  Linux systems
#sudo nano  /etc/hostname
We can edit the file /etc/hostname and change the name of the system and then run:
/etc/init.d/hostname.sh start
The hostname saved in this file (/etc/hostname) will be preserved on system reboot.
Reboot the server to see the changes.

OR


Use sysctl to change the hostname
Use sysctl to change the variable kernel.hostname:
#sysctl kernel.hostname
to read the current hostname, and
#sysctl kernel.hostname=NEW_HOSTNAME
to change it.
If you want more details check sysctl man page
 ..

UBUNTU: How to change IP Address for new clone server?

1. Manually configure your network interface file:
    sudo nano /etc/network/interfaces
Once your prefered editor opens the file you want to enter the following information (changing your addresses where necessary):
auto lo eth0
iface lo inet loopback
iface eth0 inet static
address xxx.xxx.xxx.xxx(enter your ip here)
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx(enter gateway ip here)
* Be sure to save your changes.

2. Manually configure your dns configuration file:
    # sudo nano /etc/resolv.conf

Once your preferred editor opens the file you want to enter the following information (changing your addresses where necessary):
# Generated by NetworkManager
nameserver xxx.xxx.xxx.xxx(enter your dns server ip)
nameserver xxx.xxx.xxx.xxx(enter your alt dns server ip)
* Be sure to save your changes.

3. Manually restart your network interface with the new settings:
    # sudo /etc/init.d/networking restart


..

UBUNTU: How to clone Ubuntu Server using VMware?

1. Open VMware using vSphere Client console.
2. Right Click on UbuntuMaster Server  >  Clone  >  New Server Name
3. Edit Setting  >  Network Adapter  > Unthick  Device Status > Ok
4. Power On the New Server

..

MYSQL: Add a column to an existing MySQL table


MySQL tables are easy to extend with additional columns.

Use the following SQL statement:
ALTER TABLE contacts ADD email VARCHAR(60);

This first statement will add the email column to the end of the table. To insert the new column after a specific column, such as name, use this statement:

ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;

If you want the new column to be first, use this statement:
ALTER TABLE contacts ADD email VARCHAR(60) FIRST;



..

Tuesday, June 19, 2012

MySQL: Delete All Data in a MySQL Table

Delete and Truncate


TRUNCATE TABLE tablename;
This will delete all data in the table very quickly.In  MyISAM table; When using the "TRUNCATE TABLE" method the auto increment seed value will be reset back to 1.

DELETE FROM tablename;
This also deletes all the data in the table, but is not as quick as using the "TRUNCATE TABLE" method.
In MyISAM table; When using the "DELETE FROM" method the auto increment seed will be left as it was before.

** For INNODB tables using MySQL 4.0, whether you use the "TRUNCATE TABLE" or "DELETE FROM" methods, the auto increment field will not be reset.
But, using MySQL 5.0, TRUNCATE does reset the auto increment field back to the default.

Count record in table

SELECT COUNT(*) FROM tablename;

** Check that it really is safe to delete all data Or just delete certain data instead all.


Delete data with condition

DELETE FROM tablename WHERE foo = 'bar'";




Drop Table From Database

use  database1;
DROP TABLE  tablename;


..
 

Monday, June 18, 2012

CAS- Install & Configured CAS Server in UBUNTU

Reference site: https://help.ubuntu.com/community/CentralAuthenticationService


1) Install TOMCAT on Ubuntu
 
   # sudo apt-get update
   # sudo apt-get install tomcat6
   OR
   # sudo aptitude install tomcat6
   **Make sure you run this
   # sudo apt-get install openjdk-6-jdk

   Verify Java Installation
   # java -version

2) Install Maven
   # sudo apt-get install maven2

3) Optionally you can install maven-ant-helper in case you decide to use Ant to create deployment tasks:

   # sudo apt-get install ant
   # sudo apt-get install maven-ant-helper

 
4) Configuring CAS Server Build for Maven.
   Get the latest CAS server archive from JASig: http://www.ja-sig.org/downloads/cas
           -----------------
   # wget http://www.ja-sig.org/downloads/cas/cas-server-3.3.5-release.tar.gz
   # tar -xvzf cas-server-3.5.0-RC1-release.tar.gz
   # cd cas-server-3.5.0-RC1

5) Edit pom.xml
   # cd cas-server-wepapps/
   # nano pom.xml

   and add this line:

[dependency]
 ${project.groupId}
             cas-server-support-ldap
             ${project.version}
[/dependency]
   *Change [ ] to < and > & Save file.

6) Edit server.xml
   # nano /var/lib/tomcat6/conf/server.xml

   *Make sure you add or enable this
[Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" /]


   [Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" /]

   **Change [ ] to < and > & Save file.


7) Run this command in cas-server-3.5.0-RC1/cas-server-webapp directory
  # cd cas-server-3.5.0-RC1/cas-server-webapp
  # mvn clean package

8) Copy all content from content from cas-server-3.5.0-RC1/cas-server-webapp/target/cas-server-3.5.0-RC1/
  # cd cas-server-3.5.0-RC1/cas-server-webapp/target/cas-server-3.5.0-RC1/
  # cp -Rp * /var/lib/tomcat6/webapps/ROOT/

9) Restart tomcat service
  #service tomcat6 restart
  OR
  # /etc/init.d/tomcat6 restart

10)Setup SSL (self signed cert) with tomcat
  # keytool -genkey -alias tomcat -keyalg RSA -keystore /etc/tomcat6/keystore

* You will be requested for data that will show on your user browser's certificate:
  Enter keystore password: abc123
  Re-enter new password: abc123
  What is your first and last name: Jeremy Atkins
  What is your organizational unit: OU
  What is the name of your organization: NOYO
  What is the name of your city or your locality: MyCity
  What is the name of your state or province: Saudi Arabia
  What is the two-letter country code for this unit:  uk
  Is the entered data correct: yes>


11) Edit server.xml again
           [Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"

           maxThreads="150" scheme="https" secure="true"

           clientAuth="false" sslProtocol="TLS" 

           keystoreFile="/etc/tomcat6/keystore" 

           keystorePass="abc123" /]
**Change [ ] to < and > & Save file.

 12) Restart tomcat service
  # service tomcat6 restart
  OR
  # /etc/init.d/tomcat6 restart


13) Make sure firewall allow port 8080, 8443, 8009, 389.
    Test telnet the port within server sso and ldap through all related port.
  # telnet  serverip 8443
  # telnet  serverip 8080
  # telnet  serverip 8009
  # telnet  serverip 389

14) ** Test site >> http://serveraddress:8080

15) Configure deployerConfigContex.xml
Add this line at   :
----------------------------------------------------------------------------
[bean class="org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticationHandler"]
[property name="filter" value="cn=%u,ou=people,dc=student,dc=taibah,dc=edu,dc=sa"  /]
[property name="contextSource" ref="contextSource" /] [/bean]
----------------------------------------------------------------------------

And this line after :
------------------------------------------------------------
 [bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"]
                [property name="pooled" value="true"/]
                [property name="urls"]
                    [list>
                        [value]ldap://serverldap_ip/[/value]
                    [/list]
                [/property]
                [property name="userDn" value="cn=admin,dc=it,dc=mycompany,dc=com"/]
                [property name="password" value="asdfgh"/]
                [property name="baseEnvironmentProperties"]
                    [map]
                        [entry]
                            [key]
                                [value]java.naming.security.authentication[/value]
                            [/key]
                            [value]simple[/value]
                        [/entry]
                    [/map]
                [/property]
        [/bean]
-----------------------------------------------------------
**Change [ ] to < and > & Save file.                               

16) Restart tomcat service
  #service tomcat6 restart

17) Allow port 8443  >  443 
    # nano /etc/sysctl.conf  add  ->   sysctl net.ipv4.ip_forward=1

    Run iptable command:
    # iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination serverapps_ip:8443

18) Test site >> http://serveraddress

19) Test Login


-----------------------------------------------------------------------------------
Reference site:

http://rackerhacker.com/2009/11/16/automatically-loading-iptables-on-debianubuntu/
http://stackoverflow.com/questions/2619798/setup-ssl-self-signed-cert-with-tomcat
https://help.ubuntu.com/community/IptablesHowTo


MySQL: Export data to CSV from MySQL


To dump all the records from a table called "products" into the file /tmp/products.csv as a CSV file, use the following SQL query:
SELECT *
INTO OUTFILE '/tmp/products.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM products;
*Note that the directory must be writable by the MySQL database server. If it's not, you'll get an error message like this:
#1 - Can't create/write to file '/tmp/products.csv' (Errcode: 13)
Also note that it will not overwrite the file if it already exists, instead showing this error message:
#1086 - File '/tmp/products.csv' already exists

MySQL: Selectively dumping data with mysqldump

By default mysqldump will dump all data from a table, but it is possible to select which data to be exported with mysqldump


Examples: db= test   &  table = mytable
 
columns: mytable_id, category_id and name



Using mysqldump to dump all data from the table would look like this, subsituting [username] for your username (the -t flag suppresses the table creation sql from the dump):
mysqldump -t -u [username] -p test mytable
The output from my example table looks like this, once we remove all the extra SQL commands (I've added linebreaks to make it more legible):
INSERT INTO `mytable` VALUES 
  (1,1,'Lorem ipsum dolor sit amet'),
  (2,1,'Ut purus est'),
  (3,2,'Leo sed condimentum semper'),
  (4,2,'Donec velit neque'),
  (5,3,'Maecenas ullamcorper');
If we only wanted to dump data from mytable in category_id 1, we would do this:
mysqldump -t -u [username] -p test mytable --where=category_id=1
which would output this:
INSERT INTO `mytable` VALUES 
  (1,1,'Lorem ipsum dolor sit amet'),
  (2,1,'Ut purus est');

An example of dumping data from two tables using the same where clause could look like this, where we are selecting category_id from tables "mytable" and "anothertable":
mysqldump -t -u [username] -p test mytable anothertable --where="category_id = 1"

Refer: http://www.electrictoolbox.com/mysql-execute-statements-text-file/
...

MySQL : Use mysqldump to get the schema only


Dumping the database structure for all tables with no data


Add the -d flag to signify that no data should be included in the output like so, where "mydatabase" is the name of the database to dump, and "someuser" is the login name used to connect to the database
mysqldump -d -u someuser -p mydatabase

Dumping the database structure for one table with no data

mysqldump -d -u someuser -p mydatabase products

Dumping the database structure for several table with no data

mysqldump -d -u someuser -p mydatabase products categories users

Dumping the structure to a file

mysqldump -d -u someuser -p mydatabase > mydatabase.sql

Restore the structure file to mysql

mysql -u someuser -p anotherdatabase < mydatabase.sql

Storage Terms

SANStorage Area Network (SAN)
SANs are primarily used to make storage devices, such as 
disk arraystape libraries, and optical jukeboxes, accessible to servers so that the devices appear like locally attached devices to the operating system 
A SAN does not provide file abstraction, only block-level operations. However, file systems built on top of SANs do provide file-level access, and are known as SAN filesystems or shared disk file systems


NASNetwork-attached storage (NAS)


NAS  in contrast to SAN, uses file-based protocols such as NFS or SMB/CIFS where it is clear that the storage is remote, and computers request a portion of an abstract file rather than a disk block.



SAN-NAS hybrid
Despite the differences between SAN and NAS, it is possible to create solutions that include both technologies, as shown in the diagram



SAN infrastructure

SANs often utilize a Fibre Channel fabric topology - an infrastructure specially designed to handle storage communications. It provides faster and more reliable access than higher-level protocols used in NAS.
A typical Fibre Channel SAN fabric is made up of a number of Fibre Channel switches

Sunday, June 17, 2012

VMware Server

Virtualization

  • Virtualization lets you run multiple virtual machines on a single physical machine, with each virtual machine sharing the resources of that one physical computer across multiple environments.
  • Different virtual machines can run different operating systems and multiple applications on the same physical computer.
  • VMware virtualization works by inserting a thin layer of software directly on the computer hardware or on a host operating system. 
  • Safely run several operating systems and applications at the same time on a single computer, with each having access to the resources it needs when it needs them.



VMware vSphere

VMware vSphere, the industry-leading virtualization platform for building cloud infrastructures, enables you to run business critical applications with confidence and respond to the business faster. vSphere accelerates the shift to cloud computing for existing datacenters and underpins compatible public cloud o"erings, forming the foundation for the industry's only hybrid cloud model.

VMware vSphere 5.0 has finally arrived and includes several new unique features - such as Storage DRS and Autodeploy - that deliver unprecedented value to VMware customers. Unlike prior versions, vSphere 5 supports only the ESXi hypervisor architecture, the only thin purpose-built hypervisor that does not depend on a general purpose operating system.



ESXi and ESX Architectures Compared

VMware ESXi is VMware’s most advanced hypervisor architecture. Learn about the differences with the previous generation architecture, VMware ESX:
CapabilityESX 4.1ESXi 4.1ESXi 5.0
Service ConsolePresentRemovedRemoved
Admin/config CLIsCOS + vCLIPowerCLI + vCLIPowerCLI + vCLI (enhanced)
Advanced TroubleshootingCOSTech Support ModeESXi Shell
Scripted InstallationSupportedSupportedSupported
Boot from SANSupportedSupportedSupported
SNMPSupportedSupported (limited)Supported
Active DirectoryIntegratedIntegratedIntegrated
HW Monitoring3rd party agents in COSCIM providersCIM providers
Serial Port ConnectivitySupportedNot SupportedSupported
Jumbo FramesSupportedSupportedSupported
Rapid deployment and central management of hosts via Auto DeployNot SupportedNot SupportedSupported
Custom image creation and managementNot SupportedNot SupportedSupported
Secure syslogNot SupportedNot SupportedSupported
Management interface firewallSupportedNot SupportedSupported
See the KB article for a detailed comparison.



Technical Advantages
  1. Is built on a robust, proven foundation
  2. Delivers a complete virtualization platform from desktop through the datacenter out to the public cloud
  3. Provides the most comprehensive virtualization and cloud management
  4. Integrates with your overall IT infrastructure
  5. Is proven over 190,000 customers
And best of all, VMware delivers while providing
  1. Low total-cost-of-ownership (TCO)



Cost-per-application is a more accurate metric when comparing costs of different virtualization offerings. 
Density matters in a many-to-one relationship.


Read more here >>