ansible安装nginx (tengine)

简介:

# 接上篇

    http://xiong51.blog.51cto.com/5239058/1941193

ansible管理机:192.168.8.35 名称:kick

tomcat主机: 192.168.8.244,192.168.8.245   

haproxy  : 192.168.8.35

系统版本: Centos7.2



[root@kick ~]# ansible nginx -m copy -a "src=tengine-2.2.0.tar.gz dest=/tmp"

[root@kick ~]# ansible nginx -m copy -a "src=teng.sh dest=/tmp"

[root@kick ~]# ansible nginx -m shell -a "/bin/bash /tmp/teng.sh"


#####################  安装脚本 #####################

#!/bin/bash

#


yum -y install pcre pcre-devel openssl openssl-devel

tar xf  /tmp/tengine-2.2.0.tar.gz -C /tmp

cd /tmp/tengine-2.2.0

./configure --prefix=/usr/local/nginx/  --with-http_realip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_auth_request_module --with-http_upstream_check_module

make -j 4 && make -j 4 install

useradd nginx -s /sbin/nologin

mkdir /usr/local/nginx/run

chown nginx.nginx /usr/local/nginx -R

chmod 777  /usr/local/nginx/run

####################################################



################## 启动脚本 ##################

cat >> /usr/lib/systemd/system/nginx.server << EOF

[Unit]

Description=The nginx HTTP and reverse proxy server

After=network.target remote-fs.target nss-lookup.target


