saltstack 安装nginx

1. 目录结构

[[email protected] salt]# tree /srv/salt/nginx/

/srv/salt/nginx/

+-- config.sls

+-- files

|   +-- nginx

|   +-- nginx-1.0.15.tar.gz

|   +-- nginx.conf

|   +-- nginx_log_cut.sh

|   +-- nginx-upstream-jvm-route-0.1.tar.gz

+-- init.sls

+-- install.sls

1 directory, 8 files

2.

[[email protected] nginx]# cat init.sls

include:

- nginx.install

- nginx.conf

- nginx.vhost

[[email protected] nginx]# cat config.sls

nginx_conf:

file.managed:

- name: /usr/local/webserver/nginx/conf/nginx.conf

- source: salt://nginx/files/nginx.conf

- template: jinja

nginx_script:

file.managed:

- name: /etc/init.d/nginx

- source: salt://nginx/files/nginx

- mode: 755

- user: root

cmd.run:

- names:

- /sbin/chkconfig --add nginx

- /sbin/chkconfig  nginx on

- unless: /sbin/chkconfig --list nginx

service.running:

- name: nginx

- enable: True

- reload: True

- watch:

- file: nginx_conf

nginx_log_cut:

file.managed:

- name: /usr/local/webserver/nginx/sbin/nginx_log_cut.sh

- source: salt://nginx/files/nginx_log_cut.sh

cron.present:

- name: /usr/local/webserver/nginx/sbin/nginx_log_cut.sh

- user: root

- minute: 59

- hour: 23

- require:

[[email protected] nginx]# cat install.sls

nginx_trans:

file.managed:

- source: salt://nginx/files/nginx-1.0.15.tar.gz

- name: /tmp/nginx-1.0.15.tar.gz

- unless: test -e /tmp/nginx-1.0.15.tar.gz

nginx_extract:

cmd.run:

- cwd: /tmp

- names:

- tar zxpf nginx-1.0.15.tar.gz

- require:

- file: nginx_trans

nginx_pkgs:

pkg.installed:

- pkgs:

- gcc

- openssl-devel

- pcre-devel

- zlib-devel

- libxml2

- libxml2-devel

- libxslt-devel

nginx_user:

user.present:

- name: nginx

- uid: 1502

- createhome: False

- shell: /sbin/nologin

nginx_compile:

cmd.run:

- cwd: /tmp/nginx-1.0.15

- names:

- mkdir -p /usr/local/webserver/

- ./configure --user=nginx --group=nginx --prefix=/usr/local/webserver/nginx --with-pcre --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-http_gzip_static_module --with-mail --with-mail_ssl_module --with-http_realip_module --with-http_xslt_module --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl

- make

- make install

- unless: test -d /usr/local/webserver/nginx

[[email protected] nginx]# ll files/

total 700

-rw-r--r-- 1 root root   2588 Sep  7 00:46 nginx

-rw-r--r-- 1 root root 693025 Apr 12  2012 nginx-1.0.15.tar.gz

-rw-r--r-- 1 root root   1529 Sep  7 01:28 nginx.conf

-rw-r--r-- 1 root root    568 Sep  7 01:40 nginx_log_cut.sh

-rw-r--r-- 1 root root   5807 Jul  1  2010 nginx-upstream-jvm-route-0.1.tar.gz

[[email protected] nginx]#

[[email protected] nginx]# cat files/nginx

#!/bin/sh

#

