nginx安裝腳本
#!/bin/bashthis shell will be installed jdk*.tar.gz
author: wangjiulong
ROOT=$(pwd)
SCRIPTS=$ROOT/scripts
PKGS=$ROOT/pkgs
NGINX_ROOT=/usr/local/nginx
服務器如果已經安裝了nginx,那么就不重新安裝;沒有,就安裝.
nginx_path=/usr/local/nginx
檢查要安裝的nginx版本,記錄保存
nginx_pkg=
cat $tmp_nginx_pkgtar
cat $tmp_nginx_pkgtar | awk -F.tar.gz '{print $1}' | awk -F- '{print $2}' > $tmp_nginx_pkgtar_version 2>&1 nginx_tar=cat $tmp_nginx_pkgtar | awk -F.tar.gz '{print $1}'
nginx_tar_version=cat $tmp_nginx_pkgtar_version
檢查本機中的nginx版本,記錄保存
nginx_local=$nginx_path/sbin/nginx -v > $tmp_nginx_local 2>&1 cat $tmp_nginx_local | awk -F[\/] '{print $2}' > $tmp_nginx_local_version 2>&1 nginx_local_version=
cat $tmp_nginx_local_version
datef() { date "+%Y/%m/%d %H:%M"; }
custom log
print_log(){ if [[ -d $log_dir ]];then echo "[$(datef)] $1" >> $log else echo "[$(datef)] log path does not exist,created first" >>$log mkdir -p $log_dir echo "[$(datef)] $1" >> $log fi }
檢查nginx是否安裝
Check whether the installation nginx
check_nginx(){
diff_value=
diff $tmp_nginx_local_version $tmp_nginx_pkgtar_version ;echo $?
nginx_value=ls $nginx_path > /dev/null 2>&1 ;echo $?
case $nginx_value in 0) case $diff_value in 0) print_log "本機已經安裝了nginx,nginx的版本是$nginx_local_version,程序即將退出。" exit ;; 1) print_log "本機已經安裝了nginx,但與要安裝的nginx的版本不一致。" exit ;; *) print_log "程序存在異常,即將退出。異常可能是因為不存在文件/目錄導致的,請檢查!!!" ;;
esac print_log "本機已經安裝了nginx,nginx的版本是$nginx_local_version,程序即將退出。" exit ;; *) print_log "本機不存在nginx目錄,程序即將安裝nginx,nginx版本是$nginx_tar_version" install_nginx ;; esac }
install nginx
install_nginx(){
cd $tar_dir tar -zxf $nginx_pkg cd $nginx_tar ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre --without-select_module --without-poll_module && make && make install
if [[ $? != "0" ]];then print_log "[$(datef)] install_nginx(): install error!" exit fi
cp -fv $file_dir/nginx /etc/init.d/nginx cp -fv $file_dir/nginx.conf $nginx_path/conf/ chkconfig --add nginx
add_user #Test config file exits }
add_user(){ print_log "**begin change www user mode ** " if ! grep "^www" /etc/passwd then groupadd www useradd -g www -d /data/www www fi print_log "**end changed *** " finished }
finished(){ #install complete print_log "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" print_log "+ [$(datef)] congratulagions!++++++++++++++++++++++++++++" print_log "+ [$(datef)] don't forget to modify configuration files++" print_log "+ [$(datef)] based on your system resources like mem size" print_log "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" }
print_log "執行check_nginx函數,開始準備安裝nginx" check_nginx</pre>
哎、、、nginx的腳本,我個人覺得寫的不是很好。邏輯上不是很順。只有待后面再重新改過了。