shell之yum安装nginx(适用没有yum仓库的中小企业)

判断和检查的部分可自行设置或不执行checkNginxRoot,以免受制于权限问题

#!/bin/bash

#by LC

IP=`ifconfig eth0|awk -F ‘[ :]+‘ ‘NR==2{print $4}‘`

CURL=`curl -I $IP|egrep "403|200|404"|head -1|wc -l`

ZHANDIAN=/data01/static/share

EXTRA=haixiang.conf

SERVERNAME=lc.lc.org

TOOLSDIR=/application/tools

NGINXDIR=/application/nginx1.8.0

EXTARDIR=/application/nginx1.8.0/conf/extra

ALIYUN=/etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

NGINXBANEN=nginx-1.8.0

NGINX=http://nginx.org/download/${NGINXBANEN}.tar.gz

panduan(){

if [ $? -ne 0 ]

then

echo "===============$1 NOT OK ===================="

exit 1

fi

}

function checkNginxRoot(){

if [ $UID -ne 0 ]

then

echo ‘PLEASES DO THIS "su -"‘ &&\

exit 1

fi

}

function checkNginxUser(){

if [ `cat /etc/passwd|grep nginx|wc -l` -eq 0 ]

then

useradd nginx -s /sbin/nologin -M

fi

}

function checkNginxDir(){

[ ! -d $TOOLSDIR ] && mkdir -p $TOOLSDIR

[ ! -d /app/ ] && mkdir -p /app

[ ! -d $NGINXDIR ] && mkdir -p $NGINXDIR

[ ! -d $EXTARDIR ] && mkdir -p $EXTARDIR

}

function checkYnmANDstart(){

wget -O $ALIYUN

yum makecache

yum install pcre pcre-devel -y

yum install openssl openssl-devel -y

cd $TOOLSDIR  &&\

wget $NGINX

tar xf $NGINXBANEN.tar.gz

cd $NGINXBANEN

./configure --user=nginx --group=nginx --prefix=/application/$NGINXBANEN --with-http_stub_status_module --with-http_ssl_module

panduan bianyi

make

panduan make

make install

cd ../

ln -s /application/$NGINXBANEN/ /application/nginx

panduan link

}

function NGINXCONF(){

cat >/application/$NGINXBANEN/conf/nginx.conf<<AA

worker_processes  1;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

#nginx vhosts config

include extra/$EXTRA;

}

AA

}

function haixiangconf() {

echo ‘haixiang‘ >> /application/$NGINXBANEN/conf/extra/haixiang.conf

cat >/application/$NGINXBANEN/conf/extra/haixiang.conf <<AA

server {

listen       80;

server_name  $SERVERNAME;

location / {

root   $ZHANDIAN;

index index.html index.htm;

}

}

AA

pkill nginx

pkill httpd

/application/$NGINXBANEN/sbin/nginx

}

function FORcurl(){

if [ $CURL -eq 1 ]

then

echo "############"

echo " OK  OK  OK"

echo "############"

fi

panduan CURL

}

function readme(){

echo "This is the start command :/application/$NGINXBANEN/sbin/nginx OR /application/nginx/sbin/nginx"

echo "This is the restart command:/application/$NGINXBANEN/sbin/nginx -s restart"

echo "This is the reload  command:/application/$NGINXBANEN/sbin/nginx -s reload"

echo "This is the test command:/application/$NGINXBANEN/sbin/nginx -t"

}

main (){

checkNginxUser

checkNginxDir

checkYnmANDstart

NGINXCONF

haixiangconf

FORcurl

readme

}

main

时间: 2024-12-26 13:51:00

shell之yum安装nginx(适用没有yum仓库的中小企业)的相关文章

centos7用yum安装nginx

安装好centos7后,将centos开通上网权限 1.将nginx加入yum # rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 2.yum安装Nginx 3.启动 配置文件和html目录

新安装的centos不能用yum安装nginx解决办法

在用yum安装nginx的时候,一直提示尝试其他更新源,找了好多地址不能用.最后终于找见了.现在贴出来给大家.先安装nginx的yum源,前提是我的yum安装其他的是OK的,yum update也是正常的,唯独不能yum安装nginx,所以最终定位是yum源中没有nginx.所以的找一个带有一个nginx的源. http://nginx.org/en/linux_packages.html   (这个地址列出了系统对应的nginx   yum源地址)#stable 找到链接,安装: rpm -i

CentOS 7 yum 安装 Nginx

1.添加Nginx到YUM源 添加CentOS 7 Nginx yum资源库,打开终端,使用以下命令: sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 2.安装Nginx 在你的CentOS 7 服务器中使用yum命令从Nginx源服务器中获取来安装Nginx: sudo yum install -y nginx Nginx将完成安装在

[转]CENTOS 6.5 配置YUM安装NGINX+服务器负载均衡

原文连接: CENTOS 6.5 配置YUM安装NGINX  http://blog.sina.com.cn/s/blog_69f467b70102uyux.html 本文介绍一下如何用yum源安装Nginx. 第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo: cd /etc/yum.repos.d/ vim nginx.repo 填写如下内容: [nginx] name=nginx repo baseurl=http://nginx.org/packa

centos 下yum 安装nginx

centos 下yum 安装nginx 1. 直接yum install nginx不行,要先处理下源: rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm 2. 查看源: yum info nginx 这时会提示有可安装的软件包 nginx | 2.9 kB 00:00nginx/primary_db | 15 kB 00:00可安装的软件包Nam

centos yum安装nginx 提示 No package nginx available

centos yum安装nginx 提示 No package nginx available问题了,对于这个问题我们下文正是介绍它的解决方法了,希望下文能够为各位带来帮助. 问题原因: nginx位于第三方的yum源里面,而不在centos官方yum源里面 解决方法: 安装epel(Extra Packages for Enterprise Linux) a.去epel网站 http://fedoraproject.org/wiki/EPEL下载 b.我的系统是centos5.7,cpu是x8

yum安装nginx最新官网稳定版

1. 增加nginx yum仓库 vi /etc/yum.repos.d/nginx.repo CentOS增加这段: [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 RHEL增加这段: [nginx] name=nginx repo baseurl=http://nginx.org/packages/rhel/$release

CentOS 6.7下配置 yum 安装 Nginx

CentOS 6.7下配置 yum 安装 Nginx. 转载:http://www.linuxidc.com/Linux/2016-07/133283.htm 第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo: cd /etc/yum.repos.d/ vim nginx.repo 填写如下内容: [nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/6/$basearch/gpgch

centos7通过yum安装nginx

centos7通过yum安装nginx nginx不支持centos7通过yum直接安装~~~ 1.查看操作系统位数[[email protected] ~]# rpm -aq|grep centos-releasecentos-release-7-4.1708.el7.centos.x86_64/ 2.创建nginx的yum源[[email protected] ~]# cat  /etc/yum.repos.d/nginx.repo[nginx]name=nginx repobaseurl=

Centos7 yum安装nginx

centos7 yum 安装nginx 1.添加Nginx到YUM源 添加CentOS 7 Nginx yum资源库,打开终端,使用以下命令: sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 2.安装Nginx 在你的CentOS 7 服务器中使用yum命令从Nginx源服务器中获取来安装Nginx: yum install -y ng