Wednesday, January 15, 2014

Install Multiple MySQL Versions On a Single Server

Install Multiple MySQL Versions On a Single Server



We usually need to use different version of a software in a single server in some case for testing, And some are because of requirements of some apps...,

In this example is going to install multiple MySQL version on a single server.

OS: Ubuntu Server 12.04
Default MySQL versoion: 5.5.34
Compiled MySQL version: 5.1.65
Note:
- mysql-server IP: 192.168.5.5
- remote-client IP: 192.168.5.1

1. Install MySQL from APT-GET
2. Install MySQL from Compile
    2.1. Required Softwares
    2.2 Compile MySQL
          2.2.1 Download
          2.2.2 Extract
          2.2.3 Compile

1. Install MySQL from APT-GET
#apt-get install mysql-server
During the installation will be ask you to enter root's password.


Log in into MySQL server by command:
# mysql -u root -p


Create a test database after login by command:
#mysql> create database dbtest1;


2. Install MySQL from Compile

2.1. Required Softwares
Install compiler tools

#apt-get install build-essential libncurses-dev libstdc++6 libc6 libltdl-dev autoconf

2.2 Compile MySQL 
Create folder structure,
In this example we are going to install another MySQL version 5.1.65 in /opt/mysql-versions/
# mkdir -p /opt/mysql-versions/mysql5165/datafiles
# mkdir -p /opt/mysql-versions/mysql5165/logs
# mkdir -p /opt/mysql-versions/mysql5165/pid
# mkdir -p /opt/mysql-versions/mysql5165/socket
2.2.1 Download 
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.65.tar.gz

2.2.2 Extract
tar -xvf mysql-5.1.65.tar.gz
2.2.3 Compile
Go to folder mysql-5.1.65:
# cd mysql-5.1.65
-------------------------------------------------------------------------------------------------------------------------
./configure --prefix=/opt/mysql-versions/mysql5165/ --enable-assembler --with-mysqld-ldflags=-all-static --with-tcp-port=3307 --with-unix-socket-path=/opt/mysql-versions/mysql5165/socket/mysql5165.sock
-------------------------------------------------------------------------------------------------------------------------

Run command: make and make install
# make
# make install

After run command "make install"
create a file name "mysql5165.cnf" with content:
-------------------------------------------------------------------------------------------------------------------------
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password = R00tPa$$w0rd
port = 3307
socket = /opt/mysql-versions/mysql5165/socket/mysql-5165.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3307
socket = /opt/mysql-versions/mysql5165/socket/mysql-5165.sock
pid-file = /opt/mysql-versions/mysql5165/pid/mysql-5165.pid
datadir = /opt/mysql-versions/mysql5165/datafiles
log = /opt/mysql-versions/mysql5165/logs/mysqld5165.log
log-error = /opt/mysql-versions/mysql5165/logs/mysqld5165.err
basedir = /opt/mysql-versions/mysql5165
skip-locking
skip-name-resolve
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,
#    MASTER_USER=, MASTER_PASSWORD= ;
#
#    where you replace , , by quoted strings and
#     by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =  
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =  
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =  
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /opt/mysql-versions/mysql5165/var
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /opt/mysql-versions/mysql5165/var
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
--------------------------------------------------------------------------------------------------------------------------
Go to folder folder "bin" in the mysql compiled:
cd /opt/mysql-versions/mysql5165/bin
and issue command:
./mysql_install_db --defaults-file=/opt/mysql-versions/mysql5165/mysql5165.cnf --user=mysql

Change ownership the mysql compiled folder to user "mysql"
chown -R mysql:mysql /opt/mysql-versions/mysql5165

Test to start in safe mode
# /opt/mysql-versions/mysql5165/bin/mysqld_safe --defaults-file=/opt/mysql-versions/mysql5165/mysql5165.cnf --user=mysql &

# Note: If we want to auto start up add in : /etc/rc.local

Start the server
# /opt/mysql-versions/mysql5165/share/mysql/mysql.server start

Change root password
# /opt/mysql-versions/mysql5165/bin/mysqladmin -u root -P 3307 -S /opt/mysql-versions/mysql5165/socket/mysql-5165.sock password "R00tPa$$w0rd"

Log in with new password
# /opt/mysql-versions/mysql5165/bin/mysql -u root -P 3307 -S /opt/mysql-versions/mysql5165/socket/mysql-5165.sock -p

