Search This Blog

Jan 26, 2010

Installation of MYSQL on Linux

1.)Download mysql-5.0.51a-linux-i686-glibc23.tar.gz from anywhere.
---------
2.)Next, let’s create the mysql user and group:
---------
#groupadd mysql
#useradd -g mysql mysql

3.)And continue with the actual installation:
---------
#cd /usr/local
#gunzip < /usr/local/src/mysql-5.0.51a-linux-i686-glibc23.tar.gz | tar xvf -
#ln -s mysql-5.0.51a-linux-i686-glibc23 mysql
#cd /mysql/
#scripts/mysql_install_db --user=mysql
#chown -R root .
#chown -R mysql data
#chgrp -R mysql .
#########################################################
The mysqld binary will search for configuration file under: /etc/my.cnf, /my.cnf and /my.cnf . You can start with one of the supplied configs (my-small.cnf, my-medium.cnf, my-large.cnf, my-huge.cnf or my-innodb-heavy-4G.cnf) and customize it accordingly to your needs. I chosen to put this one under /usr/local/mysql, so I can have more mysql instances running, each with its local my.cnf:
#########################################################
#cp support-files/my-medium.cnf my.cnf
#vim my.cnf
4.)Once you are happy with the config you can start mysql manually using:
#bin/mysqld_safe --user=mysql &

5.)You can stop it manually with:

/usr/local/mysql/bin/mysqladmin shutdown

6.)Start MySql >>>>>>>>>>>>>
/usr/local/mysql/bin/mysql
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Jan 20, 2010

Installing Cacti on CentOS 5