[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

# Nginx will fail to start if /usr/local/nginx/logs/nginx.pid already exists but has the wrong

# SELinux context. This might happen when running `nginx -t` from the cmdline.

# https://bugzilla.redhat.com/show_bug.cgi?id=1268621

ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid

ExecStartPre=/usr/local/nginx/sbin/nginx -t

ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

KillSignal=SIGQUIT

TimeoutStopSec=5

KillMode=process

PrivateTmp=true


[Install]

WantedBy=multi-user.target

EOF

#####################################################


[root@kick ~]# ansible nginx -m copy -a "src=nginx.service dest=/usr/lib/systemd/system/"

[root@kick ~]# ansible nginx -m shell -a "systemctl daemon-reload"

[root@kick ~]# ansible nginx -m shell -a "systemctl restart nginx"


########## 如一直出错检查一下端口被占情况 #########




####################### nginx 配置文件 ##########################

user nginx;

worker_processes 2;

error_log /usr/local/nginx/logs/error.log;

pid /usr/local/nginx/logs/nginx.pid;


# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/local/nginx/modules/*.conf;


events {

    worker_connections 1024;

}


http {

    log_format  main  '$http_x_forwarded_for $request_time - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent"';


    access_log  /usr/local/nginx/logs/access.log  main;


    sendfile            on;

    tcp_nopush          on;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 2048;


    include             /usr/local/nginx/conf/mime.types;

    default_type        application/octet-stream;


    upstream xiong.com {

        server 192.168.8.247:8080;

        server 192.168.8.246:8080;

        check interval=3000 rise=2 fall=5 timeout=1000 type=http;

}


    server {

        listen       80 default_server;

        server_name  localhost;

        charset utf-8;

        server_tokens off;


        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;


        location / {

                proxy_pass http://xiong.com;

                proxy_set_header Host $proxy_host;

                proxy_set_header Connection Close;

                proxy_set_header X-Forwarded-For $remote_addr;

        }

        location /status {

                check_status;

                access_log off;

        }

}

}

###########################################################################


# 复制文件并生启Nginx

[root@kick ~]# ansible nginx -m copy -a "src=nginx.conf dest=/usr/local/nginx/conf/"

[root@kick ~]# ansible nginx -m shell -a "systemctl restart nginx"




# nginx_check_module 访问  在Haproxy中访问效果,也可以直接使用nginx地址访问

http://192.168.8.35:81/status






###################### haproxy配置 ######################

# kickstact中安装

yum -y install haproxy


##################### haproxy配置文件 #####################

global

    log         127.0.0.1 local2

    chroot      /var/lib/haproxy

    pidfile     /var/run/haproxy.pid

    maxconn     4000

    user        haproxy

    group       haproxy

    daemon


    stats socket /var/lib/haproxy/stats


defaults

    mode                    http

    log                     global

    option                  httplog

    option                  dontlognull

    option http-server-close

    option forwardfor       except 127.0.0.0/8

    option                  redispatch

    retries                 3

    timeout http-request    10s

    timeout queue           1m

    timeout connect         10s

    timeout client          1m

    timeout server          1m

    timeout http-keep-alive 10s

    timeout check           10s

    maxconn                 3000


listen stats

bind 0.0.0.0:88  #配置状态信息 端口号为88

mode http  #模式为http

stats enable  #开启查询状态

stats hide-version   #隐藏版本号

stats uri /xiong?status  #访问状态的uri

stats auth xiong:xiong #认证帐号密码信息


frontend  http *:81

    option forwardfor header X-Forwarded-For   #配置后端显示的IP信息

    default_backend             tes     #默认后端地址


backend tes

    balance     roundrobin     #使用rr方式

    server  tes1 192.168.8.244:80 check

    server  tes2 192.168.8.245:80 check






     本文转自812374156 51CTO博客,原文链接:http://blog.51cto.com/xiong51/1941194,如需转载请自行联系原作者


相关文章
|
12天前
|
应用服务中间件 Linux 网络安全
2022年超详细在CentOS 7上安装Nginx方法(源码安装)
这篇文章提供了在CentOS 7系统上通过源码安装Nginx的详细步骤,包括从官网下载Nginx源码包、上传至虚拟机、解压、删除压缩包、编译安装前的配置、安装PCRE库(因为Nginx使用PCRE库解析正则表达式)、安装zlib和OpenSSL库(用于支持HTTPS协议)、重新编译Nginx、安装后启动Nginx服务、关闭服务、修改默认端口、以及重启服务测试等步骤。文章还提供了相关命令和操作截图,帮助用户更好地理解和执行安装过程。
2022年超详细在CentOS 7上安装Nginx方法(源码安装)
|
15天前
|
应用服务中间件 PHP nginx
Mac安装Nginx
Mac安装Nginx
16 2
Mac安装Nginx
|
4天前
|
缓存 应用服务中间件 nginx
安装nginx-http-flv-module模块
本文介绍如何为Nginx安装`nginx-http-flv-module`模块。此模块基于`nginx-rtmp-module`二次开发,不仅具备原模块的所有功能,还支持HTTP-FLV播放、GOP缓存、虚拟主机等功能。安装步骤包括:确认Nginx版本、下载相应版本的Nginx与模块源码、重新编译Nginx并加入新模块、验证模块安装成功。特别注意,此模块已包含`nginx-rtmp-module`功能,无需重复编译安装。
36 1
|
12天前
|
应用服务中间件 Linux nginx
Linux虚拟机磁盘扩容、Docker容器磁盘满的问题、Docker安装nginx
这篇文章讨论了Linux虚拟机磁盘扩容的方法,包括外部配置、具体扩容步骤和扩容后的效果验证。同时,文章还涉及了Docker容器磁盘满的问题及其解决方法,如删除不必要的镜像和容器,以及调整Docker的安装路径。此外,还提到了意外情况的处理,例如误删除停止的容器后的应对措施。最后,文章还提供了使用Docker安装nginx的步骤和成功访问的截图。
Linux虚拟机磁盘扩容、Docker容器磁盘满的问题、Docker安装nginx
|
9天前
|
应用服务中间件 Linux PHP
Linux搭建tengine2.0<Nginx>+php7环境
本文介绍了在Linux系统上搭建Tengine 2.0(一个Nginx的增强版本)和PHP 7环境的详细步骤,包括创建安装目录、下载源码包及依赖库、编译安装Nginx、配置Nginx、安装PHP及其依赖、设置PHP-FPM、配置环境变量、安装Git和Composer,以及服务管理和日志查看等。
27 0
|
10天前
|
应用服务中间件 Linux nginx
【Nginx 第二篇章】windwos、linux、docker-compose 安装 NGINX
在一节中,我们介绍了如何在Windows环境下安装Nginx,包括从官网下载稳定版压缩包、解压并直接运行`nginx.exe`启动服务,最后通过浏览器访问`http://localhost/`验证安装。第二节覆盖了Linux环境下的安装流程,首先安装必要依赖,接着利用包管理器安装Nginx,并通过`systemctl`或`service`命令启动,同样通过浏览器确认安装成功。第三节则展示了如何使用`docker-compose`轻松部署Nginx,通过编写`docker-compose.yml`文件定义服务和配置映射,最后执行`docker-compose up -d`后台启动容器。
19 0
|
16天前
|
关系型数据库 MySQL 应用服务中间件
在Ubuntu 16.04上使用Nginx安装和保护phpMyAdmin的方法
在Ubuntu 16.04上使用Nginx安装和保护phpMyAdmin的方法
14 0
|
tengine 应用服务中间件 nginx
|
12天前
|
应用服务中间件 nginx Docker
本地通过域名访问虚拟机上nginx的服务、搭建域名访问环境一(反向代理配置)
这篇文章介绍了如何通过域名在本地访问虚拟机上的nginx服务,包括创建nginx容器、修改配置文件、修改本地host文件以及进行访问测试的详细步骤。文章提供了具体的Docker命令来创建并配置nginx容器,展示了配置文件的修改示例,说明了如何在本地系统的hosts文件中添加虚拟机IP和自定义域名,以及如何通过浏览器进行测试访问。
本地通过域名访问虚拟机上nginx的服务、搭建域名访问环境一(反向代理配置)
|
8天前
|
Ubuntu 应用服务中间件 Linux
在Linux中,如何配置Web服务器(如Apache或Nginx)?
在Linux中,如何配置Web服务器(如Apache或Nginx)?