Thursday 26 January 2012

Useful Apache commands



# apachectl ­-k graceful
In a server environment, should use the command apachectl instead of /etc/init.d/httpd. apachectl command is used to control the apache httpd daemon.

# apachectl -­k restart
difference between apachectl -k graceful and apachectl -k restart is that in case of the former current requests are not aborted but in the latter case current requests are aborted. 


# ps ­-ef | grep httpd
This command lists the httpd processes. -f option lists in full format. -e option lists all system processes. By using this command we can detect the processes that is causing trouble and those processes can be killed using the kill command. 

# kill ­term 'pid'
At a time there cannot be more than 50-60 child apache processes. If that is the case then it could probably be an attack. If we notice an apache attack then at once stop the apache service using the command. 

# apachectl -­k stop
If we notice that it is a server attack, ie attacks like denial of service, flooding then at once disconnect the network cable.

 # locate httpd.pid
# cat /var/run/httpd.pid
This command lists the running apache process id. ie the id of the parent apache.

# ps -­auxf | grep httpd
This command lists all httpd processes in full format. 

# vi /etc/init.d/httpd
This file is a sript used to run apache services. 


# ps ­ef ­­--forest | grep httpd
This command lists the httpd processes. ie the parent apache and the childs in full format (-f option). Each child can have their children and so on. 


# netstat -­tn
Prints the foreign connections to the server and the ports through which they are connected. 


# netstat | grep 35296
Lists the details about this paricular port.  


# lsof ­-i tcp:80
This command lists open files (lsof). 


# lsof -­i tcp:80 | wc ­l
lists the number of files that listens to the tcp port 80.
 


# cat /etc/httpd/conf/httpd.conf | grep User
Lists the user/group who run httpd. 


# top ­-u apache
Lists all processes run by user apache 


# httpd -­l
List compiled in modules. 


# httpd ­-M
Show all loaded modules. 


# httpd ­-L
List available configuration directives. 


# httpd ­-v
Show apache version.



No comments:

Post a Comment