Monday, July 26, 2010

Shutdown Linux Box Automatically Cent OS/RHEL/Fedora

Common Tasks For at Command

  1. Shutdown/reboot the system
  2. Email yourself files
  3. Send birthday remainders

Commands

  • at- Execute a task at a specific time. For example, shutdown computer, send birthday remainder etc. Useful to schedule one job at a time or a single future event.
  • cron – If you want to shutdown Linux box automatically everyday 8 pm then you need to use cron instead of at command (see below for examples). Useful to schedule recurring events or daily events such as backup data, or check system security etc.

at Command Examples

Let us see how to shutdow a Linux automatically at 8 pm, type the command at 8pm and press [enter] key, then type halt followed by enter key. To save your job press CTRL+D.

# at 8pm


Sample outputs:

at> halt
 
(Press CTRL+D)
Try out the following utilities:
  • atq - List the current at jobs pending.
  • atrm - Used to remove pending at jobs.
at command accept fairly complex time specifications, for example:
Run job at 6am on monday:

at 6am monday
 
Run job in 5 minutes time:
 
at now + 5 minutes
 
Run job at 4pm but 3 days later:
 
at 4pm + 3 days
 
Run job at 10am on 31st July:
 
at 10am Jul 31
 
See the file /usr/share/doc/at/timespec for complete time specifications
and read man pages of at, atq, atrm. Make sure you have atd service 
running, if not start it using the following command: 

# /etc/init.d/atd start

Linux Cron job to Shutdown Linux server/Desktop system

First, login as the root user and at a shell prompt type crontab -e command so that you can add cronjob:

# crontab -e
 
OR
 
# crontab -e -u root
 
Append the following entry to it to shutdown box at 20:00 hrs [24 hour close format]:
 
0 20 * * * /sbin/shutdown -h now
 
Save and close the file. 

 
 
 

Thursday, July 22, 2010

Hadoop install on AMIs centos!



cd /etc/yum.repos.d/
[root@ip-10-250-57-221 yum.repos.d]# ll
total 4
-rw-r--r-- 1 root root 2245 Oct 1 2009 CentOS-Base.repo
[root@ip-10-250-57-221 yum.repos.d]# wget http://archive.cloudera.com/redhat/cdh/cloudera-cdh3.repo
--2010-07-12 08:47:56-- http://archive.cloudera.com/redhat/cdh/cloudera-cdh3.repo
Resolving archive.cloudera.com... 184.73.170.21
Connecting to archive.cloudera.com|184.73.170.21|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 211 [text/plain]
Saving to: `cloudera-cdh3.repo'

100%[======================================>] 211 --.-K/s in 0s

2010-07-12 08:47:56 (40.2 MB/s) - `cloudera-cdh3.repo' saved [211/211]

[root@ip-10-250-57-221 yum.repos.d]# ls
CentOS-Base.repo cloudera-cdh3.repo
[root@ip-10-250-57-221 yum.repos.d]#


yum install java-1.6.0-openjdk hadoop-0.20
Loaded plugins: fastestmirror
Determining fastest mirrors
* addons: mirror.fdcservers.net
* base: centos.mirror.nac.net
* extras: mirror.vcu.edu
* updates: mirror.rackspace.com
addons | 951 B 00:00
addons/primary | 202 B 00:00
base | 2.1 kB 00:00
base/primary_db | 1.6 MB 00:00
cloudera-cdh3 | 951 B 00:00
cloudera-cdh3/primary | 18 kB 00:00
cloudera-cdh3 62/62
extras | 2.1 kB 00:00
extras/primary_db | 185 kB 00:06
updates | 1.9 kB 00:00
updates/primary_db | 296 kB 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package hadoop-0.20.noarch 0:0.20.2+320-1 set to be updated
---> Package java-1.6.0-openjdk.i386 1:1.6.0.0-1.11.b16.el5 set to be updated
--> Processing Dependency: jpackage-utils >= 1.7.3-1jpp.2 for package: java-1.6.0-openjdk
--> Processing Dependency: libgif.so.4 for package: java-1.6.0-openjdk
--> Processing Dependency: tzdata-java for package: java-1.6.0-openjdk
--> Running transaction check
---> Package giflib.i386 0:4.1.3-7.1.el5_3.1 set to be updated
---> Package jpackage-utils.noarch 0:1.7.3-1jpp.2.el5 set to be updated
---> Package tzdata-java.i386 0:2010i-1.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
hadoop-0.20 noarch 0.20.2+320-1 cloudera-cdh3 21 M
java-1.6.0-openjdk i386 1:1.6.0.0-1.11.b16.el5 updates 37 M
Installing for dependencies:
giflib i386 4.1.3-7.1.el5_3.1 base 39 k
jpackage-utils noarch 1.7.3-1jpp.2.el5 base 61 k
tzdata-java i386 2010i-1.el5 updates 176 k

