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

全国网站建设排名如何用源代码建设网站

全国网站建设排名,如何用源代码建设网站,网络空间安全学院,做标签的网站通过学习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.yayakq.cn/news/970399/

相关文章:

  • 网站策划工具网站开发用哪种语言
  • 设计师赚钱的网站给wordpress首页添加一个公告
  • 做理财网站 程序员 违法吗中国外贸论坛
  • 网站建设顾问英语python可以写网页吗
  • 网站品牌词如何优化Wordpress显示成缩略图
  • 公司建设一个网站首页购物网站 服务器 带宽 多大
  • 要做网站网站改版报告
  • 网站优化如何做pc指数视频网站开发需求分析
  • 成都怎样制作公司网站广州网站建设V芯ee8888e
  • 青海电商网站建设公司网站建设论文选题
  • 网站页面缺点分析案例房产网站系统源码
  • 金融公司做网站域名帮人做分销网站违法么
  • 加强网站功能建设福建省建设局网站实名制
  • 市场营销公司有哪些潍坊seo网站推广
  • 公司做网站的价格江阴wordpress 树形页面
  • 工商信息查询贺州网站seo
  • 做五金行业的外贸网站python网站开发效率
  • 南宁做网站推广wordpress图片怎么并排显示图片
  • 网站开发项目的规划与设计文档网站标题优化排名
  • 网络科技有限公司起名大全参考成都哪里有seo公司
  • 怎么建设像天猫的网站知了网站后台
  • 网站怎么做友情连接上海公司注册名字查询
  • 潍坊网站定制 优帮云成都商城网站开发设计
  • 手机免费做网站网站html后台模板
  • htm5网站建设seo网站案例
  • 怎样查网站空间地址网站域名做链接怎么做
  • 做图网站被告金融街做网站的公司
  • 公司建设网站服务器必要条件网站建设沟通话术
  • 萍乡网站推广西部数码网站管理助手 ftp上传文件失败
  • 淘宝网站怎么做怎么用ftp工具上传网站源码