Sunday 28 November 2010

How To CreateHow To Create OpenVZ Virtual Machines (VPS) OpenVZ Virtual Machines (VPS)

How do I create OpenVZ virtual machine (VPS) to run CentOS or Debian as VPS?

OpenVZ comes with a template for each VPS or virtual machine. OpenVZ provides templates for all leading Linux distributions. You need to download those templates in order to create a VPS. Visit this page to grab templates for vps.

Download Ubuntu Linux VPS

Type the following commands to download precreated Ubuntu Linux template:
# cd /vz/template/cache
# wget http://download.openvz.org/template/precreated/ubuntu-9.04-x86_64.tar.gz

Download CentOS 64 bit template:
# cd /vz/template/cache
# wget http://download.openvz.org/template/precreated/centos-5-x86_64.tar.gz

Create VPS

Now you’ve download the template for your virtual machine. You can just start a VPS based on the template you have just downloaded, by typing the following commands:  [10 is VPS ID you can use as per your requirement]
vzctl create 10 –ostemplate ubuntu-9.04-x86_64
vzctl set 10 –onboot yes –save

***  Set IP for VPS ***
vzctl set 10 –ipadd 192.168.1.5 –save

*** Set Nameservers IP for VPS ***
vzctl set 10 –nameserver 192.168.1.111 –save
vzctl set 10 –nameserver 192.168.1.111 –save

*** Set Hostname IP for VPS ***
vzctl set 10 –hostname ourlinuxblog.wordpress.com –save

*** Set Disk quota for VPS (10G min [soft] and 11G max hard limit) ***
vzctl set 10 –diskspace 10G:11G –save

*** Okay lets the vps ***
vzctl start 10

***  Set root user password for VPS ***
vzctl exec 10 passwd

vzctl is used to create and set various vps properties such as memory, disk usage and much more. Where,

  • create 10 : Your VPS ID.

  • –ostemplate ubuntu-9.04-x86_64 : VPS template.

  • –config vps.ubuntu: Save configuration.

  • set 10 : Set various option for VPS ID # 10.

  • –onboot yes : Make sure VPS boots automatically after a reboot.

  • –save : Save changes to config file.


Common OpenVZ Admin Tasks

vzctl act as a master tool for various tasks:

How Do I Set VPS Name to ourlinuxblog.wordpress.com ?
# vzctl set 10 –hostname ourlinuxblog.wordpress.com –save

How Do I Set VPS IP Address?
# vzctl set 10 –ipadd 74.86.48.99 –save

How Do I Set VPS DNS Name Servers?
# vzctl set 10 –nameserver 10.0.1.11 –save

How Do I Set Disk Quota?
# vzctl set 10 –diskspace SoftLimitG:HardLimitG –save

# vzctl set 10 –diskspace 10G:12G –save

How Do I Stop / Start / Restart VPS Servers?
# vzctl start 10
# vzctl restart 10
# vzctl stop 10

How Do I Run a Command For VPS?

You can run command as follows
# vzctl exec 10 w
# vzctl exec 10 df
# vzctl exec 10 date
# vzctl exec 10 ps aux

How Do I Login Into VPS Server (container)?
# vzctl enter 10

How Do I Delete VPS?

Type the following command to delete VPS:
# vzctl destroy 10

Wednesday 24 November 2010

cPanel, Lxadmin or Direct Admin – Roundcube issues

cPanel, Lxadmin or Direct Admin – Roundcube issues – SERVICE CURRENTLY NOT AVAILABLE! Error No. [500] / Error No. [0x01F4]

On cPanel, just update roundcube

/usr/local/cpanel/bin/update-roundcube --force

On Lxadmin, just re-install

rm /var/cache/lxadmin/lxwebmail*
lphp.exe ../bin/misc/installRoundCube.php
/script/upcp


On DirectAdmin

check logs   var/www/html/roundcube/logs/error

just deleted da_roundcube
and ./build roundcube

solved the problem

Monday 22 November 2010

ack up From the Command Line (using mysqldump)

