ps -ef | grep http | wc -l
Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts
Sunday, March 4, 2012
Wednesday, February 29, 2012
How to check if ports have got open after IPTables rules
Verify that port is open
Run following command:
Make sure iptables is allowing port 80 / 110 / 143 connections:
netstat -tulpn | lessMake sure iptables is allowing port 80 / 110 / 143 connections:
iptables -L -nRefer to iptables man page for more information about iptables usage and syntax:
man iptablesIPTables CentOS5.6 - port 80, 143, 443 allowed or open
I had my webserver setup perfectly and it was working fine but it was not accessible from outside. It was IPtables blocking the same. I read on internet about the rules for IpTables to allow access to port 80,443,143. below mentioned are the rules.
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT
But even after applying these rules things were not working because I was appending these rules after the rule
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
-------------------------------------------------------------------------------
I think (I don't know for sure) the rule for icmp shall always be at the last. Any rule after that to allow access to network resources will not get effective.
If I am wrong please correct.
You can refer to http://www.cyberciti.biz/faq/howto-rhel-linux-open-port-using-iptables/ for more information on IPTables.
Tuesday, February 28, 2012
How to find the Linux Distro Name and version
Some distros put a '*-release' or '*-version' file
in /etc. Here are some examples:
/etc/redhat-release
/etc/debian_version
/etc/SuSE-release
/etc/slackware-version
/etc/gentoo-release
You could do 'cat /etc/*-release' or 'cat /etc/*-version'.
in /etc. Here are some examples:
/etc/redhat-release
/etc/debian_version
/etc/SuSE-release
/etc/slackware-version
/etc/gentoo-release
You could do 'cat /etc/*-release' or 'cat /etc/*-version'.
IPtables the play is dangerous and frustrating...yet find the way how to enable outbound traffic for port 3306 mysql
1. vi /etc/sysconfig/iptables
To allow inbound traffic add this rule: -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
To allow outbound traffic add this rule: -A OUTPUT -p tcp -m tcp --dport 3306 -j ACCEPT
Now restart IPtables: /etc/init.d/iptables restart
To allow inbound traffic add this rule: -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
To allow outbound traffic add this rule: -A OUTPUT -p tcp -m tcp --dport 3306 -j ACCEPT
Now restart IPtables: /etc/init.d/iptables restart
tail command to see the access log details created by a particular IP
tail -f /var/log/httpd/access_log | grep "122.176.44.144"
How to send alert message for SWAP Usage
here is a shell script which will Alert by send mail if the system started to use more than 20% of swap area and 80% of hard disk space.
$ vim swap-use.sh
#!/bin/sh
free -m | grep Swap | while read output;
do
swap=$(echo $output | awk '{print $2}' )
used=$(echo $output | awk '{ print $3 }' )
freed=$(echo $output | awk '{ print $4 }' )
echo "Swap : $swap"
echo "Used : $used"
echo "Free : $freed"
usep=`expr $used \* 100 / $swap`
echo $usep
if [ $usep -ge 20 ]; then
echo "Swap Usage Alert Total Swap: \"$swap\" Used: \"$used ($usep%)\" Free:
\"$freed\" on $(hostname) as on $(date)" |
mail -s "Alert: Swap Usage space $usep%" mail1@example.com,mail2@ example.com
fi
doneThen schedule it in cron--
How to add existing users in existing groups in linux and see which user is in which group
How to add existing users in existing groups in linux and see which user is in which group
Add to group:
[root@288832-web3 ~]# usermod -a -G group1 user1
[root@288832-web3 ~]# usermod -a -G group2 user2
View which group which user belongs:
[root@288832-web3 ~]# groups user1
user1 : user1 apache group1
[root@288832-web3 ~]# groups user2
user2 : user2 apache group2
[root@288832-web3 ~]# usermod -a -G group2 user2
View which group which user belongs:
[root@288832-web3 ~]# groups user1
user1 : user1 apache group1
[root@288832-web3 ~]# groups user2
user2 : user2 apache group2
Run a command in background example: wget
Run the command in background on Linux:
$> nohup wget URL
This is true for running any command in background. Also, the command
generates a file called nohup.out, which might grow as the command
proceeds. So if you are downloading something using wget in
background, you can see the status by
cd <download_folder>
tail -f nohup.out
$> nohup wget URL
This is true for running any command in background. Also, the command
generates a file called nohup.out, which might grow as the command
proceeds. So if you are downloading something using wget in
background, you can see the status by
cd <download_folder>
tail -f nohup.out
Setting up liferay/tomcat as service on suse linux
1. Copy the attached file to /etc/init.d
2. Modify the paths
3. Run the following command to add the script as service
chkconfig --add liferay
---------------------------------
Filename: liferay
#!/bin/sh
#
# /etc/init.d/tomcat
#
# This is the init script for starting up the
# Jakarta Tomcat server
#
# description: Starts and stops the Tomcat daemon.
#
tomcat=/media/Resources/data/www/liferay-portal-6.0.6/tomcat-6.0.29
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
start() {
echo -n $"Starting Tomcat service: "
sh $startup
echo $?
}
stop() {
echo -n $"Stopping Tomcat service: "
sh $shutdown
echo $?
}
restart() {
stop
start
}
status() {
#ps -aef | grep liferay | grep -v tomcat6 | grep -v grep
numproc=`ps -ef | grep liferay | grep -v "grep liferay" | wc -l`
if [ $numproc -gt 0 ]; then
echo "Liferay is running..."
else
echo "Liferay is stopped..."
fi
}
# Handle the different input options
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
2. Modify the paths
3. Run the following command to add the script as service
chkconfig --add liferay
---------------------------------
Filename: liferay
#!/bin/sh
#
# /etc/init.d/tomcat
#
# This is the init script for starting up the
# Jakarta Tomcat server
#
# description: Starts and stops the Tomcat daemon.
#
tomcat=/media/Resources/data/www/liferay-portal-6.0.6/tomcat-6.0.29
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
start() {
echo -n $"Starting Tomcat service: "
sh $startup
echo $?
}
stop() {
echo -n $"Stopping Tomcat service: "
sh $shutdown
echo $?
}
restart() {
stop
start
}
status() {
#ps -aef | grep liferay | grep -v tomcat6 | grep -v grep
numproc=`ps -ef | grep liferay | grep -v "grep liferay" | wc -l`
if [ $numproc -gt 0 ]; then
echo "Liferay is running..."
else
echo "Liferay is stopped..."
fi
}
# Handle the different input options
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
Add a new user to SVN for UKSS
Login as root via SSH on UKSS
Here we are adding a new user with the username: user1
Add new user: useradd user1
Add Password for the new user: passwd user1
Add user to groups:
gpasswd -a user1 svn
gpasswd -a user1 apache
How to get list of files greater than 512MB in linux
find / -type f -size +512000k -exec du -hs {} \;How to zip or archive or tar a directory and exclude one directory
tar -czpf /path/to/backups/my_backup.tar .gz --exclude path/to/images/tmp path/to/images/Saturday, January 21, 2012
How to see disk space utilization in Linux
Listing size and % usage of each partition.
[root@288832-web3 ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 279G 265G 0 100% /
/dev/sda2 2.1G 355M 1.7G 18% /tmp
/dev/sda1 104M 26M 73M 26% /boot
tmpfs 13G 0 13G 0% /dev/shm
------------------------------------------------------------------
Find How Much Disk Space Is Being Used Show Display
Login as root
then cd /
then execute: du -hc --max-depth=1
Output:
[root@hostname /]# du -hc --max-depth=1
0 ./net
1.6G ./usr
16K ./lost+found
515M ./proc
8.0K ./misc
648M ./var
112K ./dev
8.0K ./mnt
66M ./lib
8.0K ./selinux
7.3M ./bin
77M ./root
4.2M ./boot
28K ./tmp
2.7M ./backups
20M ./sbin
8.0K ./media
8.0K ./srv
0 ./sys
43M ./etc
42M ./home
8.0K ./opt
3.0G .
3.0G total
Taken from: http://www.wallpaperama.com/forums/linux-command-to-find-how-much-disk-space-is-being-used-show-display-t713.html
[root@288832-web3 ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 279G 265G 0 100% /
/dev/sda2 2.1G 355M 1.7G 18% /tmp
/dev/sda1 104M 26M 73M 26% /boot
tmpfs 13G 0 13G 0% /dev/shm
------------------------------------------------------------------
Find How Much Disk Space Is Being Used Show Display
Login as root
then cd /
then execute: du -hc --max-depth=1
Output:
[root@hostname /]# du -hc --max-depth=1
0 ./net
1.6G ./usr
16K ./lost+found
515M ./proc
8.0K ./misc
648M ./var
112K ./dev
8.0K ./mnt
66M ./lib
8.0K ./selinux
7.3M ./bin
77M ./root
4.2M ./boot
28K ./tmp
2.7M ./backups
20M ./sbin
8.0K ./media
8.0K ./srv
0 ./sys
43M ./etc
42M ./home
8.0K ./opt
3.0G .
3.0G total
Taken from: http://www.wallpaperama.com/forums/linux-command-to-find-how-much-disk-space-is-being-used-show-display-t713.html
Subscribe to:
Posts (Atom)