Apache HTTP Server 점검 스크립트
-
short3300
(스벅오늘의커피) - 이 글의 작성자
- Offline
- Junior
덜보기
더보기
- Posts: 182
- Thank you received: 24
25 Jan 2022 16:44 #5488
작성자: short3300
short3300 님의 글: Apache HTTP Server 점검 스크립트
#!/bin/sh
usage() {
echo " Usage :"
echo " ./httpd_check.sh -h [webwas-home]"
echo ""
echo " Example :"
echo " $ ./httpd_check.sh -h /sw/apache/2.4/servers"
echo ""
}
print_k_v() {
printf "| %-20s | %s\n" "$1" "$2"
}
print_k_v_raw() {
printf "%s^%s\n" "$1" "$2"
}
print_t_l_s() {
printf "+----------------------+--------------------------------------------------------------------\n"
}
print_t_l_e() {
printf "+----------------------+--------------------------------------------------------------------\n\n"
}
get_value() {
echo $1 | cut -d'=' -f2 | sed -e 's/"//g' | sed -e 's/\/>//g'
}
get_ltrim_strip_field2() {
echo $1 | sed -e 's/^[[:space:]]*//' | sed -e 's/"//g' | cut -d' ' -f2
}
get_ltrim_strip_varlable_field2() {
echo $1 | sed -e 's/^[[:space:]]*//' | sed -e 's/["|$|{|}]//g' | cut -d' ' -f2
}
get_apa_custom_log() {
if [[ $1 == *"rotatelog"* ]]; then
apa_custom_log1=`echo $1 | cut -d' ' -f3 | awk -F "/" '{print $NF}'`
else
apa_custom_log1=`echo $1 | cut -d' ' -f2 | awk -F "/" '{print $NF}'`
fi
echo ${apa_custom_log1//\"/}
}
get_apa_error_log() {
if [[ $1 == *"rotatelog"* ]]; then
echo $1 | cut -d' ' -f2 | sed -e 's/\"//g' | awk -F "/" '{print $NF}'
else
echo $1 | cut -d' ' -f1 | sed -e 's/\"//g' | awk -F "/" '{print $NF}'
fi
}
display_apache_server() {
inst_count=0
for inst in `cd $HTTPD_HOME/servers; ls -d */`
do
inst_count=$(($inst_count + 1))
inst=${inst%%/}
apa_inst_ps=`ps -ef | grep httpd | grep ${inst} | grep -v grep | head -1`
apa_inst_user=`echo $apa_inst_ps | awk '{print $1}'`
apa_inst_ver=`$HTTPD_HOME/bin/httpd -v | grep version`
apa_inst_home=$HTTPD_HOME/servers/$inst
apa_inst_ver=`$HTTPD_HOME/bin/httpd -v | grep version | sed -e 's/Server version: //g'`
env_sh=$apa_inst_home/env.sh
echo ""
ps -ef | grep httpd | grep ${inst} | grep -v grep
echo ""
if [ -d "$env_sh" ]; then
. $env_sh
fi
httpd_conf=$apa_inst_home/conf/httpd.conf
httpd_ssl_conf=$apa_inst_home/conf/extra/httpd-ssl.conf
httpd_default_conf=$apa_inst_home/conf/extra/httpd-default.conf
workers_properties=$apa_inst_home/conf/workers.properties
if [ -d "$env_sh" ]; then
apa_inst_listen_http=`grep "^export SERVICE_PORT=" $env_sh | cut -d'=' -f2`
else
apa_inst_listen_http=`grep "^Listen" $httpd_conf | cut -d' ' -f2`
fi
netstat -an | grep tcp | grep ":$apa_inst_listen_http" | grep LISTEN > /dev/null
if [ $? -eq 0 ]; then
is_apa_inst_listen_http="Listen"
else
is_apa_inst_listen_http="Not Listen"
fi
if [ -d "$env_sh" ]; then
apa_inst_listen_https=`grep "^Listen" $env_sh | cut -d'=' -f2`
else
apa_inst_listen_https=`grep "^Listen" $httpd_ssl_conf | cut -d' ' -f2`
fi
netstat -an | grep tcp | grep ":$apa_inst_listen_https" | grep LISTEN > /dev/null
if [ $? -eq 0 ]; then
is_apa_inst_listen_https="Listen"
else
is_apa_inst_listen_https="Not Listen"
fi
if [ -d "$env_sh" ]; then
apa_inst_documrnt_root1=`get_ltrim_strip_varlable_field2 "\`grep 'DocumentRoot ' $httpd_conf | grep -v '#'\`"`
apa_inst_document_root=`grep "^export $apa_inst_documrnt_root1=" $env_sh | cut -d'=' -f2`
else
apa_inst_document_root=`grep "^DocumentRoot" $httpd_conf | cut -d' ' -f2`
fi
if [ -d "$apa_inst_document_root" ]; then
apa_inst_document_root_permission=`ls -ld $apa_inst_document_root | awk {'print $1'}`
else
apa_inst_document_root_permission="No Directory"
fi
apa_inst_trace_enable=`grep "^TraceEnable " $httpd_conf | cut -d' ' -f2`
apa_inst_keep_alive=`grep "^KeepAlive " $httpd_default_conf | cut -d' ' -f2`
apa_inst_keep_alive_timeout=`grep "^KeepAliveTimeout " $httpd_default_conf | cut -d' ' -f2`
apa_inst_server_tokens=`grep "^ServerTokens " $httpd_default_conf | cut -d' ' -f2`
apa_inst_server_signature=`grep "^ServerSignature " $httpd_default_conf | cut -d' ' -f2`
apa_inst_custom_log=`get_apa_custom_log "\`grep "CustomLog " $httpd_conf | grep -v "#" | sed -e 's/^[[:space:]]*//'\`"`
apa_inst_error_log=`get_apa_error_log "\`grep "^ErrorLog " $httpd_conf | cut -d' ' -f2-\`"`
## MPM
is_mpm_line=0
while read mpm_line
do
if [ $is_mpm_line -eq 0 -a "$mpm_line" == "<IfModule mpm_worker_module>" ]; then
is_mpm_line=1
elif [ $is_mpm_line -eq 1 -a "$mpm_line" == "</IfModule>" ]; then
break
fi
if [ $is_mpm_line -eq 1 ]; then
if [[ "$mpm_line" == *"StartServers"* ]]; then
tmp_str=${mpm_line/"StartServers"}
apa_inst_mpm_start_servers=${tmp_str//[[:blank:]]/}
elif [[ "$mpm_line" == *"MaxClients"* ]]; then
tmp_str=${mpm_line/"MaxClients"}
apa_inst_mpm_max_clients=${tmp_str//[[:blank:]]/}
elif [[ "$mpm_line" == *"ThreadsPerChild"* ]]; then
tmp_str=${mpm_line/"ThreadsPerChild"}
apa_inst_mpm_threads_per_child=${tmp_str//[[:blank:]]/}
fi
fi
done < $apa_inst_home/conf/extra/httpd-mpm.conf
echo " <> Apache HTTP Server - $inst_count. $inst"
echo ""
ps -ef | grep httpd | grep ${inst} | grep -v grep
echo ""
print_t_l_s
print_k_v "Hostname" "$webwas_host_name"
print_k_v "CPU Count" "$webwas_cpu_count"
print_k_v "Memory Total" "$webwas_mem_total"
print_k_v "IP Address (eth)" "$webwas_ip_address"
print_k_v "OS" "$webwas_os_info"
print_t_l_s
print_k_v "Apache Version" "$apa_inst_ver"
print_k_v "WEB User" "$apa_inst_user"
print_k_v "Instance Home" "$apa_inst_home"
print_k_v "Start Script" "start.sh"
print_k_v "Stop Script" "stop.sh"
print_k_v "HTTP Port" "$apa_inst_listen_http ($is_apa_inst_listen_http)"
print_k_v "HTTPS Port" "$apa_inst_listen_https ($is_apa_inst_listen_https)"
print_k_v "Access Log" "$apa_inst_custom_log"
print_k_v "Error Log" "$apa_inst_error_log"
print_k_v "Document Root" "$apa_inst_document_root ($apa_inst_document_root_permission)"
print_k_v "KeepAlive" "$apa_inst_keep_alive"
print_k_v "KeepAliveTimeout" "$apa_inst_keep_alive_timeout"
print_k_v "TraceEnable" "$apa_inst_trace_enable"
print_k_v "ServerTokens" "$apa_inst_server_tokens"
print_k_v "ServerSignature" "$apa_inst_server_signature"
print_k_v "StartServers" "$apa_inst_mpm_start_servers"
print_k_v "MaxClients" "$apa_inst_mpm_max_clients"
print_k_v "ThreadsPerChild" "$apa_inst_mpm_threads_per_child"
print_t_l_s
#vhost_seq=1
#for vhost in `cd $apa_inst_home/conf/extra/vhost; ls`
#do
#vhost_conf=$apa_inst_home/conf/extra/vhost/$vhost
#vhost_name=`echo $vhost | sed -e 's/.conf//g'`
#print_k_v "Virtual Host" "[$vhost_seq] $vhost_name"
#_get_vhost
#_get_urimap
#print_k_v "- Uriworkermap" " - `(IFS=$','; echo \"${urimap_array[*]}\")`"
#print_k_v "- Document Root" " - $apa_inst_vhost_document_root"
#print_k_v "- Access Log" " - $apa_inst_vhost_custom_log"
#print_k_v "- Error Log" " - $apa_inst_vhost_error_log"
#done
print_t_l_s
worker_seq=1
lb_seq=1
IFS=","
for lb in `grep '^worker.list=' $workers_properties | cut -d'.' -f2 | sed -e 's/list=//g'`
do
if [ "$lb" != "jkstatus" ]; then
lb_name=$lb
print_k_v "Load Balancer" "[$lb_seq] $lb_name"
IFS=","
for lb_worker in `grep "worker.$lb_name.balance_workers=" $workers_properties | grep -v "^#" | cut -d'=' -f2`
do
print_k_v "- Worker Name" " ($worker_seq) $lb_worker"
IFS=$IFS_NEW_LINE
for all_worker in `grep "^worker.$lb_worker." $workers_properties \
| grep -v '^worker.list' \
| grep -v '^worker.template' \
| grep -v '^worker.jkstatus' \
| cut -d'.' -f2 \
| sort \
| uniq`
do
if [ "$lb_worker" == "$all_worker" ]; then
print_k_v " - Host" " - `grep "${all_worker}.host=" $workers_properties | cut -d'=' -f2`"
print_k_v " - Port" " - `grep "${all_worker}.port=" $workers_properties | cut -d'=' -f2`"
print_k_v " - Pool" " - `grep "${all_worker}.connection_pool_size=" $workers_properties | cut -d'=' -f2`"
print_k_v " - Pool Min" " - `grep "${all_worker}.connection_pool_minsize=" $workers_properties | cut -d'=' -f2`"
((worker_seq++))
fi
done
done
((lb_seq++))
fi
done
print_t_l_e
done
}
_get_vhost() {
apa_inst_vhost_document_root1=`get_ltrim_strip_varlable_field2 "\`grep 'DocumentRoot ' $vhost_conf | grep -v '#'\`"`
apa_inst_vhost_document_root=`echo ${!apa_inst_vhost_document_root1} | cut -d'=' -f2`
if [ -d "$apa_inst_vhost_document_root" ]; then
apa_inst_vhost_document_root_permission=`ls -ld $apa_inst_vhost_document_root | awk {'print $1'}`
else
apa_inst_vhost_document_root_permission="No Directory"
fi
apa_inst_vhost_custom_log=`get_apa_custom_log "\`grep "CustomLog " $vhost_conf \
| grep -v "#" | sed -e 's/^[[:space:]]*//'\`"`
apa_inst_vhost_error_log=`get_apa_error_log "\`grep "^ErrorLog " $vhost_conf \
| cut -d' ' -f2-\`"`
}
_get_urimap() {
apa_inst_vhost_uriworkermap=`get_ltrim_strip_field2 "\`grep 'JkMountFile ' $vhost_conf | grep -v '#'\`"`
echo $apa_inst_vhost_uriworkermap
urimap_array=()
if [ "$apa_inst_vhost_uriworkermap" != "" ]; then
for urimap in `cat \`eval echo $apa_inst_vhost_uriworkermap\``
do
uri=`echo $urimap | cut -d'=' -f1 | sed -e 's/[\||\/]//g'`
if [ "$uri" == "*" ]; then
urimap_array+=("*")
else
urimap_array+=($uri)
fi
done
fi
}
while [[ $# > 1 ]]
do
key="$1"
case $key in
-h|--home)
HTTPD_HOME="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
#echo "home = $HTTPD_HOME"
IFS_NEW_LINE=$'
'
webwas_host_name=`uname -n`
if [ `ifconfig -a | grep eth0 | wc -l` -gt 0 ]; then
webwas_ip_address=`ifconfig eth0 | grep 'inet addr:' | cut -d':' -f2 | awk '{print $1}'`
elif [ `ifconfig -a | grep eth1 | wc -l` -gt 0 ]; then
webwas_ip_address=`ifconfig eth1 | grep 'inet addr:' | cut -d':' -f2 | awk '{print $1}'`
fi
webwas_os_info=`uname -sr`
webwas_cpu_count=`grep processor /proc/cpuinfo | wc -l`
webwas_mem_total=`grep MemTotal /proc/meminfo | cut -d':' -f2 | sed -e 's/^[[:space:]]*//'`
echo ""
display_apache_server
Time to create page: 0.051 seconds