Transaction Summary
================================================================================
Install 5 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 58 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): giflib-4.1.3-7.1.el5_3.1.i386.rpm | 39 kB 00:00
(2/5): jpackage-utils-1.7.3-1jpp.2.el5.noarch.rpm | 61 kB 00:00
(3/5): tzdata-java-2010i-1.el5.i386.rpm | 176 kB 00:00
(4/5): hadoop-0.20-0.20.2+320-1.noarch.rpm | 21 MB 00:01
(5/5): java-1.6.0-openjdk-1.6.0.0-1.11.b16.el5.i386.rpm | 37 MB 00:03
--------------------------------------------------------------------------------
Total 12 MB/s | 58 MB 00:04
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : giflib 1/5
Installing : jpackage-utils 2/5
Installing : tzdata-java 3/5
Installing : hadoop-0.20 4/5
Installing : java-1.6.0-openjdk 5/5

Installed:
hadoop-0.20.noarch 0:0.20.2+320-1
java-1.6.0-openjdk.i386 1:1.6.0.0-1.11.b16.el5

Dependency Installed:
giflib.i386 0:4.1.3-7.1.el5_3.1 jpackage-utils.noarch 0:1.7.3-1jpp.2.el5
tzdata-java.i386 0:2010i-1.el5

Complete!
[root@ip-10-250-57-221 yum.repos.d]#