# 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:      /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/webserver/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/webserver/nginx/conf/nginx.conf"

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`" ]; then

useradd -M -s /bin/nologin $user

fi

options=`$nginx -V 2>&1 | grep ‘configure arguments:‘`

for opt in $options; do

if [ `echo $opt | grep ‘.*-temp-path‘` ]; then

value=`echo $opt | cut -d "=" -f 2`

if [ ! -d "$value" ]; then

# echo "creating" $value

mkdir -p $value && chown -R $user $value

fi

fi

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

[[email protected] nginx]# cat files/nginx_log_cut.sh

#!/bin/bash

logs_path="/usr/local/webserver/nginx/logs/"

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log

kill -USR1 `cat /usr/local/webserver/nginx/logs/nginx.pid`

cd ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")

tar zcpf access_$(date -d "yesterday" +"%Y%m%d").log.tar.gz access_$(date -d "yesterday" +"%Y%m%d").log

rm -f access_$(date -d "yesterday" +"%Y%m%d").log

exit

时间: 2025-01-05 17:02:03

saltstack 安装nginx的相关文章

SaltStack安装Nginx

1. 思路整理 五步走: 整个base环境规划 工作当中,我们在使用SaltStack的时候,环境目录的规划尽量做到标准化,自己要严格要求好!这也是作为一个运维工程师的基本技能要求. 安装Nginx(依赖包) 在本文章中,我的Example使用的是源码安装,也是当前主流的安装方式!(这里会用到pkg.installed,cmd.run等多种状态管理模块) 配置管理 在安装好服务之后,我们需要对服务进行基本的配置管理,通过模板文件来进行统一管理!(会用到"file.managed",&q

Saltstack安装nginx+haproxy

@font-face {  font-family: "Times New Roman";}@font-face {  font-family: "宋体";}@font-face {  font-family: "Calibri";}p.MsoNormal { margin: 0 0 0; text-align: justify; font-family: Calibri; font-size: 14px; }span.msoIns { text

salt-stack 安装nginx

init-pkg-install: pkg.installed: - names: - gcc - gcc-c++ - make - autoconf - openssl - openssl-devel - lsof - tree - lrzsznginx-source-install: file.managed: - name: /usr/local/src/nginx-1.8.1.tar.gz - source: salt://nginx-1.8.1.tar.gz - user: root

saltstack 系列(四)centos7使用saltstack源码安装nginx

使用saltstack源码安装nginx,首先先看一下我nginx的目录  tree一下,我们只需要关系nginx-install.sls 和nignx-service.sls.clu-vhost是我用python写的自动添加集群和自动更新踢出集群,后面会讲到. nginx ├── files │   ├── clu-vhost │   │   ├── 11.py │   │   ├── content.txt │   │   ├── epel-release-latest-7.noarch.r

(七)saltstack项目实战_安装nginx

创建nginx所需目录 [[email protected] ~]# cd /data/etc/salt/ [[email protected] salt]# mkdir -p nginx/files [[email protected] salt]# cd nginx/files/ [[email protected] files]# wget http://nginx.org/download/nginx-1.11.3.tar.gz [[email protected] salt]# tre

SaltStack 之 在从机上安装nginx软件

SaltStack 之 在从机上安装nginx软件 一.在salt目录下创建参数文件 [[email protected] salt]# vi install_nginx.sls nginx-install: #文件标识 pkg.installed: #pak:模块 installed:方法 - names: #names:所需安装的软件,在下面可列多个 - nginx #安装的软件名 service.running: #service:模块 running:方法 #用于服务启动 - names

【saltstack学习笔记之十】使用sls安装nginx并管理nginx的配置文件

1.需求 使用sls安装nginx并管理nginx的配置文件,当nginx配置文件被修改时,自动更新配置文件,并重启nginx. 2.配置 1.在master端上写好nginx.sls文件 mkdir -p /srv/salt/nginx cd /srv/salt/nginx vim init.sls nginx: pkg: - installed service: - running - enable: True - reload: True - watch: - pkg: nginx - f

SaltStack学习系列之State安装Nginx+PHP环境

目录结构 |-- pillar | |-- nginx | | `-- nginx.sls #nginx变量(key:value) | `-- top.sls `-- salt|-- init #初始化目录 | `-- repos.sls #安装yum源 |-- roles #角色(nginx和php) | |-- nginx #Nginx | | |-- config.sls #copy和利用pillar渲染配置文件 | | |-- files #存放需要copy和渲染到客户端的文件 | |

saltstack安装配置

1. saltstack安装前期准备:准备两台机器,写hostname10.10.13.239  master.river.com   10.10.13.248    client.river.com server上:yum install -y epel-releaseyum install -y salt-master  salt-minion client上:yum install -y epel-releaseyum install -y salt-minion 启动server上:/e