Allow other machine to remote to
Add a line "skip-name-resolve" in /opt/mysql-versions/mysql5165/mysql5165.cnf
# and on mysql server log into mysql: mysql> grant all privileges on *.* to 'root'@'192.168.5.1' identified by 'R00tPa$$w0rd' with grant option;

Login and create database:
mysql -u root -h 192.168.5.5 -p -P3307


Thursday, January 9, 2014

Script Change PHP Versions

Script Change PHP Versions


I am lazy to edit the vhost file to change the PHP version that I usually change,
So I create this script to help me complete this task. :D

This is the script to change PHP version which is base on where you keep the path of your PHP.
Download this script file and put somewhere on you computer.

*** Adjust this script base on your custom configurations.

How to run the script:
sudo ./change-php-version.sh
You will get the options to choose:

Please select the options, Enter the number only.
1. For list virtualhost
2. For list PHP version
3. For Change PHP version
4. For Exit

Note: If you choose option number 3 you need to provide other informations in order to change PHP version such as:
* virtualhost-name
* PHP version

As the following example:

Please Enter virtualhost file:
(example: local.demo)
local.demo

Please Enter PHP version number only:
(example: 5.3.8)
 5.4.9
If the virtualhost file exist and with PHP version is correct, Script will run without error.

Changing PHP Version to 5.4.9
 * Reloading web server config                                                              [ OK ]
Virtualhost local.demo changed to PHP version 5.4.9

Done, In this example, The script will change vhost file local.demo to PHP version 5.4.9.

==================== Here is the Script Content ================
#!/bin/bash
# Version 1.0
# Require user "root" to run this script.
if [ "$(whoami)" != 'root' ]; then
        echo "You have no permission to run $0 as non-root user."
        echo "Log in as user '"root"' or Use '"sudo"' !!!"
        exit 1;
fi
# Available options
echo ""
echo "Please select the options, Enter the number only."
echo ""
echo "1. For list virtualhost"
echo "2. For list PHP version"
echo "3. For Change PHP version"
echo "4. For Exit"
echo ""
read USERINPUT

USAGE="Pleaes enter the valid option"

if [ $USERINPUT = "1" ]
then
  CONFIG_OPTION="1"
fi

if [ $USERINPUT = "2" ]
then
  CONFIG_OPTION="2"
fi

if [ $USERINPUT = "3" ]
then
  CONFIG_OPTION="3"
fi

if [ $USERINPUT = "4" ]
then
  CONFIG_OPTION="4"
fi

if [ "$CONFIG_OPTION" = "" ]
then
  echo "$USAGE"
echo ""
  exit 1
fi

if [ "$USERINPUT" = "1" ]
then
echo "Available virtualhost files..."
echo ""
        if [ "$USERINPUT" = "1" ];
sudo ls /etc/apache2/sites-enabled/ >> /opt/php-versions/vhost.tmp ; cat /opt/php-versions/vhost.tmp ; rm /opt/php-versions/vhost.tmp
        then
echo ""
        else
           echo "$USAGE"
echo ""
        exit 1
fi
fi

if [ "$USERINPUT" = "2" ]
then
echo "Available PHP versions..."
echo ""
        if [ "$USERINPUT" = "1" ];
sudo ls /opt/php-versions/ |grep php5 >> /opt/php-versions/php-version.tmp ; cat /opt/php-versions/php-version.tmp ; rm /opt/php-versions/php-version.tmp
        then
echo ""
        else
           echo "$USAGE"
echo ""
        exit 1
        fi
fi

if [ "$USERINPUT" = "4" ]; then
        echo "Exit the programm"
        exit 1;
fi

################################################################
if [ "$USERINPUT" = "3" ]
then
echo ""
echo "Please Enter virtualhost file:"
echo ""
echo "(example: local.demo)"
echo ""
read VHOST
echo ""
echo "Checking if file virtualhost exist or not.."
echo ""

        if [ -f /etc/apache2/sites-available/$VHOST ];
        then
           echo "File virtualhost $VHOST exist..."
        else
           echo "File virtualhost $VHOST does not exists..."
        exit 1
fi
echo ""
echo "Please Enter PHP version number only:"
echo ""
echo "(example: 5.3.8) "
echo ""
read PHPVERSION
echo ""

if [ $PHPVERSION = "5.3.8" ]
then
  PHPPATH="/opt/php-versions/php538/"
fi

if [ $PHPVERSION = "5.4.9" ]
then
  PHPPATH="/opt/php-versions/php549/"
fi

if [ $PHPVERSION = "5.4.13" ]
then
  PHPPATH="/opt/php-versions/php5413/"