Cacti is a GPL-licensed, scalable, RRDtool-based monitoring program with flexible graphing options. This article describes the process of installing and configuring Cacti on CentOS 5.2.
Useful links to this installation were BXtra and TechDB.
Per the Cacti documentation, Cacti requires:
RRDTool 1.0.49 or 1.2.x or greater
MySQL 4.1.x or 5.x or greater
PHP 4.3.6 or greater, 5.x greater highly recommended for advanced features
A Web Server e.g. Apache or IIS
I'd also recommend installing vim, net-snmp, net-snmp-utils, php-snmp, initscripts, perl-rrdtool, and any dependencies.
To perform this install, I am logged into Gnome as a normal user, and opened a terminal that is switched to the root user using the su command. I had already installed apache, mysql, and PHP during the original install process of CentOS 5.2.
I added a new repository to facilitate this install. To do this, I created a file
(/etc/yum.repos.d/dag.repo) containing Dag Wiers repository, which contains rrdtool, among other things.
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el5/en/i386/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1
You can create this file by typing vim /etc/yum.repos.d/dag.repo and copying and pasting the above information into the file. Be warned that the above text containing the repository is version and architecture-specific.
I then typed yum update to update CentOS and the repository list before installing additional software.
I installed everything but cacti through yum. You can verify that you have the packages in question (or the version numbers of installed packages) by attempting to install them, as yum will remind you that you already have the latest version installed, as well as the version status of the packages, as shown here:
# yum install php httpd mysql mysql-server php-mysql vim-enhanced net-snmp net-snmp-utils php-snmp initscripts perl-rrdtool rrdtool initscripts
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* base: pubmirrors.reflected.net
* updates: mirror.fdcservers.net
* addons: chi-10g-1-mirror.fastsoft.net
* extras: mirror.fdcservers.net
Setting up Install Process
Parsing package install arguments
Package php-5.1.6-23.2.el5_3.i386 already installed and latest version
Package httpd-2.2.3-22.el5.centos.1.i386 already installed and latest version
Package mysql-5.0.45-7.el5.i386 already installed and latest version
Package mysql-server-5.0.45-7.el5.i386 already installed and latest version
Package php-mysql-5.1.6-23.2.el5_3.i386 already installed and latest version
Package 2:vim-enhanced-7.0.109-4.el5_2.4z.i386 already installed and latest version
Package 1:net-snmp-5.3.2.2-5.el5_3.1.i386 already installed and latest version
Package 1:net-snmp-utils-5.3.2.2-5.el5_3.1.i386 already installed and latest version
Package php-snmp-5.1.6-23.2.el5_3.i386 already installed and latest version
Package initscripts-8.45.25-1.el5.centos.i386 already installed and latest version
Package perl-rrdtool-1.3.7-1.el5.rf.i386 already installed and latest version
Package rrdtool-1.3.7-1.el5.rf.i386 already installed and latest version
Package initscripts-8.45.25-1.el5.centos.i386 already installed and latest version
Nothing to do
Download the latest version of Cacti (0.8.7e, as of the writing of this article) from here. I downloaded it to my desktop and unzipped it by right clicking it and selecting "Extract here". I also renamed the cacti-0.8.7e directory by right clicking and selecting "Rename". You could do this in the command line, if you wanted to:
[your root shell] # tar xzvf cacti-0.8.7e.tar.gz
[your root shell] # mv cacti-0.8.7e cacti
Move the entire cacti directory to /var/www/html/ :
[your root shell] # mv cacti /var/www/html
I chose to create a 'cactiuser' user (and cacti group) to run cacti commands and to have ownership of the relavent cacti files. It was here that I noticed that my install did not have any of the /sbin directories in its $PATH , so I simply typed the absolute path:
[your root shell] # /usr/sbin/groupadd cacti
[your root shell] # /usr/sbin/useradd -g cacti cactiuser
[your root shell] # passwd cactiuser
Change the ownership of the /var/www/html/cacti/rra/ and /var/www/html/cacti/log/ directories to the cactiuser we just created
[your root shell] # cd /var/www/html/cacti
[your root shell] # chown -R cactiuser rra/ log/
Create a mysql root password, if you haven't already (password in this example is samplepass:
[your root shell] # /usr/bin/mysqladmin -u root password samplepass
Create a MySQL database for cacti:
[your root shell] # mysqladmin --user=root --password=samplepass create cacti
Change directories to the cacti directory, and use the cacti.sql file to create tables for your database:
[your root shell] # cd /var/www/html/cacti
[your root shell- cacti] # mysql --user=root --password=samplepass cacti < cacti.sql
I also created a MySQL username and password for Cacti:
[your root shell] # mysql --user=root --password=samplepass
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 28
Server version: 5.0.45 Source distribution
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'samplepass';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
Edit /var/www/html/cacti/include/config.php with your favorite editor, and update the information to reflect our cacti configuration (you can leave the other text in the file alone):
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "samplepass";
$database_port = "3306";
Create a cron job that polls for information for Cacti (I'm choosing to use /etc/crontab here):
[your root shell] # vim /etc/crontab
Add this line to your crontab:
*/5 * * * * cactiuser /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
Edit your PHP config file at /etc/php.ini/memory_limit in command mode.
[your root shell] # vim /etc/php.ini
I changed memory_limit = 8M to memory_limit = 128M
Before I check to see if Cacti works, I want to check and see if mysqld and httpd are running using the service command.
[your root shell] # /sbin/service mysqld status
[your root shell] # /sbin/service httpd status
If mysqld and httpd are running, great. If not, type:
[your root shell] # /sbin/service mysqld start
[your root shell] # /sbin/service httpd start
If you're an "I need to see what the output looks like" type, here is an example of the previous command:
[your root shell] # /sbin/service mysqld status
mysqld is stopped
[your root shell] # /sbin/service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
Starting MySQL: [ OK ]
Figure 1
You should now be able to access cacti at http://localhost/cacti from the local computer or from any computer within your LAN network at http://your.internal.IP.address/cacti .
There should be a Cacti Installation Guide window that shows up, giving licensing info and the like. Click "Next".
Select "New Installation", since this is a new installation.
The next window to pop up should tell you whether Cacti could find the paths to all of the elements that Cacti needs to run, such as RRDtool, PHP, snmp stuff, etc. If everything but Cacti was installed via yum, you should be good here. Click "Finish" to save the settings and bring up the login window.
Figure 1 is a screenshot of the login window. The default user name is admin. The default password is admin. It should prompt an automatic password change for the admin account when you log in the first time.
Figure 2
If you successfully log in, I'd recommend taking a break here. Depending on how fast you are, your cron job may not have had enough time to run the poller program and create data for your graphs. I'd suggest taking a deep breath, or brewing a cup of tea (or coffee) for yourself.
The localhost machine should have some graph templates that are already created, but you can click the "Create Additional Devices" link to add graphs for any other machines on your network. I added my FreeNAS box (tutorial for that to follow).
Figure 3
After having consumed your beverage of choice, press the "Graphs" button. Cacti should have a graph showing you a couple minutes of data for the machines you have added. The longer your machine is on, the more informational the graphs will be. Also, if you click on a particular graph, Cacti will show you more detail by redrawing the graph on the fly. Cacti is a very flexible tool that allows you to change the colors being graphed as well as the metrics for graphing very easily. Congratulations! You're now monitoring!

Installation and Configuration of DNS Server-LINUX

1 ) Install the dns packages

