Monday, April 6, 2015

Usage Server


The Usage Server takes data from the events in the system and enables usage-based billing for accounts in cloudstack. The usage records show the amount of resources, such as VM run time or template storage space, consumed by guest instances.When multiple Management Servers are present, the Usage Server may be installed on any number of them. The Usage Servers will coordinate usage processing. A site that is concerned about availability should install Usage Servers on at least two Management Servers.The Usage Server runs at least once per day. It can be configured to run multiple times per day.


For install Usage server

yum install cloudstack-usage 
Once installed, start the Usage Server with the following command.
service cloudstack-usage start
Enable the service at boot
chkconfig cloudstack-usage on
Global Paramiters need to change by requirement


 
In MYSQL-database there is a database cloud_usage contain all the information with time stamp.                   
usage_event               
 usage_event_details       
 usage_ip_address          
 usage_job                 
 usage_load_balancer_policy
 usage_network             
 usage_network_offering    
 usage_port_forwarding     
 usage_security_group      
 usage_storage             
 usage_vm_disk             
 usage_vm_instance         
 usage_vmsnapshot          
 usage_volume              
 usage_vpn_user            
 user_statistics           
 vm_disk_statistics     

Example-mysql> select * from usage_event\G
id: 378
type: VM.CREATE
account_id: 2
created: 2015-04-06 09:27:01
zone_id: 1
resource_id: 37
resource_name: mycent1
offering_id: 27
template_id: 5
size: NULL
resource_type: XenServer
processed: 1
virtual_size: NULL

When you what to check usage record by using api fallow the below
 


Here I am generate usage record for one account for one day.

http://192.168.0.41:8080/client/api?command=listUsageRecords&response=xml&sessionkey=P18GL7ltdP8pyMEZpgTpWfOJm1w%3D&listAll=true&page=1&pagesize=20&_=1428322026900&&&startdate=2015-04-05&enddate=2015-04-06


Monday, March 30, 2015

Wordpress

Install Wordpress on Centos 6
Step One—Download WordPress
We can download Wordpress straight from their website:
wget http://wordpress.org/latest.tar.gz
This command will download the zipped wordpress package straight to your user's home directory. You can unzip it the the next line:
tar -xzvf latest.tar.gz
Step Two—Create the WordPress Database and User
After we unzip the wordpress files, they will be in a directory called wordpress in the home directory.
Now we need to switch gears for a moment and create a new MySQL directory for wordpress.
Go ahead and log into the MySQL Shell:
Mysql –u root -p

Login using your MySQL root password, and then we need to create a wordpress database, a user in that database, and give that user a new password. Keep in mind that all MySQL commands must end with semi-colon. First, let's make the database (I'm calling mine wordpress for simplicity's sake; feel free to give it whatever name you choose):
CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

Then we need to create the new user. You can replace the database, name, and password, with whatever you prefer:
CREATE USER wordpressuser@localhost;
Query OK, 0 rows affected (0.00 sec)

