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