fi

if [ $PHPVERSION = "5.5.0" ]
then
  PHPPATH="/opt/php-versions/php550/"
 fi

if [ "$PHPPATH" = "" ]
then
  echo "This PHP Version does not exist. or not included. "
  exit 1
fi

#########################
# If $PHPVERSION = 5.3.8#
#########################
if [ $PHPVERSION = "5.3.8" ]
then
echo "Changing PHP Version to "$PHPVERSION""
# Remove "#" before Alias if more then 4 keep only 1.
sudo sed -i -e 's/#####Alias/#Alias/g' /etc/apache2/sites-available/$VHOST
# Comment all the line that exist the word "php5-default".
sudo sed -i -e 's/\/#Alias/' /etc/apache2/sites-available/$VHOST
# Uncomment the line which contain the PHP version that we want to enable
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
#service apache2 restart
sudo service apache2 reload
fi
#########################
# If $PHPVERSION = 5.4.9#
#########################
if [ $PHPVERSION = "5.4.9" ]
then
echo "Changing PHP Version to "$PHPVERSION""
# Remove "#" before Alias if more then 4 keep only 1.
sudo sed -i -e 's/#####Alias/#Alias/g' /etc/apache2/sites-available/$VHOST
# Comment all the line that exist the word "php5-default".
sudo sed -i -e 's/\/#Alias/' /etc/apache2/sites-available/$VHOST
# Uncomment the line which contain the PHP version that we want to enable
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
#service apache2 restart
sudo service apache2 reload
fi
##########################
# If $PHPVERSION = 5.4.13#
##########################
if [ $PHPVERSION = "5.4.13" ]
then
echo "Changing PHP Version to "$PHPVERSION""
# Remove "#" before Alias if more then 4 keep only 1.
sudo sed -i -e 's/#####Alias/#Alias/g' /etc/apache2/sites-available/$VHOST
# Comment all the line that exist the word "php5-default".
sudo sed -i -e 's/\/#Alias/' /etc/apache2/sites-available/$VHOST
# Uncomment the line which contain the PHP version that we want to enable
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
#service apache2 restart
sudo service apache2 reload
fi
#########################
# If $PHPVERSION = 5.5.0#
#########################
if [ $PHPVERSION = "5.5.0" ]
then
echo "Changing PHP Version to "$PHPVERSION""
# Remove "#" before Alias if more then 4 keep only 1.
sudo sed -i -e 's/#####Alias/#Alias/g' /etc/apache2/sites-available/$VHOST
# Comment all the line that exist the word "php5-default".
sudo sed -i -e 's/\/#Alias/' /etc/apache2/sites-available/$VHOST
# Uncomment the line which contain the PHP version that we want to enable
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
#service apache2 restart
sudo service apache2 reload
fi

echo ""
echo "Virtualhost $VHOST changed to PHP version $PHPVERSION"
        else
echo ""
        exit 1
fi

####################### End Of Script #######################

Monday, January 6, 2014

Zabbix Installation on CentOS 6.X

Zabbix Installation on CentOS 6.X

1. what is Zabbix?
2. Installations
3. Usage

Here we go:

1. what is Zabbix?
Zabbix is an open source monitoring solution that can be used to monitor and track performance and availability of network servers, devices and other IT resources.
2. Requirements Installations

2.1 LAMP 
LAMP (Linux, Apache HTTP Server, MySQL database, and PHP/Perl/Python)
2.1.1 Install Apache
# yum install httpd
Start Apache and add to auto startup when every boot.
# service httpd start 
# chkconfig httpd on
Allow Port 80 through our firewall
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

# service iptables restart
2.1.2 Install MySQL
# yum install mysql mysql-server
Start MySQL and add to auto startup when every boot.
# service mysqld start 
# chkconfig mysqld on
Set MySQL root's password by:
# mysql_secure_installation

2.1.3 Install PHP
# yum install php
# yum install php-mysql

2.2 EPEL
Before we can install Zabbix or other packages we need to install EPEL (Extra Packages for Enterprise Linux) first:
For CentOS 6.x
# wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm 
# rpm -Uvh epel-release-6-8.noarch.rpm

we can show our repository installed by:
# yum repolist

Update Repository
#yum update
Install Zabbix services
#yum install zabbix-server-mysql zabbix-agent zabbix-web-mysql

Log in into MySQL and create database and user for Zabbix
[root@zabbix ~]# mysql -u root -p
Enter password: 
mysql> create database zabbix;
mysql> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbixpassword';
mysql> flush privileges;
mysql> exit

