nginx安装脚本
2018-07-20 来源:open-open
#!/bin/bash # this 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
哎、、、nginx的脚本,我个人觉得写的不是很好。逻辑上不是很顺。只有待后面再重新改过了。
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇:统计时间分布脚本(mysql)
最新资讯
热门推荐