2013年7月26日星期五

FW: openfire cluster

Openfire + Hazelcast on Amazon EC2

I have been searching high and low for something, somwhere, to guide me on this beast that is clustering. After shedding a few liters of blood sweat and tears, I finally was able to get my cluster up.
This post should prove useful for my future self. You’re welcome, future self.
The end result: One DB server, a cluster of Openfire servers and a load balancer to distribute traffic. Sweet!

Launch an Instance

  1. Launch an EC2 Instance, in my case I used a micro instance for testing. Just follow the Request Instance Wizard and you’ll be fine.
  2. Take note of your key-pair. Download it, keept it and savor it’s essence.
  3. When setting up your firewall, free dem ports:
    • 22 (SSH)
    • 3478
    • 3479
    • 5222
    • 5701
    • 7070
    • 7443
    • 7777
    • 9090
    • 9091
  4. SSH to your server by doing ssh -i your_pem_file.pem ubuntu@your-instance-public-dns

Launch a DB Server on RDS

  1. I’m using MySQL, so I’m just gonna go ahead and choose that.
  2. Name your database appropriately.
  3. Remember your Master Username and Password. You’re gonna need it.
  4. Update your RDS security groups. Head on to the RDS console and select DB Security Groups. Add your EC2 instance to the list as an EC2 Security Group.

Setup Openfire

  1. Install Java with:
     sudo add-apt-repository ppa:webupd8team/java
     sudo apt-get update
    
     sudo apt-get remove --purge openjdk*
     sudo apt-get install oracle-java-7-installer
    
     java -version
    
  2. Install Openfire with:
     wget -O openfire.tar.gz http://www.igniterealtime.org/downloads/download-landing.jsp?file=openfire/openfire_3_8_1.tar.gz
    
    Change the version to the latest stable available. Then untar and move like so:
     tar -xzvf openfire.tar.gz
     mv openfire/ /opt
    
  3. Edit your hosts file in /etc/hosts and add a line to let the server know what’s its name is. Hosts file should look like:
     127.0.0.1 localhost
     127.0.1.1 ubuntu
     127.0.0.1 chat.yourdomain.com
    
  4. Run Openfire by going to /your_openfire_directory/bin and running ./openfire start
  5. Visit http://your-instance-public-dns:9090 and it should give you the first step for the Openfire setup wizard. Plow through the wizard like a champ. Just remember the following important points:
    • The host should be the one you set in your /etc/hosts file a while ago.
    • The database host should be the host on the RDS DB server from the setup above.
    • The database username and password is your MASTER username and password from RDS.
  6. Install Hazelcast! On your Openfire Admin Panel, Go to Plugins > Available Plugins > Install. If you don’t see any plugins on the Available Plugins page, you can find an update link on the page.
  7. Go back to the terminal and we’ll change a few settings for the cluster to work. Edit the file in /your_openfire_directory/plugins/hazelcast/classes/hazelcast-cache-config.xml. Find the <network> tag and we should configure it like so:
    ...
    <port auto-increment="true">5701</port>
    <join>
      <multicast enabled="false" />
      <tcp-ip enabled="true">
        <hostname>private-ip-address-of-this-machine:5701</hostname>
      </tcp-ip>
      <aws enabled="false"/>
    </join>
    <interfaces enabled="true">
      <interface>private-ip-address-of-this-machine</interface>
    </interfaces>
    ...
    
    The private IP address of your machine can be found on your Amazon EC2 Console on the instance details under Private IPs.
  8. Restart your Openfire server by going to /your_openfire_dir/bin and doing ./openfire stop and ./openfire start Visit your Openfire Admin Console and enable clustering. You should be able to join a cluster with one node running. Neat.

Growing your Openfire army

  1. On the EC2 Console, create an AMI of the Openfire instance. Launch a new instance using the AMI.
  2. On the wizard, use the same settings as we had with the other instance.
  3. SSH to the new server and edit /your_openfire_directory/plugins/hazelcast/classes/hazelcast-cache-config.xml. The config should now look like:
    ...
    <port auto-increment="true">5701</port>
    <join>
      <multicast enabled="false" />
      <tcp-ip enabled="true">
        <hostname>private-ip-of-the-other-machine:5701</hostname>
        <hostname>private-ip-address-of-this-machine:5701</hostname>
      </tcp-ip>
      <aws enabled="false"/>
    </join>
    <interfaces enabled="true">
      <interface>private-ip-address-of-this-machine</interface>
    </interfaces>
    ...
    
    Make sure the IP addresses for the machine is correct.
  4. Restart Openfire.
  5. Go to the Openfire Admin Console and enable clustering.
  6. SSH to the server that we first set up and edit the hazelcast config file. Add a new <hostname> line on the file with the IP address of the new instance we just created.
  7. Restart Openfire for that
  8. Just repeat the process should you want to add more instances to the cluster.

Setup Load Balancing

  1. On the EC2 Console under Load Balancers, create a new load balancer.
  2. Open up these ports under Load Balancers > Listeners:
    • HTTP 80
    • TCP 3478
    • TCP 3479
    • TCP 5222
    • TCP 5262
    • HTTP 9090
    • HTTP 7070
    If you need SSL, you need to upload them and attach them to a listener.

Final Steps

On your DNS manager, make a CNAME record that points to the load balancer, and that’s it!
If you’re stuck or can’t get this to work and you think I might be of help, drop me an email vincent.paca@gmail.com.

WHost '*' is not allowed to connect to this MySQL serverConnection closed by foreign host.

grant all privileges on *.* to 'root'@'your ip' identified by 'your password';

FW: Change mysql folder

MySQL is a widely used and fast SQL database server. It is a client/server implementation that consists of a server daemon (mysqld) and many different client programs/libraries.

If you want to install Mysql database server in Ubuntu check this tutorial.

What is Mysql Data Directory?
Mysql data directory is important part where all the mysql databases storage location.By default MySQL data default directory located in /var/lib/mysql.If you are running out of space in /var partition you need to move this to some other location.
Note:- This is only for advanced users and before moving default directory make a backup of your mysal databases.
Procedure to follow
Open the terminal
First you need to Stop MySQL using the following command
sudo /etc/init.d/mysql stop
Now Copy the existing data directory (default located in /var/lib/mysql) using the following command
sudo cp -R -p /var/lib/mysql /path/to/new/datadir
All you need are the data files, so delete the others with the command
sudo rm /path/to/new/datadir
Note:- You will get a message about not being able to delete some directories, but that's what you want.
Now edit the MySQL configuration file with the following command
gksu gedit /etc/mysql/my.cnf
Look for the entry for "datadir", and change the path (which should be "/var/lib/mysql") to the new data directory.
Important Note:-From Ubuntu 7.10 (Gutsy Gibbon) forward, Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you'll never be able to restart MySQL with the new datadir location.
In the terminal, enter the command
sudo gedit /etc/apparmor.d/usr.sbin.mysqld
Copy the lines beginning with "/var/lib/mysql", comment out the originals with hash marks ("#"), and paste the lines below the originals.
Now change "/var/lib/mysql" in the two new lines with "/path/to/new/datadir". Save and close the file.
Restart the AppArmor profiles with the command
sudo /etc/init.d/apparmor reload
Restart MySQL with the command
sudo /etc/init.d/mysql restart
Now MySQL should start with no errors, and your data will be stored in the new data directory location.

2013年7月24日星期三

structs IE8 https unable to download

Add the following tow lines in your codes:

response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "public");