Import zabbix templates to Zabbix database

# mysql -uzabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-1.8.18/create/schema/mysql.sql
# mysql -uzabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-1.8.18/create/data/data.sql
# mysql -uzabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-1.8.18/create/data/images_mysql.sql

Configure Zabbix server
# vi /etc/zabbix/zabbix_server.conf

[...]
DBName=zabbix
[...]
DBUser=zabbix
[...]
DBPassword=zabbixpassword
[...]

Edit file /etc/zabbix/zabbix_agentd.conf
# vi /etc/zabbix/zabbix_agentd.conf
[...]
Hostname= zabbix.vannakk.net
[...]

Edit Zabbix reqirements:
vi /etc/httpd/conf.d/zabbix.conf

php_value max_execution_time 900
php_value max_input_time 600
php_value memory_limit 256M
php_value upload_max_filesize 32M
php_value post_max_size 32M

Edit PHP.ini
# vi /etc/php.ini
date.timezone = Asia/Phnom_Penh

Adjust Firewall settings
Adjust iptables to allow the zabbix ports 10050 and 10051.
# vi /etc/sysconfig/iptables
[...]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT
[...]
# service iptables restart

Restart zabbix and httpd services and make them to start automatically on every reboot

# service zabbix-server start
# service zabbix-agent start
# service httpd restart
# service mysqld restart
# chkconfig zabbix-server on 
# chkconfig zabbix-agent on

Access Zabbix Web console
http://ip-address/zabbix or http://domain-name/zabbix

Follow the screen shoot and complete all the steps:










The default username/password is admin/zabbix



3. Usage
(Not yet added)

Thursday, December 19, 2013

Proxmox Virtualiazation

Proxmox Virtualiazation

1. What is Proxmox?
2. Installation
3. Promox Usage
4. VPSs Storage
4.1 Create a Raid storage for VPSs and backup

1. What is Proxmox?

Proxmox is an Open Source Server Virtualization Platform, based on KVM and OpenVZ.

2. Installation
Go to proxmox web site and download the the latest version at: http://www.proxmox.com/downloads
and install,
In this example my harddis size to install Promox is just only 55GB. and I will configure Raid 5 to store the Virtual Private Servers (VPSs) and VPSs Backup in the following steps.

Follow the installations step and fill in by your own information:
Enter to Boot: _
I agree
Next
Next
Next
Wait, 
Next
Reboot, to finish the installation.
We can log in with user "root" with the password that we put during the installation.
Or we can access via web browser with user "root" with the password that we put during the installation.


3. Promox Usage

Proxmox system file and path:
Proxmox has 3 main default configuration paths:
/etc/pve/
It is the important path for global Proxmox configuration such as VMs list, Storage information, Users, etc.
/etc/vz/
It is mainly for the Proxmox repository where we can define the download repository, logs path, log level etc.
/var/lib/vz 
It is the default storage where we can store the IOS, images, dumps and as well as the VPSs. We are currently point all these images and VMs to /storage partition.

4. VPSs Storage
4.1 Create a Raid storage for VPSs and backup

In this example, I am going to configure RAID5 with 50GB with 3 Disks.
Install required softwares:
apt-get update
apt-get install vim
apt-get install mdadm

Now I am going to setup RAID5 on /dev/sdb /dev/sdc /dev/sdd
root@proxmox01:~# fdisk /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x98a71f64.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-104857599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): 
Using default value 104857599

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L
 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
root@proxmox01:~#

and then do the same for other disks (/dev/sdc and /dev/sdd)

RAID-5:
mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1
root@proxmox01:~#mkfs.ext4 /dev/md0 
root@proxmox01:~# mkdir /storage
root@proxmox01:~# mount /dev/md0 /storage/
Now we should see /storage with the size (50GB * 3) - 50GB = 100GB

Add to fstab file
vi /etc/fstab

Create tother 3 folders under /storage
mkdir /storage/proxmox_sys
mkdir /storage/proxmox_data
mkdir /storage/proxmox_backup

Changing default Proxmox configuration and storage path
cd /etc/vz/
vi vz.conf
Change following 
LOCKDIR=/storage/proxmox_sys/lib/vz/lock
DUMPDIR=/storage/proxmox_sys/lib/vz/dump
LOGFILE=/storage/proxmox_sys/log/vzctl.log
TEMPLATE=/storage/proxmox_sys/lib/vz/template
VE_ROOT=/storage/proxmox_sys/lib/vz/root/$VEID
VE_PRIVATE=/storage/proxmox_sys/lib/vz/private/$VEID

