OpenSolaris 2008.05 has all the benefits of Solaris' Kernel and uses ZFS (the greatest file system of the planet) as its native file system. The first impression I had when I installed was its fastness. It's certainly much faster than Ubuntu 8.04, Fedora 9 and, of course, Windows. I'm using it now to do all my work and I'm really satisfied. See my desktop screen:
OpenSolaris cames with Java installed, Firefox and ThunderBird, Pidgin, GIMP, eVince and many others Gnu Tools.The Flash plug-in is very easy to install, Firefox is prepared to do everything for you... so, no need to download it apart and then configure Firefox yourself to make it work. It just install and work for you.
One of the greatest features of Solaris, for me, is it's Service Management Facility, aka SMF, that gives Solaris the Self Healing ability. Different from Linux, the services are not started and managed through the RC scripts manually, they are controlled by SMF, that manages dependencies, status, errors and organizes everything. If something goes wrong, SMF takes an attitude to repair the situation automatically. If it has no autonomy to full repair a problem, it gives great feedback, instructions about possibilities to fix the problem and very useful logs. OpenSolaris is smart!
To challenge the OpenSolaris way of use, I decided to put a full SAMP platform to work on it, integrating that with Solaris SMF Self Healing System.
And the steps I followed to do it will fit on a single blog Post!
For those that are not familiar with some terminologies, SAMP means: Solaris+Apache+MySql+PHP ... a fast and furious development platform.
The First Step was to install Apache, MySql and PHP. OpenSolaris cames with a Package Manager that downloads, configures and installs the packages for us, with no troubles and headaches about dependencies. Next is a screen shot:
First, I searched for apache and asked the Package Manager to Install Apache 2.2 (SUNWapch22), FastCGI plugin (SUNWapch22m-fcgid), and PHP5 module for Apache (SUNWapch22m-php5). Second, I searched for mysql and asked the manager to install MySql 5 (SUNWmysql5), PHP5 Extension module(Core) to connect to MySQL database (SUNWphp524-mysql) and SUNWmysql-base. The last step was the search for php. I asked Package manager to install PHP Server 5.2.4 (SUNWphp524), Core components of PHP server (SUNWphp524core) and SUNWphp524usr.
All the Packages are available on opensolaris.org repository.
No headache to install SAMP. The three applications were installed on my system on /usr , /etc and /var directories separating (not that exactly, but...) executables/libs, configuration files and functional data, respectively.
Then, I stepped to the interesting part: to configure Apache, MySQL and PHP to work together and to be part of SMF! I've started with MySQL.
Created a my.cnf file at /usr/mysql/5.0 copying the my-small.cnf from /usr/mysql/5.0/share/mysql and renaming it:
# cd /usr/mysql/5.0
#cp ./share/mysql/my-small.cnf .
#mv my-small.cnf my.cnf
Then, I've run mysql_install_db, running the script inside /usr/mysql/5.0/bin:
#cd /usr/mysql/5.0/bin
#./mysql_install_db
After that, just put mysql user as owner of /var/mysql folders:
#cd /var
#chown -R mysql:mysql ./mysql
So, it was already possible to start MySQL through '/usr/mysql/5.0/bin/mysql_safe &' command. To stop MySQL, we may use 'pkill mysql'. I did it to test if everything was going OK. Then I configured Apache to work with PHP.
First, I've edited the httpd.conf file on /etc/apache2/2.2 . I've searched on httpd.conf file for ServerName and ServerAdmin variables. I've left the ServerName variable set to 127.0.0.1, but it can be changed to an specific server name. Then I changed the ServerAdmin value to a valid e-mail.
Next, I searched for <IfModule mime_module> tag on httpd.conf. And, Near the following lines:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
I've added a third line with: AddType application/x-httpd-php .php
It stayed like that:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
That's all for httpd.conf. Now, there is only php.ini left. I've just copied /etc/php5/5.2.4/php.ini file to /etc/apache2/2.2/:
#cd /etc/apache2/2.2
#cp /etc/php5/5.2.4/php.ini .
And then opened it to edit. I've only needed to find the block:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
And add the following line after the comments:
extension=mysql.so
So far so good. Everything is configured and working. You can try starting apache through '/usr/apache2/2.2/bin/apacheclt start' and use a little PHP script to test (Start MySQL too). Create a file with these lines:
<?php
echo "Hello World!
";
$conexao = mysql_connect('localhost', 'root', '');
echo $conexao;
?>
and save it inside /var/apache2/2.2/htdocs with a name like myTest.php . Then, open your browser and type "http://localhost/myTest.php" . Apache and MySQL should be running (you may check it using the 'ps' command)! The Browser should display a message like:
You may see I haven't configured a password for MySQL root user! That's really bad for a real system! You may change root's password on MySQL and create other users to use the databases as you need. But my intention here is just testing.
Now Let's put Apache and MySQL inside SMF!
To set up a service inside SMF you need a script that knows how to start and stop your service (like the old rc scripts of linux) and a XML manifest file that gives more information about the service to SMF like dependencies and other characteristics. There is not so much headache to create these files. The Method script, as I mentioned, is not very different from an RC script, and for the XML manifest, that could sounds more complicated, there is a tool on opensolaris.org that helps you to generate your manifest file automatically, have a look at EASY SMF - http://es.opensolaris.org/easySMF/.
Anyway, Apache and MySQL are famous services and, because I was in a hurry, I've just searched the Internet to see if there was something already done. And there it was. I've edited the scripts and manifests files from these links to put my services under SMF management.
http://systemsadmin.info/solaris/articles/setting-up-smf-for-apache-and-zope-on-solaris-10
http://www.sun.com/bigadmin/content/submitted/mysql_smf_tip.html
Thanks to Chris Miles and William Pool for the files!
I've had to edit the original method scripts and manifest files because many installation details were different from what I found on the originals, like the paths to many important files. So I've adapted them to work directly for OpenSolaris Package Manager Installations.
So, you can have the method scripts here. Just copy them into /lib/svc/method :
Apache Method: apache2
MySQL Method: svc-mysql
>> After saving them on method directory, chmod them into 555 permission (read and execute) (( '# chmod 555 apache2 svc-mysql' ))
And here are the Manifest Files. They will be copied into different directories:
Apache2 Manifest: apache2.xml
>> Save it inside '/var/svc/manifest/site' directory and chmod it to 444 permission (read only) (( '# cdmod 444 apache2.xml' ))
MySQL Manifest: mysql.xml
>> Save it inside '/var/svc/manifest/network' directory and chmod it to 444 permission (read only) (( '# cdmod 444 apache2.xml' ))
Good. Now the last step. Import them into SMF through the commands:
# svccfg -v import /var/svc/manifest/site/apache2.xml
# svccfg -v import /var/svc/manifest/network/mysql.xml
If you have Apache2 and MySQL running on the system, turn them off (you may use 'pkill mysql' and 'apacheclt stop'). To start your services, now you may use:
# svcadm -v enable apache2
and
# svcadm -v enable mysql
and
# svcadm -v disable apache2
and
# svcadm -v disable mysql
To turn them off.
It's possible to see their status through the command:
# svcs -a | grep apache2
# svcs -a | grep mysql
(svcs command list the enabled services; -a option show all the services, enabled and disabled ones)
You may see if there is any problem with your services running the following command:
# svcs -x
If something weird makes your Apache or MySQL go down killing their processes (try it yourself), SMF will take care of it and put the services up and running again!
Nice, isn't it?? And quite easy too!
That's it. Through few steps, now I have my SAMP platform configured and under OpenSolaris Self-Healing system.
This is originally posted at:
http://blogs.sun.com/jonasdias/entry/self_healing_samp_with_opensolaris