当前位置: 首页 > news >正文

网页和网站有什么区别最近国际新闻大事20条

网页和网站有什么区别,最近国际新闻大事20条,行业网站建设内容,做视频网站注意什么通过学习ansible自动化运维,初步对ansible有了一定的了解,此次分享两个案例,希望对大家有所帮助 案例一:自动化安装nginx 本次案例目的是ansible自动化安装nginx并配置 首先创建如图所示目录 在主机上安装好nginx,如…

通过学习ansible自动化运维,初步对ansible有了一定的了解,此次分享两个案例,希望对大家有所帮助

案例一:自动化安装nginx

本次案例目的是ansible自动化安装nginx并配置

首先创建如图所示目录

在主机上安装好nginx,如下:

使用wget下载nginx包,下载地址:http://mirrors.sohu.com/nginx/nginx-1.9.6.tar.gz
对nginx进行解压
tar -zxvf nginx-1.9.6.tar.gz -C /usr/local
cd /usr/local/nginx-1.9.6
./configure --prefix=/usr/local/nginx
若是报错,根据提示安装好缺少的依赖
make && makeinstall

修改/etc/init.d/nginx 内容如下:

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usx/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"start()
{echo -n $"Starting $prog: "mkdir -p /dev/shm/nginx_tempdaemon $NGINX_SBIN -c $NGINX_CONFRETVAL=$?echoreturn $RETVAL
}
stop()
{echo -n $"Stopping $prog: "killproc -p $NGINX_PID $NGINX_SBIN -TERMrm -rf /dev/shm/nginx_tempRETVAL=$?echoreturn $RETVAL
}
reload()
{echo -n $"Reloading $prog: "killproc -p $NGINX_PID $NGINX_SBIN -HUPRETVAL=$?echoreturn $RETVAL
}
restart()
{stopstart
}
configtest()
{$NGINX_SBIN -c $NGINX_CONF -treturn 0
}
case "$1" instart)start;;stop)stop;;reload)reload;;restart)restart;;configtest)configtest;;*)echo $"Usage: $0 {start|stop|reload|restart|configtest}"RETVAL=1
esac
exit $RETVAL

授予权限

chmod 777 /etc/init.d/nginx

清空该文件并进行如下配置/usr/local/nginx/conf/nginx.conf

user nobody nobody;             #定义nginx运行的用户和用户组
worker_processes 2;             #nginx进程数,一般为CPU总核心数
error_log /usr/local/nginx/logs/nginx_error.log crit;   #全局错误日志定义类型
pid /usr/local/nginx/logs/nginx.pid;    #进程文件
worker_rlimit_nofile 51200;
events          #工作模式与连接数上限
{
use epoll;
worker_connections 6000;
}
http            #http下的一些配置
{
include mime.types;             #文件扩展名与文件类型映射表
default_type application/octet-stream;          #默认文件类型
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;            #开启高效文件传输模式
tcp_nopush on;          #防止网络阻塞
keepalive_timeout 30;           #长连接超时时间,单位为秒
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;         #防止网络阻塞
gzip on;                #开启gzip压缩输出
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
server          #虚拟主机配置
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/1ocal/nginx/html$fastcgi_script_name;
}
}
}

启动服务

service nginx start

将nginx的压缩包移动至目标目录下,复制启动脚本和配置文件到目标目录下

mv nginx-1.9.6.tar.gz /etc/ansible/nginx_install/roles/install/files/
cp /usr/local/nginx/conf/nginx.conf /etc/ansible/nginx_install/roles/install/templates/
cp /etc/init.d/nginx /etc/ansible/nginx_install/roles/install/templates/

在nginx_install目录下编写启动文件install.yml

---
- hosts: testremote_user: rootgather_facts: Trueroles:- common- install

在roles/common/tasks/main.yml文件下编写需要安装的依赖文件

- name: install initialization require softwareyum: name={{ item }} state=installedwith_items:- zlib-devel- pcre-devel- gcc

在 roles/install/vars/main.yml文件下定义各种变量

nginx_user: www
nginx_port: 80
nginx_basedir: /usr/local/nginx

在roles/install/tasks/copy.yml文件下编写需要复制的文件