#yum install bind bind-utils bind-chroot caching-nameserver

2) Check /etc/resolv.conf

cp /etc/resolv.conf /etc/resolv.conf.original

vi /etc/resolv.conf

Insert,
search tornado.com
nameserver 127.0.0.1

Setting daemon options

cp /var/named/chroot/etc/named.conf var/named/chroot/etc//named.conf.original

set the permission for named.conf

chown root:named named.conf

vi /var/named/chroot/etc/named.conf

Insert the BOLD;

options {
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
//query-source address * port 53;
listen-on { 127.0.0.1; 10.29.29.112 ; };
allow-query { 127.0.0.1; 10.29.29.0/24; };
};


If your DNS server is located behind a firewall and is having difficulty with resolving names, you may need to uncomment this directive.
query-source address * port 53;

The "." zone below tells named to check this file for a list of the root name servers, so it knows where to send external queries. This enables the caching nameserver feature of BIND, by forwarding any unknown requests to the root nameservers listed in the file. This zone should already be listed in the configuration.
zone "." IN {
type hint;
file "named.ca";
};
##################################################################################### You may find that sending every new DNS query to the root name servers will be a little slow. This can be improved by sending all of your queries to a quicker "upstream" DNS server which will process your request for you. An upstream DNS server (like the ones at your ISP) may already have the query you're after in its cache, or it will normally have a faster backbone link to the root name servers.

To use forwarders you need to have at least one upstream DNS server IP address. Forwarders are a configuration option which needs to be placed inside the "options" section (place under the "allow-query" option above).
#Place INSIDE 'options'

forward first;
forwarders { xxx.xxx.xxx.xxx; xxx.xxx.xxx.xxx; }; <-- Add your ISP's DNS servers in here (IP addresses ONLY)
#####################################################################################

Adding Your Domain
vi /var/named/chroot/etc/named.conf
zone "tornado.com" IN {
type master;
file "data.tornado.com";
allow-update { none; };
};

zone "29.29.10.in-addr.arpa" IN {
type master;
file "reverse-10.29.29";
allow-update { none; };
};
vi /var/named/chroot/var/named/data.tornado.com
The following is an example FORWARD zone file for the "example.com" domain name, it is using private addressing for internal only name resolution.
$TTL 1D
@ IN SOA thunder.tornado.com. root (
10 ; Serial
8H ; Refresh
2H ; Retry
4W ; Expire
1D ) ; Minimum
;
IN NS thunder ; Name Server for the domain
IN MX 10 thunder ; Mail Exchange
;
tornado.com. IN A 10.29.29.112 ; IP address for the domain tornado.com
thunder IN A 10.29.29.112 ; IP address for ' thunder'
www IN CNAME thunder ; ' thunder ' is also known as www
ftp IN CNAME thunder ; ' thunder ' is also known as ftp
;
=========================
The forward zone file allows name resolution from NAME to IP address. To allow name resolution from IP address to NAME, we need to configure a REVERSE zone file.
vi /var/named/chroot/var/named/reverse-10.29.29
$TTL 1D
@ IN SOA thunder.tornado.com. root (
10 ; Serial
8H ; Refresh
2H ; Retry
4W ; Expire
1D ) ; Minimum
;
IN NS thunder.tornado.com.
1 IN PTR thunder.tornado.com.


