Wednesday, December 18, 2013

Tomcat Basics

It's very important from an administrator's point of view, to know about the configuration files and their usage in the Tomcat environment. Configuration properties one-by-one, as follows:
  • catalina.policy: This file describes the security policy permissions for Tomcat 7. It enforces the security policy permissions by JVM on the web application.
When catalina is executed with the -security option, the security policy mentioned in the catalina file is used and the web application security policy also gets executed.
  • catalina.properties: This file contains the shared definition of the server, shared loader, and JARs, which need to be scanned at the time of the server startup.
  • server.xml: This is one of the important configuration files of Tomcat. It holds critical information, such as the IP address, port, virtual host, context path, and so on.
  • tomcat-users.xml: This file is used for authentication, authorization, and role-based definitions. It is used to implement a database of users/passwords/roles for authentication and container-managed security. To add/remove users or assign/unassign roles to existing users, edit this file.
  • logging.properties: As the name suggests, it defines the logging properties of the Tomcat instances (such as startup logs).
  • web.xml: This defines the default values for all web applications loaded into this instance of Tomcat, at the time of startup of the Tomcat instance. If a web application has its own deployment descriptor, its content will always override the configuration settings specified in this default descriptor.
  • context.xml: The contents of this file will load with every application. Configuration of parameters such as session persistence, Comet connection tracking, and so on, are done here.
Any changes made in the server.xml file will be in effect after restarting the Tomcat instance.
Application level resources are not defined in the web.xml of the configuration folder. It would be better to define these in the application web.xml.

IBM HTTP server status monitoring page

Now by enabling server-status on IBM HTTP Server, below details can be obtained :
  • The CPU usage
  • The total number of requests served since the server is up
  • The total traffic size since the server is up
  • Some average about the response time
  • The number of requests currently running
  • The number of idle threads
  • And the list of the requests being processe

To enable the server status monitoring page, perform the following steps:
1. Edit the httpd.conf file, and remove the comment character (#) from the 
following lines in this file:
#LoadModule status_module, modules/ApacheModuleStatus.dll,
#  < Location/server-status >
#SetHandler server-status
# < /Location >
2. Save the changes, and restart IBM HTTP Server.
3. In a web browser, access URL :  http://hostname/server-status. 

Click Reload to update the status. Also , 

http://your_host/server-status?refresh=10 to refresh every 10 seconds

---- courtesy ibm redbook ---- 

Few MySQL Commands

1. Login to mysql database
#mysql -h [hostname] -u root -p

2. Create a new database
mysql> create database [database name]

3. To delete a database.
mysql> drop database [database name]

4. Display all the databases on the server
mysql> show databases;

5. Switch to database
mysql> use [database];

6. To see database's field formats.
mysql> describe [table];

7. To show all the tables in selected database.
mysql> show [tables];

8. Show all data in a table.
mysql> SELECT * FROM [table name];

9. Show the columns.
mysql> show columns from [table name];

10. Search a particular entry in table
mysql> SELECT * FROM [table name] WHERE [field name] = "???????";
eg. mysql> SELECT * FROM [user] WHERE User = "testuser" AND Host = 'localhost';

create new mysql database

Create new Database

create database DataBaseName; 

Create User

CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';

Grant privileges on Datatabase 

GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost'; - limited privileges
or
GRANT ALL ON *.* TO 'user1'@'localhost'; - All privileges
or
GRANT ALL PRIVILEGES ON * . * TO 'sunil'@'localhost' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; - root level privileges

Backup Database
mysqldump -u username -p -h hostname DatabaseName > exportedfilename.sql

Restore Database from dump
mysqldump -u username -p -h hostname DatabaseName < mysqldumpfilename.sql

Find version of mysql

select version();

Change Password for user
update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='user';
mysql> flush privileges;