热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Linux脚本编译安装NGINX1.8.1(附启动脚本)

Linux脚本编译安装NGINX1.8.1(附启动脚本)话不多说,直接上货:#!binbash#开始NGINX编译前的
                 Linux 脚本编译安装NGINX1.8.1(附启动脚本)

话不多说,直接上货:

#!/bin/bash
#开始NGINX编译前的环境准备工作,请等候
yum install openssl openssl-devel pcre pcre-devel zlib zlib-devel -q -y
yum install -y -q autoconf automake apr apr-devel apr-util apr-util-devel \bison bzip2-devel cpp fontconfig-devel freetype-devel gcc gcc-c++ compat-dapl \compat-db-headers compat-db47 compat-gcc-44 compat-gcc-44-c++ compat-glibc \compat-glibc-headers compat-libcap1 compat-libf2c-34 compat-libgfortran-41 \compat-libtiff3 compat-openldap ncurses-deveal wget met-tools && echo $?
useradd -M -s /sbin/nologin nginx
wget http://nginx.org/download/nginx-1.8.1.tar.gz
echo "============================================================================="
echo "如果提前下载了NGINX的安装包,请将上面的下载注释"
tar zxf nginx-1.8.1.tar.gz -C /usr/local/src/
cd /usr/local/src/nginx-1.8.1/
echo $PWD
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx \
--without-http_memcached_module \
--with-http_gzip_static_module \
--with-threads \
--with-http_ssl_module \
--with-http_stub_status_module && make 2>&1 | tee /root/nginx.log && make installecho "编译完成,日志记录在/root/nginx.log内,如果出错,请查找原因,下面开始启动NGINX"
ln -s /usr/local/nginx/sbin/nginx /usr/bin/
nginx -t -c /usr/local/nginx/conf/nginx.conf
nginx && nginx -s reload
#生成启动脚本,启动方式为service nginx start|restart|stop|status
echo "#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ \"\$NETWORKING\" = \"no\" ] && exit 0
nginx=\"/usr/local/nginx/sbin/nginx\"
prog=\$(basename \$nginx)
NGINX_CONF_FILE=\"/usr/local/nginx/conf/nginx.conf\"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=\`\$nginx -V 2>&1 | grep \"configure arguments:\" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -\`if [ -z \"\`grep \$user /etc/passwd\`\" ]; thenuseradd -M -s /bin/nologin \$userfi
options=\`\$nginx -V 2>&1 | grep 'configure arguments:'\`
for opt in \$options; doif [ \`echo \$opt | grep '.*-temp-path'\` ]; thenvalue=\`echo \$opt | cut -d \"=\" -f 2\`if [ ! -d \"\$value\" ]; then# echo \"creating\" \$valuemkdir -p \$value && chown -R \$user \$valuefifi
done
}
start() {
[ -x \$nginx ] || exit 5
[ -f \$NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n \$\"Starting \$prog: \"
daemon \$nginx -c \$NGINX_CONF_FILE
retval=\$?
echo
[ \$retval -eq 0 ] && touch \$lockfile
return \$retval
}
stop() {
echo -n \$\"Stopping \$prog: \"
killproc \$prog -QUIT
retval=\$?
echo
[ \$retval -eq 0 ] && rm -f \$lockfile
return \$retval
}
restart() {
#configtest || return \$?
stop
sleep 1
start
}
reload() {
#configtest || return \$?
echo -n \$\"Reloading \$prog: \"
killproc \$nginx -HUP
RETVAL=\$?
echo
}
force_reload() {
restart
}
configtest() {
\$nginx -t -c \$NGINX_CONF_FILE
}
rh_status() {
status \$prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case \"\$1\" in
start)rh_status_q && exit 0\$1;;
stop)rh_status_q || exit 0\$1;;
restart|configtest)
\$1
;;
reload)rh_status_q || exit 7\$1;;
force-reload)force_reload;;
status)rh_status;;
condrestart|try-restart)rh_status_q || exit 0;;
*)
echo \$\"Usage: \$0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}\"
exit 2
esac">/etc/init.d/nginx
chmod +x /etc/init.d/nginx
echo "启动方式为service nginx start|restart|stop|status,热重启方式为: nginx -s reload"
chkconfig --add nginx && chkconfig nginx on && service nginx restart

相信以上完成后,打开同网段内的任意一个浏览器输入这台机器的ip就可以看到nginx的首页了。

总结:上述工作做完后,请在防火墙和selinux中放行nginx或者关闭防火墙和selinux,话不多说,具体的请百度。


推荐阅读
  • centos6.8 下nginx1.10 安装 ... [详细]
  • linux下编译安装lnmp
    2019独角兽企业重金招聘Python工程师标准#######################安装依赖#####################安装必要的包:y ... [详细]
  • 本文是搭建的mariadb-10.0.17版本的下载地址:https:downloads.mariadb.orginterstitialmariadb-10.0.17sourcemariadb-10.0.17.tar.gzfromhtt ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • centos php部署到nginx 404_NodeJS项目部署到阿里云ECS服务器全程详解
    本文转载自:http:www.kovli.com20170919ecs-deploy作者:Kovli本文详细介绍如何部署NodeJS项目到阿里云ECS上, ... [详细]
  • 基于SSL的mysql服务器的主从架构实现说明:本文选用172.16.22.1作为主服务器,172.16.22.3作为从服务器从服务器的mysql软件版 ... [详细]
  • linux clickhouse安装在指定目录_Centos8服务器指定目录安装配置Nginx
    1.安装前准备(1)检查是否安装过nginx(如果没有安装过可以无视)find-namenginx搜索nginx文件及其文件夹rm-rf【nginx配置地址文件及其文件夹】手动删除 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • Gitlab接入公司内部单点登录的安装和配置教程
    本文介绍了如何将公司内部的Gitlab系统接入单点登录服务,并提供了安装和配置的详细教程。通过使用oauth2协议,将原有的各子系统的独立登录统一迁移至单点登录。文章包括Gitlab的安装环境、版本号、编辑配置文件的步骤,并解决了在迁移过程中可能遇到的问题。 ... [详细]
  • 【技术分享】一个 ELF 蠕虫分析
    【技术分享】一个 ELF 蠕虫分析 ... [详细]
  • 开发笔记:Squid代理服务
    本文由编程笔记#小编为大家整理,主要介绍了Squid代理服务相关的知识,希望对你有一定的参考价值。Squid服务基础缓存代理概述 ... [详细]
  • 编译安装更轻量,不会像yum安装那么臃肿。(一)安装MYSQL:一、安装简介用户名:mysql安装目录:us ... [详细]
  • 文本处理与软件管理
    1、自建yum仓库,分别为网络源和本地源本地源:       网络源:[root@openvpn~]#catetcyum.repos.dCentOS-Base.repo#CentO ... [详细]
  • 删除iPad或iPhone目录privatevarkeychainskeychain-2.db文件,重启iPad或iPhone。1.如何卸载机内自带软件? ... [详细]
author-avatar
妖姬脸似花甘露_545
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有