- name: Copy Nginx Software   #复制nginx安装包copy: src=nginx-1.9.6.tar.gz dest=/tmp/nginx-1.9.6.tar.gz owner=root group=root
- name: Uncompression Nginx Software  #解压nginxshell: tar zxf /tmp/nginx-1.9.6.tar.gz -C /usr/local/
- name: Configure Nginx   #编译安装nginxshell: cd /usr/local/nginx-1.9.6 && ./configure --prefix=/usr/local/nginx
- name: Make Nginx   #初始化nginxshell: cd /usr/local/nginx-1.9.6 && make && make install
- name: Copy Nginx Start Script   #复制nginx启动脚本template: src=nginx dest=/etc/init.d/nginx owner=root group=root mode=0755
- name: Copy Nginx Config  #复制nginx配置文件template: src=nginx.conf dest={{ nginx_basedir }}/conf/ owner=root group=root mode=0644

在roles/install/tasks/install.yml下编写启动文件

- name: create nginx useruser: name={{ nginx_user }} state=present createhome=no shell=/sbin/nologin
- name: start nginx serviceshell: /etc/init.d/nginx start
- name: add boot start nginx serviceshell: chkconfig --level 345 nginx on
- name: delete nginx compression filesshell: rm -rf /tmp/nginx-1.9.6.tar.gz

在 roles/install/tasks/main.yml中编写主要文件

- include: copy.yml
- include: install.yml

执行脚本,结果如图所示

在test主机中查看nginx是否启动

可以看到启动成功

案例二:管理nginx配置文件

首先创建如下目录:

roles目录下分为new目录和old目录,new目录表示需要更新的配置文件,old目录为备份的文件。在做配置文件的时候,备份非常重要,在执行update.yml文件前应该备份好当前配置文件,出现错误时可以及时的回滚操作。

 rsync -av /etc/ansible/nginx_config/roles/new/  /etc/ansible/nginx_config/roles/old/

使用该命令可以将new目录中的配置文件备份到old目录中

files目录中表示的是配置文件,可以自行添加,此处放置的为空目录。

handlers目录中表示的是重启服务,内容如下

- name: restart nginx   #用于重新加载nginx服务shell: /etc/init.d/nginx reload

tasks目录中就是主要的命令,内容如下:

- name: copy conf file  #复制.conf和hosts文件copy: src={{ item.src }} dest={{ nginx_basedir }}/{{ item.dest }} backup=yes owner=root group=root mode=0644with_items:- { src: nginx.conf, dest: conf/nginx.conf }- { src: vhosts, dest: conf/ }notify: restart nginx

vars目录中表示变量,内容如下:

nginx_basedir: /usr/local/nginx #定义变量

update.yml文件为更新文件,内容为:

---
- hosts: test  #入口文件user: rootroles:- new         #这里只有new

执行命令,结果如下:

由于此处的files目录中放置的是空目录,所以结果没有任何改变,可以自行添加配置文件进行修改。

http://www.yidumall.com/news/46057.html

相关文章:

  • 没有网站做cpa海东地区谷歌seo网络优化
  • 多语言企业网站源码天津seo顾问
  • 一般的企业网站开发价格设计好看的网站
  • 品牌网站建设怎么做网站推广宣传语
  • 查看一个网站的备案人2023今日新闻头条
  • 佛山新网站制作平台大数据分析师
  • wordpress怎么设计网站百度爱采购官方网站
  • 网络推广和seo杭州专业seo服务公司
  • 岳阳二手房网站百度软件安装
  • 网站平台构建网站做优化一开始怎么做
  • 自助建站系统免费加盟360识图
  • 南宁自助建站软件windows优化大师卸载
  • 做博客网站怎么赚钱网络营销专业是做什么的
  • 石河子网页制作招聘宁波seo推广服务电话
  • 网站设置访问密码神马网站快速排名软件
  • 山东网站营销指数基金
  • 大于二高端网站建设公司网站推广费用
  • 关于网站建设的论文提纲网站seo公司哪家好
  • 任丘网站开发建设怎么选软件开发公司排名
  • wordpress网站 app河南seo技术教程
  • 哪些公司经常做网站发布平台
  • 外贸局是做什么的工作陕西seo快速排名
  • 哪些网站是dz做的推广软件赚钱违法吗
  • 网站开发合同封面优化关键词排名推广
  • 山西网络网站建设销售公司常熟seo网站优化软件
  • 上海html5网站制作个人免费建站软件
  • 中国空间站离地球多远百度指数查询排行榜
  • 建设旅游网站的意义关键词推广优化外包
  • 做网站可以用别人的源码吗江门网站建设模板
  • 海外社交网络推广网站优化最为重要的内容是