Set the password for your new user:
SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
Query OK, 0 rows affected (0.00 sec)
Finish up by granting all privileges to the new user. Without this command, the wordpress installer will not be able to start up:
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)
Then refresh MySQL:
FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
Exit out of the MySQL shell:
exit
Step Three—Setup the WordPress Configuration
The first step to is to copy the sample wordpress configuration file, located in the wordpress directory, into a new file which we will edit, creating a new usable wordpress config:
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
Then open the wordpress config:
vi ~/wordpress/wp-config.php
Find the section that contains the field below and substitute in the correct name for your database, username, and password:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');
Save and Exit.
Step Four—Copy the Files
We are almost done uploading Wordpress to the server. The final move that remains is to transfer the unzipped WordPress files to the website's root directory.
sudo cp -r ~/wordpress/* /var/www/html
From here, WordPress has its own easy to follow installation form online.However, the form does require a specific php module to run. If it is not yet installed on your server, download php-gd:
sudo yum install php-gd
Last of all restart Apache:
 sudo service httpd restart
Step Five—RESULTS: Access the WordPress Installation
Once that is all done, the wordpress online installation page is up and waiting for you:
Access the page by adding /wp-admin/install.php to your site's domain or IP address (eg. example.com/wp-admin/install.php) and fill out the short online form (it should look like this).


Troubleshot- Unable to create directory wp-content/uploads/2015/03

Change the user permissions on the folder wp-content to 777


Path cd /var/www/html

Tuesday, March 17, 2015

SSL





Enabling SSL in the CloudStack UI

Back up and edit /etc/cloud/management/server.xml. By default the HTTPS configuration is commented out, so uncomment it and update it as necessary. Note that Tomcat runs as the "cloud" user and not root, so an unprivileged port (1025/tcp or above) must be used and the keystore file will need appropriate permissions. Include the password you will use for the certificate
Modify server.xml
 /etc/cloud/management/server.xml

                                                         Original file



/etc/cloud/management/server.xml

                                                         Modify and uncomment the 8443 port

Create SSL key
Obtain Certificate
·        Follow your organization's standard procedures to generate and obtain a certificate suitable for securing a website. For example, generate a private key:
     openssl genrsa 1024 > cloud.key

Submit the CSR to a certificate authority (for example, DigiNotar...) and get the 
certificate, or generate a self-signed certificate as follows: 
openssl x509 -req -in cloud.csr -signkey cloud.key > cloud.crt


     Alternately, you can generate a CSR to have signed by a valid CA - implemention (for now) left as an exercise for the reader. Either way, the cert must be stored in a keystore, as described below.
·        Create a PKCS12 format keystore using the private key and signed certificate:
    openssl pkcs12 -export -in cloud.crt -inkey cloud.key -name cloud -passout pass:password > /usr/share/cloud-management/conf/cloud-localhost.pk12

Restart CloudStack


Configure iptables
If iptables is in use, update the rules to allow access to the configured port.
iptables -I INPUT 1 -p tcp -m tcp --dport 8443 -j ACCEPT

Optionally, enable redirection from 443/tcp in iptables(Apply natic table rule)

 iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443

service iptables save

Thursday, March 12, 2015

HAProxy &Keepalived

HAProxy &Keepalived
       For configuring HA-Load balancer, You need 2 virtual/physical servers for the load-balancers and 2 virtual/physical servers to load-balance. In addition to the 4 IP addresses needed by the servers themselves, a fifth virtual IP address (VIP) is necessary. The two load-balancers and the VIP need to be in the same network segment.
HAProxy and keepalived. So, HAProxy will be used as load-balancing software, keepalived as high availability solution and apache as software to load-balance.

Load Balancer 1: haproxy1.psi.com, IP address: 192.168.0.25
Load Balancer 2: haproxy2.psi.com, IP address: 192.168.0.26
MGMT Server 1: mgmt1.psi.com, IP address: 192.168.0.21
MGMT Server 2: mgmt1.psi.com, IP address: 192.168.0.22
We also need a virtual IP address that floats between lb1 and lb2: 192.168.0.31
Here's a little diagram that shows our setup:

    shared IP=192.168.0.31
   192.168.0.25     192.168.0.26        192.168.0.21            192.168.0.22
 -------+--------- ---+--------------+-----------+-----------------+--------- ---+--------------+
    |                          |                      |       |                       |             |                        |
     +--+--+ +--+--+ +----+----+ +----+----+ +----+----+ +----+----+ +----+----+ +----+--
     | lb1 |                    | lb2 |                 |  http1  |                           |  http2  |
     +-----++-----+ +---------+ +---------+ +---------+ +---------+ +---------+ +---------+
     haproxy              haproxy                                  2 MGMT servers (Apache)
     keepalived        keepalived





HAProxy Configuration on server 1
HaProxy configuration-
   #Yum install haproxy
Copy the below configuration file below defaults and change the portnumber,name of the server& server ip by requirements
vi /etc/haproxy/haproxy.conf
listen cloudstack_ui_443(Port https-443,Http-8080)
bind *:443
mode http     
 balance source
server mgmt1.psi.com 192.168.0.21:443 cookie A check(Server name&IP address)
server mgmt2.psi.com 192.168.0.22:443 cookie B check(Server name&IP address)
      listen cloudstack_systemvm_8250(System VM-Mgmt server port port)
            bind *:8250
            mode tcp
            balance source
server mgmt1.psi.com 192.168.0.21:8250 maxconn 32 check (Servername&IP address)
server mgmt2.psi.com 192.168.0.22:8250 maxconn 32 check (Servername&IP address) 

Keepalived configuration on server 1(used for virtual ip creation)
        #Yum install keepalived
•         cp /etc/keepalived/keepalived.conf  /etc/keepalived/keepalived.conf.orig(Copy original file and keep it as a backup)
•         Open vi editor and copy below content in to configuration file(192.168.0.31 virtual ip)
vi /etc/keepalived/keepalived.conf
  vrrp_script chk_haproxy {
    script "killall -0 haproxy" # check the haproxy process
    interval 2 # every 2 seconds
    weight 2 # add 2 points if OK
 }
 vrrp_instance VI_1 {
     interface eth0 # interface to monitor
     state MASTER # MASTER on haproxy1, BACKUP on haproxy2
     virtual_router_id 77 
     priority 200 # 101 on haproxy1, 100 on haproxy2 
  virtual_ipaddress {     
    192.168.0.31 #dev eth0 # virtual ip address 
  }  
  track_script   {
      chk_haproxy 
  }
} 

HAProxy Configuration on server 2
HaProxy configuration-
   #Yum install haproxy
Copy the below configuration file below defaults and change the portnumber,name of the server& server ip by requirements
vi /etc/haproxy/haproxy.conf
listen cloudstack_ui_443(Port https-443,Http-8080)
bind *:443
mode http     
 balance source
server mgmt1.psi.com 192.168.0.21:443 cookie A check(Server name&IP address)
server mgmt2.psi.com 192.168.0.22:443 cookie B check(Server name&IP address)
      listen cloudstack_systemvm_8250(System VM-Mgmt server port port)
            bind *:8250
            mode tcp
            balance source
server mgmt1.psi.com 192.168.0.21:8250 maxconn 32 check (Servername&IP address)
server mgmt2.psi.com 192.168.0.22:8250 maxconn 32 check (Servername&IP address)

To check keep alive status: ip addr | grep eth0




Keepalived configuration on server 2(used for virtual ip creation)
        #Yum install keepalived
•         cp /etc/keepalived/keepalived.conf  /etc/keepalived/keepalived.conf.orig(Copy original file and keep it as a backup)
•         Open vi editor and copy below content in to configuration file(192.168.0.31 virtual ip)
vi /etc/keepalived/keepalived.conf
  vrrp_script chk_haproxy {
    script "killall -0 haproxy" # check the haproxy process
    interval 2 # every 2 seconds
    weight 2 # add 2 points if OK
 }
 vrrp_instance VI_1 {
     interface eth0 # interface to monitor
    state MASTER # MASTER on haproxy1, BACKUP on haproxy2
     virtual_router_id 77 
     priority 111 # 101 on haproxy1, 100 on haproxy2 
  virtual_ipaddress {     
    192.168.0.31 #dev eth0 # virtual ip address 
  }  
  track_script   {
      chk_haproxy 
  }
}

 To check keep alive status: ip addr | grep eth0


DB Replication



DB Replication

CloudStack supports database replication from one MySQL node to another. This is achieved using standard MySQL replication. You may want to do this as insurance against MySQL server or storage loss. MySQL replication is implemented using a master/slave model. The master is the node that the Management Servers are configured to use. The slave is a standby node that receives all write operations from the master and applies them to a local, redundant copy of the database. The following steps are a guide to implementing MySQL replication.


                                         DB Replication


Master server
1)Ensure that this is a fresh install with no data in the master.
Edit my.cnf on the master and add the following in the [mysqld] section below datadir.
    # vi /etc/my.cnf
     log_bin=mysql-bin
     server_id=1
2)Restart the MySQL service:
    #service mysqld restart
3)Create a replication account on the master and give it privileges. We will use the "cloud-repl" user with the password "password". This assumes that master and slave run on the 192.168.0.0/24 network.
    #mysql -u root -p
  Mysql> create user 'cloud-repl'@'192.168.0.%' identified by 'XXXX';
  Mysql>grant replication slave on *.* TO 'cloud-repl'@'192.168.0.%';
  Mysql> flush privileges;
  Mysql>flush tables with read lock;
4)Leave the current MySQL session running.In a new shell start a second MySQL session. Retrieve the current position of the database.
     #mysql -u root -p
     Mysql>show master status; 
+------------------+--------+--------------+------------------+-----------------+ ------+
| File                     | Position      | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+-----------------+----
| mysql-bin.000007 | 175307681|                              |                                  |
+------------------+----------+--------------+------------------+ -----------------+----
5)Note the file and the position that are returned by your instance. Exit from this session.
Complete the master setup. Returning to your first session on the master, release the locks and exit MySQL.
         #mysql>unlock tables;
Slave server
1)Edit my.cnf and add the following lines in the [mysqld] section below datadir.
  #vi /etc/my.cnf
  #log_bin=mysql-bin(comment the line)
   server_id=2
2)Restart MySQL.
   #service mysqld restart
3)Instruct the slave to connect to and replicate from the master. Replace the IP address, password, log file, and position with the values you have used in the previous steps.
Mysql>change master to master_host='192.168.0.23',master_user='cloud-repl', master_password='XXXX', master_log_file='mysql-bin.000007', master_log_pos=175307681;
4)Then start replication on the slave.
#start slave;
#Show slave status;


Test For DB Replication

1)Create an account in UI as a administrator
2)Go to Slave DB
            log in to my sql
                             Use cloud database
                                               Show account
Find new user account details with time stamp
               


Thursday, January 8, 2015

Apache cloudstack 4.4.2 installation on malty node

Apache cloudstack 4.4.2 installation on malty node.

Minimum System Requirements
Operating system:
Preferred: CentOS/RHEL 6.3+ or Ubuntu 12.04(.1)
64-bit x86 CPU (more cores results in better performance)
8 GB of memory
250 GB of local disk (more results in better capability; 500 GB recommended)
At least 1 NIC
Statically allocated IP address
Fully qualified domain name as returned by the hostname command
Configuring Management server –Linux vm1.
1)To configure static ip
#vi /etc/sysconfig/network-scripts/ifcfg-eth0
i)Ip should be static(BOOTPROTO=static)
ii)ONBOOT=yes
2)To check Hostfull name command
hostname –fqdn (host full name) if hostname not available goto below file and edit the details
#vi /etc/sysconfig/network
HOSTNAME=csmgmt1.cloud.com

Also give entry for hostname
#vi /etc/hosts
192.168.0.12(vm ip)=csmgmt1.cloud.com

To update hostname run the command
#Hostname csmgmt1
3)Resolve.conf use to direct the hostnames
vi /etc/resolve.conf
 nameserver 8.8.8.8
4 )ping www.cloudstack.org to check internet connectivity
5)Create the file with the help of vi editor and enter the below commands it is help to download the packages for cloudstack.
#vi /etc/yum.repos.d/cloudstack.repo
[cloudstack]
name=cloudstack
baseurl=http://cloudstack.apt-get.eu/rhel/4.4/
enabled=1
gpgcheck=0
6)Network time protocol  is a protocol that is used to synchronize computer clock times in a network of computers. NTP uses Coordinated Universal Time (UTC) to synchronize computer clock times to a millisecond, and sometimes to a fraction of a millisecond
#yum install ntp
7) Selinux-CloudStack can be blocked by security mechanisms, such as SELinux. Disable SELinux to ensure + that the Agent has all the required permissions.
SELINUX=permissive
7.a) setenforce permissive
8)cloudstack-installation The CloudStack Management server can be installed using either RPM or DEB packages. These packages will depend on everything you need to run the Management server
#yum install cloudstack-management
9) Vhd-utilsThis procedure is required only for installations where XenServer is installed on the hypervisor hosts.Before setting up the Management Server
#cd /usr/share/cloudstack-common/scripts/vm/hypervisor/xenserver
In this location download vhd utils 
 wget http://download.cloud.com.s3.amazonaws.com/tools/vhd-util
Configuring Database server –Linux vm2.
 1) Configure static ip
 2)check fully qualified domain name
3) Resolve.conf use to direct the hostnames
4) ping www.cloudstack.org to check internet connectivity
1 ) Install MySQL from the package repository of your distribution
#yum install mysql-server
2) Open the MySQL configuration file. The configuration file is vi /etc/my.cnf (or)vi /etc/mysql/my.cnf, depending on your OS.Insert the following lines in the [mysqld] section.You can put these lines below the datadir line. The max_connections parameter should be set to 350 multiplied by the number of Management Servers you are deploying. This example assumes one Management Server.
 #vi /etc/my.cnf
Insert the following lines below [mysqld] section
innodb_rollback_on_timeout=1
innodb_lock_wait_timeout=600
max_connections=700
log-bin=mysql-bin
binlog-format = 'ROW'

3) Start or restart MySQL to put the new configuration into effect
#service mysqld start
4 ) restart MySQL
#service mysql restart
5 ) Run the following command to secure your installation. You can answer “Y” to all questions
#mysql_secure_installation(optional)
6 )To give all permissions to user “cloud” run the below command on DB server
#mysql -u root –p (to enter in to mysql db)
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;(grant permissions-root)
>GRANT ALL PRIVILEGES ON *.* TO 'cloud'@'%' WITH GRANT OPTION;( grant permissions-cloud)
Run Below Command in Management server
10 )Set up the database. The following command creates the “cloud” user on the database.
#cloudstack-setup-databases cloud:"password"@dbserverip --deploy-as=root:"password"
11)To check cloudstack running status
12) Now that the database is set up, you can finish configuring the OS for the Management Server. This command will set up iptables, sudoers, and start the Management Server
#cloudstack-setup-management
13)To download teplet
/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -m /mnt/secondary -u http://cloudstack.apt-get.eu/systemvm/4.4/systemvm64template-4.4.1-7-xen.vhd.bz2 -h xenserver
If XenServer is installed on the hypervisor hosts
#xe-switch-network-backend bridge
 enable security groups, elastic load balancing, and elastic IP on XenServer, download and install the CloudStack XenServer Support Package (CSP). After installing XenServer, perform the following additional steps on each XenServer host.