The following are some of the common parameters (and definitions) required to configure our zone files.
Parameter Definition
$TTL Time To Live for the zone file
IN The Internet system
SOA Start Of Authority to administer zone
NS Name Server for the zone
MX Mail Exchange for the zone (needs a priority value)
A Address records for hosts / network equipment
CNAME Canonical name for an alias (points to "A" record)

chown named.named /var/named/chroot/var/named/data.tornado.com
chown named.named /var/named/chroot/var/named/reverse-10.29.29
Checking Your Work
named-checkconf /var/named/chroot /etc/named.conf
named-checkzone -d tornado.com /var/named/chroot/var/named/data.tornado.com
loading "example.com" from "/var/named/master-example.com" class "IN"
zone example.com/IN: loaded serial 10
OK
named-checkzone -d 29.29.10.in-addr.arpa //var/named/chroot/var/named/reverse-10.29.29

loading "1.168.192.in-addr.arpa" from "/var/named/data/reverse-192.168.1" class "IN"
zone 1.168.192.in-addr.arpa/IN: loaded serial 10
OK




Starting BIND
chkconfig --level 2345 named on
/etc/init.d/named restart
chkconfig --list named
grep named /var/log/messages
galaxy named[19111]: starting BIND 9.3.2 -u named -t /var/named/chroot
galaxy named[19111]: found 2 CPUs, using 2 worker threads
galaxy named[19111]: loading configuration from '/etc/named.conf'
galaxy named[19111]: listening on IPv4 interface lo, 127.0.0.1#53
galaxy named[19111]: listening on IPv4 interface eth1, 192.168.1.1#53
galaxy named[19111]: command channel listening on 127.0.0.1#953
galaxy named[19111]: zone 0.in-addr.arpa/IN: loaded serial 42
galaxy named[19111]: zone 0.0.127.in-addr.arpa/IN: loaded serial 1997022700
galaxy named[19111]: zone 1.168.192.in-addr.arpa/IN: loaded serial 10 <-- Successful load
galaxy named[19111]: zone 255.in-addr.arpa/IN: loaded serial 42
galaxy named[19111]: zone example.com/IN: loaded serial 10 <-- Successful load
galaxy named[19111]: zone localdomain/IN: loaded serial 42
galaxy named[19111]: zone localhost/IN: loaded serial 42
galaxy named[19111]: running

Testing The Server
[bash]# dig www.example.com

; <<>> DiG 9.3.2 <<>> www.example.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48535
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;www.example.com. IN A

;; ANSWER SECTION:
www.example.com. 86400 IN CNAME galaxy.example.com.
galaxy.example.com. 86400 IN A 192.168.1.1 <-- Correct IP address returned

;; AUTHORITY SECTION:
example.com. 86400 IN NS galaxy.example.com.

;; Query time: 3 msec
;; SERVER: 127.0.0.1#53(127.0.0.1) <-- Query from local server
;; WHEN: Wed May 17 21:16:38 2006
;; MSG SIZE rcvd: 84

dig example.com AXFR @localhost