If you have shell or telnet access to your web server, you can backup your MySQL data by using the mysqldump command. This command connects to the MySQL server and creates an SQL dump file. The dump file contains the SQL statements necessary to re-create the database. Here is the proper syntax:
# mysqldump --opt -u [uname] -p[pass] [dbname] > [backupfile.sql]

  • [uname] Your database username

  • [pass] The password for your database (note there is no space between -p and the password)

  • [dbname] The name of your database

  • [backupfile.sql] The filename for your database backup

  • [--opt] The mysqldump option

  • For example, to backup a database named 'Tutorials' with the username 'root' and with no password to a file tut_backup.sql, you should accomplish this command:
    # mysqldump -u root -p Tutorials > tut_backup.sql

    This command will backup the 'Tutorials' database into a file called tut_backup.sql which will contain all the SQL statements needed to re-create the database.

    With mysqldump command you can specify certain tables of your database you want to backup. For example, to back up only php_tutorials and asp_tutorials tables from the 'Tutorials' database accomplish the command below. Each table name has to be separated by space.
    # mysqldump -u root -p Tutorials php_tutorials asp_tutorials > tut_backup.sql

    Sometimes it is necessary to back up more that one database at once. In this case you can use the --database option followed by the list of databases you would like to backup. Each database name has to be separated by space.
    #  mysqldump -u root -p --databases Tutorials Articles Comments > content_backup.sql

    Back up your MySQL Database with Compress

    If your mysql database is very big, you might want to compress the output of mysqldump. Just use the mysql backup command below and pipe the output to gzip, then you will get the output as gzip file.
    #  mysqldump -u [uname] -p[pass] [dbname] | gzip -9 > [backupfile.sql.gz]

    If you want to extract the .gz file, use the command below:
    # gunzip [backupfile.sql.gz]

    Backing Up and Restoring using PHPMyAdmin

    It is assumed that you have phpMyAdmin installed since a lot of web service providers use it. To backup your MySQL database using PHPMyAdmin just follow a couple of steps:

    • Open phpMyAdmin.

    • Select your database by clicking the database name in the list on the left of the screen.

    • Click the Export link. This should bring up a new screen that says View dump of database (or something similar).

    • In the Export area, click the Select All link to choose all of the tables in your database.

    • In the SQL options area, click the right options.

    • Click on the Save as file option and the corresponding compression option and then click the 'Go' button. A dialog box should appear prompting you to save the file locally.


    Restoring your database is easy as well as backing it up. Make the following:

    • Open phpMyAdmin.

    • Create an appropriately named database and select it by clicking the database name in the list on the left of the screen. If you would like to rewrite the backup over an existing database then click on the database name, select all the check boxes next to the table names and select Drop to delete all existing tables in the database.

    • Click the SQL link. This should bring up a new screen where you can either type in SQL commands, or upload your SQL file.

    • Use the browse button to find the database file.

    • Click Go button. This will upload the backup, execute the SQL commands and re-create your database.

    Missing HOST Config Line in /etc/wwwacct.conf, please reconfigure with Edit Setup

    Missing HOST Config Line in /etc/wwwacct.conf, please reconfigure with Edit Setup

    If you are getting this error during account creation or account transfer

    Account Creation Status: failed (Missing HOST Config Line in /etc/wwwacct.conf, please reconfigure with Edit Setup.)
    Missing HOST Config Line in /etc/wwwacct.conf, please reconfigure with Edit Setup.

    or Missing HOST Config Line in /etc/wwwacct.conf, please reconfigure with Edit Setup.


    then this can be solved by editing /etc/wwwacct.conf file. Issue the following commands in ssh:

    nano /etc/wwwacct.conf

    Enter the server's hostname in HOST field.

    Then press Ctrl+X and then Y.

    Restoring your MySQL Database

    Create an appropriately named database on the target machine
    Load the file using the mysql command:
    # mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]

    Have a look how you can restore your tut_backup.sql file to the Tutorials database.
    # mysql -u root -p Tutorials < tut_backup.sql

    To restore compressed backup files you can do the following:
    # gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]

    If you need to restore a database that already exists, you'll need to use mysqlimport command. The syntax for mysqlimport is as follows:
    # mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]

    How to backup your MySQL database

    Wednesday 17 November 2010

    Managing Log Files and Log Rotation

    Plesk allows managing log files and log rotation settings from the control panel. To access these functions, click the  Log Manager icon on the Domain Administration page. The Log Manager page will open:



    • Define the number of log file's lines to be displayed at once. To do that, type in the number of lines in the Lines of log file to be displayed input field prior to selecting a log file for viewing.

    • View a log file. To this effect, click on a log file's name in the list. The log file contents will be displayed in a separate Log File Viewer window.

    • Save a log file on your local machine. To do that, click on the appropriate  icon. After that you will need to specify the location on your local machine and the file name for the downloaded log file to be saved, and then click Save.

    • Delete log files. To this effect, select the corresponding checkboxes, and click Remove Selected.


    To configure the log rotation preferences, follow these steps:

    1. Click the  Log Rotation icon on the Log Files Management page. The Log Rotation Preferences page will open:

    2. Click the  Enable or  Disable icon respectively to enable/disable log rotation.

    3. Select the log rotation condition:                                                                                      a)  log file size - enter the size in kilobytes in the appropriate field.

    4. Specify the maximum number of log files in the appropriate input field, if desired. The maximum number is the number of processed files to be kept for each log file.

    5. Select the Compress log files checkbox to enable compression.

    6. If desired, in the Send processed log files to e-mail input field, enter the e-mail address, for the processed log files to be delivered to.

    7. Click OK to submit changes.

    Tuesday 16 November 2010

    Delete an IP address from linux cPanel dedicated server

    Normally, to delete an IP from a cPanel server you can login to WHM and remove the IP using the function “Show or delete current IP address” under “IP functions” or use linux command.

    For some reason we were having problems with the datacenter and we were asked to remove the IP using KVM. In this case, we entered the KVM and checked the if the IP was listed on the server by using ifconfig – we found that the IP was listed there. To remove the IP edit the file.
    root@server# nano /etc/ips

    and now remove the line of the IP and then restart the ipaliases service by the command
    root@server# service ipaliases restart

    It will show failed, you can ignore those warnings. And you can recheck if the IP has gone by using the command ifconfig. You’ll see the IP is not seen in the ifconfig output. Now, you can ask the datacenter to get the server online and then if you check from the WHM you will see that the IP is not available there.

    That’s it!

    Wednesday 10 November 2010

    How to find out Windows uptime?

    1.  Go to "Start" -> "Run".

    2.  Write "CMD" and press on "Enter" key.

    3.  Write the command "net statistics server" and press on "Enter" key.

    4.  The line that start with "Statistics since …" provides the time that the server was up from.

    • The command "net stats srv" can be use instead.

    Saturday 6 November 2010

    Fixing Permissions of Valiases

    Tthis script a while back to fix the permissions of alias files in /etc/valiases when users were having trouble creating forwarders. You can also download the script in plaintext here.
    #!/bin/bash
    # Script to fix permissions of valiases
    # Written by: Vanessa Vasile 5/17/10
    # http://thecpaneladmin.com


    for domain in `cat /etc/userdomains |awk '{print $1}' | grep -v "*" | cut -d: -f1`
    do

    if ! [ -f /etc/valiases/$domain ]; then
    touch /etc/valiases/$domain
    fi

    user=$(egrep "^$domain:" /etc/userdomains |awk '{print $2}');
    chown $user:mail /etc/valiases/$domain
    chown $user:mail /etc/vdomainaliases/$domain
    chmod 644 /etc/valiases/$domain
    chmod 644 /etc/vdomainaliases/$domain
    done

    Installing A Wildcard SSL Certificate

    A wildcard ssl basically allows you to use unlimited subdomains on a given domain name with one SSL certificate.  A user will need to purchase a wildcard SSL from a vendor that supplies them.

    Similar to having multiple certificates installed on a server, each subdomain containing the certificate needs its own IP as well.  Wildcard SSL’s do not work like Wildcard DNS – you really do have to specifically install the certificate on each subdomain. Here are two methods to setting up Wildcard certificates for a domain.

    Multiple Accounts

    In this scenario, you’d have each subdomain hosted as a separate cPanel account, and each of those cPanel accounts will have its own IP address.

    1. Generate the Certificate Signing Request (CSR) in WHM, using *.domain.com

    2. Read this article to learn how to assign each account its own IP address

    3. When you’re obtained the certificate,go to WHM > Install a SSL Certificate and Setup the Domain and paste in the CRT and CA Bundle for *.domain.com

    4. The fields should auto-populate, in which case you need to make sure the IP is correct, then change the SSL hostname from *.domain.com to the target subdomain

    5. Click install to install the certificate


    One Account

    This method may be best for users that are not resellers or that are on shared hosting servers, where having multiple cpanel accounts may not be ideal. In this case, you’d have one cPanel account and assign multiple IPs to its subdomains.

    1. Generate the Certificate Signing Request (CSR) in WHM, using *.domain.co

    2. Read this article to learn how to assign dedicated IPs to multiple subdomains on the same account

    3. When you’re obtained the certificate,go to WHM > Install a SSL Certificate and Setup the Domain and paste in the CRT and CA Bundle for *.domain.com

    4. The fields should auto-populate, in which case you need to make sure the IP is correct, then change the SSL hostname from *.domain.com to the target subdomain

    5. Click install to install the certificate

    How to Rebuild cPanel Bandwidth Graphs

    Cpanel 11.25 restructured the way that bandwidth RRD files are being processed, in that each service has two RRD files – one for peak, and one for rate.  The “peak” file is used for long timespans of a month or longer, and the “rate” file covers a timespan of a week or less.  The following is an example of files that would be created for domain.com:

    domain
    domain.com.5min
    domain.com.hour
    domain.com
    domain.com.5min
    domain.com.hour

    Re rebuild the RRD databases for a user, run:
    /usr/local/cpanel/bin/rebuildbwrrd

    To do this for the entire server:
    /usr/local/cpanel/bin/rebuildbwrrd –all

    Beware though that cPanel 11.25 requires a  bit more disk space for the new bandwidth graphs, so if you have /var on a separate partition and there won’t be enough room, I recommend doing the following:
    mv /var/cpanel/bandwidth /home

    ln -s /home/bandwidth /var/cpanel/bandwidth

    You’re basically moving the bandwidth graphs to another location and linking them to /var/cpanel/bandwidth.

    How to install Subversion and Java

    Install Subversion and Java


    yum -y install java-1.6.0-openjdk java-1.6.0-openjdk-devel
    yum -y install subversion

    Install Ant


    cd /opt
    wget http://mirrors.kahuki.com/apache/ant/binaries/apache-ant-1.8.1-bin.tar.bz2
    tar jxvf apache-ant-1.8.1-bin.tar.bz2
    mv apache-ant-1.8.1 ant
    ln -s /opt/ant/bin/ant /usr/bin/ant


    Result: /opt/ant

    Export some variables and add to bashrc:


    export ANT_HOME=/opt/ant
    export JAVA_HOME=/usr/lib/jvm/java
    export PATH=$PATH:/opt/ant/bin
    export CLASSPATH=.:$JAVA_HOME/lib/classes.zip


    echo 'export ANT_HOME=/opt/ant' >> /etc/bashrc
    echo 'export JAVA_HOME=/usr/lib/jvm/java' >> /etc/bashrc
    echo 'export PATH=$PATH:/opt/ant/bin' >> /etc/bashrc
    echo 'export CLASSPATH=.:$JAVA_HOME/lib/classes.zip' >> /etc/bashrc

    Install Red5:


    cd /opt
    svn co http://red5.googlecode.com/svn/java/server/trunk red5
    cd red5
    ant prepare
    ant dist

    Create an init script


    By default you have to use red5?s inherent scripts to start/stop, which can be a bit annoying. Create a file called /etc/init.d/red5 and past int he following:

    #!/bin/sh
    # For RedHat servers
    # description: Red5 flash media server
    # processname: red5
    PROG=red5
    RED5_HOME=/opt/red5
    DAEMON=$RED5_HOME/$PROG.sh
    PIDFILE=/var/run/$PROG.pid
    # Source function library
    . /etc/rc.d/init.d/functions
    [ -r /etc/sysconfig/red5 ] && . /etc/sysconfig/red5
    RETVAL=0
    case "$1" in
    start)
    echo -n $"Starting $PROG: "
    cd $RED5_HOME
    $DAEMON >/dev/null 2>/dev/null &
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
    echo $! > $PIDFILE
    touch /var/lock/subsys/$PROG
    fi
    [ $RETVAL -eq 0 ] && success $"$PROG startup" || failure $"$PROG startup"
    echo
    ;;
    stop)
    echo -n $"Shutting down $PROG: "
    killproc -p $PIDFILE
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROG
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    status)
    status $PROG -p $PIDFILE
    RETVAL=$?
    ;;
    *)
    echo $"Usage: $0 {start|stop|restart|status}"
    RETVAL=1
    esac
    exit $RETVAL


    *Note that WordPress has a strange way of outputting double quotes, so make sure you address those in the script!
    Now, chmod 755 /etc/init.d/red5 and run:
    chkconfig red5 on

    This will run Red5 on startup. With the init script, you can now start, stop, and restart red5 as needed, ex:
    service red5 restart

    red5 should now run port 5080 and rtmp service on port 1935. You may need to open these ports in your server’s firewall.

    Test:


    http://hostname:5080/demos/port_tester.swf