Go to -> Data Center -> Storage -> Add -> Directory -> Select (ISO,Images,Containers and Templates) and named the Directory as proxmox_data
Go to -> Data Center -> Storage -> Add -> Directory -> Select (Backups) and named the Directory as proxmox_backup
and all the other required folders will be create automatically in these folders.

Copy the image iso for the distribution that you want to install and put in the correct location.
Example, we want to install a Ubuntu server, so we just copy the image iso of Ubuntu server put in: /storage/proxmox_data/template/iso
So when we create the VPSs we can select the default location or we want to use the path /storage which is the RAID-5 we create.

Here We go, Enjoy.

Error:

Go to -> Option -> KVM hardware virtualization -> Untick -> OK

That all for now about this Virtualize environments that I want to mention...! 

I am going to test more with the Cluster and Move a VPSs without downtime. ;) for the next post.





Friday, December 13, 2013

Unison File Synchronizer

Unison File Synchronizer

There are many tools use to sync file from one server to other server or two way synchronization.
In my previous artical I use to mentions one tool call CSYNC2 (Cluster Synchronization Tool).
After using this tool for a while there are some more features that I need but this tool could not show it up.

For I now I try to set and other tool up call: Unison File Synchronizer

Which is an other File Synchronizer tool, That I going to mention and show what I tried and work as what I exspected:
That provide 2 ways synchroinzations between nodes and we also could exclude (ignore) the folder that we don't want to sync also.
Here is a sample structure sync:


Install in Ubuntu server:
apt-get install unison

There are many different ways of using this tool. In this purpose I am going to sync between 2 servers. (they are cluster-servers)

After Installed,
Make sure these 2 node can automatically log in into each other with using password:
by using key. If you not sure how to check it out from here:
After complete this step,
1. Log in as root on server1 and edit a default profile file:
vi /root/.unison/default.prf
with content:
---------------------------------------------------
# Unison preferences file
include userone
include usertwo

root = /home
root = ssh://server2//home

auto=true
batch=true
confirmbigdel=true
fastcheck=true
group=true
owner=true
prefer=newer
silent=true
times=true

2. Edit file userone
vi /root/.unison/userone
with content:
---------------------------------------------------
# Paths to synchronize
path = userone/public_html

# Ignore
ignore = Path userone/public_html/foldertemp/*

3. Edit file usertwo
vi /root/.unison/usertwo
with content:
---------------------------------------------------
# Paths to synchronize
path = usertwo/public_html

# Ignore
ignore = Path usertwo/public_html/foldertemp/*
---------------------------------------------------

Now that we have put all settings in a preferences file (especially the root (and optionally the path) directives), we can run Unison without any arguments:
unison 
Or,
We should run this in cron in every 2 minutes:
crontab -e
*/2 * * * * /usr/bin/unison &> /dev/null

In this example will sync 2 ways between public_html and ignore /public_html/foldertemp in home users:
userone and usertwo between server1 and server2.

Note:
* Unison will check configurations in its users run the command, in folder name ~/.unison
* In file /root/.unison/default.prf has the option include filename
(we can include as many files as we one with those filename that contain the path we want to sync.)
* We can include the path as many as we want.

For more info: http://www.cis.upenn.edu/~bcpierce/unison/lists.html

Thursday, December 12, 2013

Linux Professional Institute Candidate in Cambodia

Linux Professional Institute Candidate in Cambodia

#Linux #Professional #Institute #Cambodia 
#LPI



Monday, December 2, 2013

Use Your Own Domain With Blog

Use Your Own Domain With Blog

What we need:
- Domain name registrations (vannakk.net)
- Blogger Site (vannakk.blogspot.com)

1. Own a domain with DNS. so register your domain with DNS

2. Add a record
Name TTL Class TYPE Record
www.vannakk.net. 3600 IN CNAME ghs.google.com


3. Change on your Blog
Go to Setting --> Publishing --> Advanced settings --> Add a custome domain
- Enter your domain name.
- Tick Redirect none www. to www.
- Save.

4. TIPs
If you are setting sub domain like www.mydomain.com instead of my domain.com
and if you want to point your nick domain i.e.mydomain.com to your blog,
you also have to add four A records to dns settings of your domain to these ip address as follows :
* 216.239.32.21
* 216.239.34.21
* 216.239.36.21
* 216.239.38.21

After a while you blog should be redirect to http://www.vannakk.net/  . Depend on TTL settings.
Done,