; <<>> DiG 9.3.2 <<>> example.com AXFR @localhost
; (1 server found)
;; global options: printcmd
example.com. 86400 IN SOA galaxy.example.com. sysadmin.example.com. 10 28800 7200 2419200 86400
example.com. 86400 IN NS galaxy.example.com.
example.com. 86400 IN MX 10 galaxy.example.com.
example.com. 86400 IN A 192.168.1.1
ftp.example.com. 86400 IN CNAME galaxy.example.com.
galaxy.example.com. 86400 IN A 192.168.1.1
wkstn1.example.com. 86400 IN A 192.168.1.201
wkstn2.example.com. 86400 IN A 192.168.1.202
www.example.com. 86400 IN CNAME galaxy.example.com.
example.com. 86400 IN SOA galaxy.example.com. sysadmin.example.com. 10 28800 7200 2419200 86400
;; Query time: 2 msec
;; SERVER: 127.0.0.1#53(127.0.0.1) <-- Query from local server
;; WHEN: Wed May 17 21:17:21 2006
;; XFR size: 9 records (messages 1)

host 10.29.29.112
201.1.168.192.in-addr.arpa domain name pointer wkstn1.example.com.

Basics of MYSQL

1.)Table creation on sql
***********************

create table contact
(
id INT NOT NULL AUTO_INCREMENT
PRIMARY KEY,
first_name varchar (30),
Last_name varchar (30),
phone varchar (15)
)

#######################

desc contact

#######################

2.)Adding Values to TABLES
************************
insert into contact values
(
1,'Remya','Gopi','90*6***40'
)
#######################
3.)For updating table values
***************************
select * from contact
update contact
set phone = '04683333'
where id = 1

#######################

4.)For delete value from TABLE
*****************************
delete from contact
where id = 1

#######################

5.)For deleting a TABLE
***********************
drop table contact

#######################

6.)Adding a column on a table
***************************
alter table test add state varchar2 (2)

#######################

7.)Deleting a column on a table
*******************************
alter table noc DROP COLUMN salary

#######################

8.)Comparison
***************
select * from list
where age >= '25'
========================
select * from ardc
where id = '1' or id = '2'

select * from ardc
where id != '1' and id = '2'

#######################

9.)IN or NOT IN
**************

select * from ardc
where id not in (1,3)

select * from ardc
where id in (1,3)

select * from ardc
where name not in ('Sreenu Raghavan','Ratheesh')

select * from ardc
where name in ('Sreenu Raghavan','Ratheesh')

#######################

10.)BETWEEN or NOT BETWEEN
***********************
select * from ardc
where id between 1 and 3

select * from ardc
where id >= 1 and id <= 3


select * from ardc
where id not between 1 and 3


select * from ardc
where id < 1 or id > 3

#######################

11.)LIKE or NOT LIKE with % or _
********************
select * from ardc
where name like 'S%'

select * from ardc
where name like 'S_ee_u%'

select * from ardc
where name not like 'S_ee_u%'

#######################

12.)< or >
*******
select * from noc
where salary < prev_salary

select * from noc
where name > 'S'
select * from noc
where name > 'Na'

B > A
C > B
a > A

#######################

13.)NULL
******
1)insert into noc values
(7,'pratheek','madiwala','3000',null)

2)insert into noc (sl,name,house,salary) values
(7,'pratheek','madiwala','3000')

3)select * from noc
where prev_salary = null >>>> Wrong

select * from noc
where prev_salary != null >>>>>Wrong


select * from noc
where prev_salary is null >>>>>Correct

select * from noc
where prev_salary is not null >>>>>>Correct

#######################

14.)ORDER
******
select * from noc
order by name
=
select * from noc
order by salary,sl
=
select * from noc
order by 1 >>>Column Number
=
select sl,name from noc
order by 2 >>>>order should be as per select list

#######################

15.)ORDER_descending order
**********************
select * from noc
order by name desc
==
select * from noc
order by salary desc ,sl desc
==
select sl,name,salary from noc
order by 3 desc
===============================
select * from ardc
where (salary > '2000' or dept ='1') and year = '2008'

select * from ardc
where salary > '2000' or (dept ='1' and year = '2008')

select * from ardc
where dept ='1' and year = '2007'

3 Ratheesh 2600 1 2008
4 Robin 2600 2 2008
1 Sreenu Raghavan 6000 1 2007
2 Nithin Kumar 6000 2 2007
###########################################################
###########################################################