[root@ip-10-250-57-221 conf]# vi hadoop-env.sh
# The java implementation to use. Required.
export JAVA_HOME=/usr/java/jdk1.6.0_14/ (remove # and set JAVA environment)


[root@ip-10-250-57-221 java]# vi ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:
JAVA_HOME=/usr/java/jdk1.6.0_14/
export PATH
export JAVA_HOME
unset USERNAME

[root@ip-10-250-57-221 ~]# . .bash_profile
[root@ip-10-250-57-221 ~]# . .bash_profile
[root@ip-10-250-57-221 ~]# . .bash_profile
[root@ip-10-250-57-221 ~]# . .bash_profile
[root@ip-10-250-57-221 ~]# java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode)
[root@ip-10-250-57-221 ~]# echo $JAVA_HOME
/usr/java/jdk1.6.0_14/
[root@ip-10-250-57-221 ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/ec2/bin:/home/ec2/bin:/root/bin:/home/ec2/bin:/root/bin:/usr/java/default/bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin:


[root@ip-10-250-57-221 java]# vi ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:
JAVA_HOME=/usr/java/jdk1.6.0_14/
HADOOP_HOME=/usr/lib/hadoop-0.20
export PATH
export JAVA_HOME
export HADOOP_HOME
unset USERNAME

echo $HADOOP_HOME
/usr/lib/hadoop-0.20
[root@ip-10-250-57-221 hadoop-0.20]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/ec2/bin:/home/ec2/bin:/root/bin:/home/ec2/bin:/root/bin:/usr/java/default/bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin::/home/ec2/bin:/root/bin:/usr/java/jdk1.6.0_14//bin:


[root@ip-10-250-57-221 conf]# pwd
--> #/usr/lib/hadoop-0.20/conf
--> #conf/core-site.xml:
--> #
--> #
--> # fs.default.name
--> # hdfs://:9000
--> #
--> #
--> #conf/hdfs-site.xml:
--> #
--> #
--> # dfs.replication
--> # 1
--> #
--> #
--> #conf/mapred-site.xml:
--> #
--> #
--> # mapred.job.tracker
--> # :9001
--> #
--> #


Setup passphraseless ssh
Now check that you can ssh to the localhost without a passphrase:
# ssh localhost
If you cannot ssh to localhost without a passphrase, execute the following commands:
# ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
# cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

Format a new distributed-filesystem:
# bin/hadoop namenode -format
Start the hadoop daemons:
# bin/start-all.sh

open port 50070 and 50030

Browse the web interface for the NameNode and the JobTracker; by default they are
available at:
NameNode - http://:50070/
JobTracker - http://:50030/




Friday, July 9, 2010

TeamCity with LAMP Cent OS AMIs

 Installing MySQL 5
To install MySQL, we do this:
yum install mysql mysql-server
Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the
system boots) and start the MySQL server:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start
Run
mysql_secure_installation
to set a password for the user root (otherwise anybody can access your MySQL database!):
[root@server1 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
     SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): <-- ENTER
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <-- ENTER
New password: <-- yourrootsqlpassword
Re-enter new password: <-- yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <-- ENTER
 ... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <-- ENTER
 ... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <-- ENTER
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <-- ENTER
 ... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Installing Apache2
Apache2 is available as a Fedora package, therefore we can install it like this:
yum install httpd
Now configure your system to start Apache at boot time...
chkconfig --levels 235 httpd on
... and start Apache:
/etc/init.d/httpd start
Now direct your browser to http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com/ and you should see
the Apache2 placeholder
 page:
(( Optional ))
Installing PHP5
We can install PHP5 and the Apache PHP5 module as follows:
yum install php
We must restart Apache afterwards:
/etc/init.d/httpd restart
vi /var/www/html/info.php
phpinfo();
?>
Now we call that file in a browser (e.g. http://ec2-XX-xx-xxx-xxx.compute-
1.amazonaws.com/info.php):
Getting MySQL Support In PHP5
To get MySQL support in PHP, we can install the php-mysql package. It's a good idea to install some
other PHP5 modules as well as you might need them for your applications. You can search for available
PHP5 modules like this:
yum search php
Pick the ones you need and install them like this:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-
eaccelerator php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-
snmp php-soap php-tidy
Now restart Apache2:
/etc/init.d/httpd restart
Now reload http://ec2-xXX-xX-xXx-XXx.compute-1.amazonaws.com/info.php in your browser and scroll
down to the modules section again. You should now find lots of new modules there, including the
MySQL module:
phpMyAdmin
phpMyAdmin is a web interface through which you can manage your MySQL databases.
phpMyAdmin can be installed as follows:
yum install phpmyadmin
Now we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows
connections not just from localhost (by commenting out the
stanza):
vi /etc/httpd/conf.d/phpMyAdmin.conf
# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
#
# order deny,allow
# deny from all
# allow from 127.0.0.1
# allow from ::1
#

# This directory does not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#

   Order Deny,Allow
   Deny from All
   Allow from None

# This configuration prevents mod_security at phpMyAdmin directories from
# filtering SQL etc. This may break your mod_security implementation.
#
#
#
#      SecRuleInheritance Off
#

#

Restart Apache:
/etc/init.d/httpd restart
Afterwards, you can access phpMyAdmin under http://ec2-XXX-XX-XXX-XXX.compute-
1.amazonaws.com/phpmyadmin/:
Red Hat Enterprise Linux, CentOS, etc.
The OpenJDK 6 packages are also available in EPEL, a community-run project which makes Fedora
packages available to users of Red Hat Enterprise Linux 5, CentOS 5, and other RHEL 5 derivatives.
First install the package that enables the EPEL repository:
   $ su -c "rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm"
If installing from a live image, such as a live CD or USB flash drive, add the OpenJDK 6 runtime after
the install:
   * To install with the graphical package manager, follow Applications > Add/Remove Software and
use search to find the package(s) to install.
   * To install from the command line:
       $ su -c "yum install java-1.6.0-openjdk"
     This package contains just the Java Runtime Environment. If you want to develop Java programs
then install the java-1.6.0-openjdk-devel package. You can also install all the OpenJDK 6 packages,
including the API documentation, by using the wildcard java-1.6.0-openjdk*.
On Fedora 8 the OpenJDK 7 runtime and development packages are installed by default during any
large-media install, such as from the Fedora 8 DVD, under the name IcedTea. If installing from a live
image then follow the above instructions but replace 1.6.0-openjdk with 1.7.0-icedtea.
 yum install tomcat5 tomcat5-webapps tomcat5-admin-webapps
Set JAVA_HOME / PATH for single user
Login to your account and open .bash_profile file
$ vi ~/.bash_profile
Set JAVA_HOME as follows using syntax export JAVA_HOME=. If your path is set
to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
export JAVA_HOME=/usr/java/jdk1.6.0_16/bin/java
Set PATH as follows:
export PATH=$PATH:/usr/java/jdk1.6.0_16/bin
Save and close the file. Just logout and login back to see new changes:
$ echo $JAVA_HOME
$ echo $PATH
Edit the .bash_profile for Java Environment
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:
JAVA_HOME=/usr/java/jdk1.6.0_16/
export CATALINA_HOME=/opt/jetbrains/TeamCity
export PATH
export JAVA_HOME
unset USERNAME
http://www.jetbrains.com/teamcity/
Download TeamCity 5.1.2
http://download.jetbrains.com/teamcity/TeamCity-5.1.2.tar.gz
# cd /opt
# mkdir jetbrains
# cd jetbrains
# mkdir TeamCity
# cp TeamCity-5.1.2.tar.gz /opt/jetbrains/TeamCity
# vi /opt/jetnrains/TeamCity/conf/server.xml
 
           connectionTimeout="20000"
           redirectPort="8443"
           enableLookup="false"
           useBodyEncodingForURI="true"
      />
  
  
  
  
8543 will default port change to 8443
# service httpd restart
# chkconfig httpd on
# service mysqld restart
# chkconfig mysqld on
# service tomcat5 restart
# chkconfig tomcat5 on
# cd /opt/jetbrains/TeamCity/bin
TeamCity server can be started and stopped by the scripts provided in the /bin
directory
To start/stop TeamCity server and default agent at the same time, use the runAll script.
To start/stop only the TeamCity server, use teamcity-server script.
For example:
   * Use runAll.bat start to start the server and the default agent
   * Use runAll.bat stop to stop the server and the default agent
By default, TeamCity runs on http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com:8111/ and has
one registered build agent that runs on the same computer.

Tuesday, July 6, 2010

MySQL root user password using MySQL sql command

This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:
1) Login to mysql server, type following command at shell prompt:
$ mysql -u root -p
2) Use mysql database (type command at mysql> prompt):
mysql> use mysql;
3) Change password for user root:
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='root';
4) Reload privileges:
mysql> flush privileges;
mysql> quit