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

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

[[email protected] ~]# ansible nginx -m copy -a "src=teng.sh dest=/tmp"

[[email protected] ~]# 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

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

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

[[email protected] ~]# ansible nginx -m shell -a "systemctl daemon-reload"

[[email protected] ~]# 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

[[email protected] ~]# ansible nginx -m copy -a "src=nginx.conf dest=/usr/local/nginx/conf/"

[[email protected] ~]# 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

时间: 2024-10-17 07:50:52

ansible安装nginx (tengine)的相关文章

ansible安装nginx

ansible安装nginx实现回滚发布功能 一.准备工作 1.准备两台机器 sai: 192.168.131.132  --> ansible的服务端 luojy: 192.168.131.133 --> ansible的客户端 2.132机器上安装ansible (1)yum install -y epel-release (2)yum install -y ansible 3.132,133机器上关闭防火墙 4.设置hostname,/etc/sysconfig/network 上定义

使用Ansible安装部署nginx+php+mysql

前提: 1.已配置好hosts文件且免密码登录 2.需要的yaml文件已上传到主控端 一.使用Ansible安装nginx 1.nginx.yaml文件 1 --- 2 - hosts: clong 3 remote_user: root 4 gather_facts: no 5 tasks: 6 # 安装epel源 7 - name: install epel-release repo 8 yum: name=epel-release state=present 9 # 安装libselinu

4.1-ansible实例-安装nginx上

Ansible 安装nginx * 思路:先在一台机器上编译安装好nginx.打包,然后再用ansible去下发 1./usr/local/nginx/是已经编译安装好的nginx文件,配置好了启动脚本和配置文件. 2.cd /usr/local                  #进入上一级目录 3.tar czvf nginx.tar.gz nginx    #将目录打包 4.cd /etc/ansible   进入ansible配置文件目录 5.mkdir  nginx_install  

用ansible自动 安装nginx

一 前期说明 l思路:先在一台机器上编译安装好nginx.打包,然后再用ansible去下发 lcd /etc/ansible   进入ansible配置文件目录 lmkdir  nginx_install   创建一个nginx_install的目录,方便管理 lcd nginx_install; lmkdir -p roles/{common,install}/{handlers,files,meta,tasks,templates,vars} ## 分别在common 和install 这

ansible实战-nginx安装

背景:尽管yum和service模块安装和管理相应服务很方便,但实际生产中,一般需要使用源码安装 思路:先在一台机器上编译安装好nginx,打包,再用ansible分发下去 1. 创建相关目录和配置文件,整体树状图 mkdir /etc/ansible/nginx_install 1.1 vim /etc/ansible/nginx_install/install.yml #总安装文件 --- - hosts: agent.huangzp.com   remote_user: root   ga

ansible 初探nginx安装

我的配置: /etc/hosts: /etc/ansible/hosts: nglinx安装包: ansible自动化安装nginx: 1.安装ansible. 2.创建目录结构: mkdir -p /ansible/roles/nginx/{defaults,files,handlers,meta,tasks,templates,vars} 3.install_nginx.sh: #!/bin/bash yum -y install zlib zlib-devel openssl openss

ansible案例-安装nginx

一.创建目录: mkidr -p playbook/{files,templates}   二.自定义index.html文件 $ vim playbook/templates/index.html.j2 ----------------------------------------------------------> <html> <head> <title>Welcome to ansible</title> <body> <

ansible自动化安装nginx

1.安装ansible 参考:运维自动化工具之Ansible 2.ansible相关配置 cat /etc/ansible/hosts [webserver] 192.168.1.101 192.168.1.102 3.在/etc/ansible/roles中创建nginx目录结构 [[email protected] roles]# mkdir -p/etc/ansible/roles/nginx/{defaults,files,handlers,meta,tasks,templates,va

LNMP环境之Nginx/Tengine的源代码安装及优化

一.介绍: Tengine是由淘宝网发起的Web服务器项目.它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性.Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验.它的最终目标是打造一个高效.稳定.安全.易用的Web平台. 二.下载并安装: [[email protected] ]#wget http://tengine.taobao.org/download/tengine-2.1.0.tar.gz 安装前需要安装依赖的库文件: yum  i