打造网站品牌,游戏代理平台免费,装修公司线上推广方式,织梦做的网站能做seo吗目录
(一)练习一
1.新建一个role——app
2.创建文件
3.删除之前安装的httpd服务和apache用户
4.准备tasks任务
(1)创建组group.yml
(2)创建用户user.yml
(3)安装程序yum.yml
(4)修改模板httpd.conf.j2
(5)编写templ.yml
(6)编写start.yml
(7)编写copyfile.yml
(8…目录
(一)练习一
1.新建一个role——app
2.创建文件
3.删除之前安装的httpd服务和apache用户
4.准备tasks任务
(1)创建组group.yml
(2)创建用户user.yml
(3)安装程序yum.yml
(4)修改模板httpd.conf.j2
(5)编写templ.yml
(6)编写start.yml
(7)编写copyfile.yml
(8)定义顺序main.yml
5.准备变量文件vars
(1)编写变量脚本——main.yml
6.准备触发器handlers
(1)编写脚本main.yml
7.编写playbook脚本调度任务
8.角色app目录结构
9.执行脚本
10.检查结果
(二)练习二——使用运算符//设置缓存大小
1.准备工作
2.修改node141机器的内存
(1)node141现在的内存
(2)修改node141的内存
(3)修改node141后内存
(4)查看node142的内存
3.编辑配置文件
4.准备tasks任务
(1)编写yum.yml
(2)编写start.yml
(3)编写templ.yml
(4)编写main.yml
5.角色memcached目录结构
6.编写playbook脚本
7.检查并执行playbook脚本
8.脚本执行结果
(三)推荐资料 (一)练习一
1.新建一个role——app
[rootansible145 ansible]# cd roles/[rootansible145 roles]# rm -rf app/[rootansible145 roles]# mkdir app[rootansible145 roles]# cd app/2.创建文件
[rootansible145 app]# mkdir tasks templates vars handlers files[rootansible145 app]# tree
.
├── files
├── handlers
├── tasks
├── templates
└── vars5 directories, 0 files
3.删除之前安装的httpd服务和apache用户
ansible all -m shell -a rm -rf /data/*ansible all -m shell -a userdel -r apacheansible all -m shell -a yum -y remove httpdansible all -m shell -a rpm -q httpd
4.准备tasks任务
(1)创建组group.yml
- name: create groupgroup: nameapp systemyes gid123
(2)创建用户user.yml
- name: create useruser: nameapp systemyes shell/sbin/nologin uid123
(3)安装程序yum.yml
- name: install packageyum: namehttpd
(4)修改模板httpd.conf.j2
[rootansible145 tasks]# cp /etc/httpd/conf/httpd.conf ../templates/httpd.conf.j2[rootansible145 tasks]# vim ../templates/httpd.conf.j241 #Listen 12.34.56.78:80
42 Listen {{ ansible_processor_vcpus*10 }}
43 #
44 # Dynamic Shared Object (DSO) Support64 #
65 User {{ username }}
66 Group {{ groupname }}
67
68 # Main server configuration
(5)编写templ.yml
- name: copy conftemplate: srchttpd.conf.j2 dest/etc/httpd/conf/httpd.confnotify: restart service(6)编写start.yml
- name: start serviceservice: namehttpd statestarted enabledyes
(7)编写copyfile.yml
- name: copy confcopy: srcvhosts.conf dest/etc/httpd/conf.d/ ownerapp(8)定义顺序main.yml
- include: group.yml
- include: user.yml
- include: yum.yml
- include: templ.yml
- include: copyfile.yml
- include: start.yml
5.准备变量文件vars
(1)编写变量脚本——main.yml
[rootansible145 vars]# vim main.ymlusername: app
groupname: app6.准备触发器handlers
(1)编写脚本main.yml
[rootansible145 app]# vim handlers/main.yml- name: restart serviceservice: namehttpd staterestarted
7.编写playbook脚本调度任务
[rootansible145 ansible]# vim app_role.yml- hosts: websrvsremote_user: rootroles:- app8.角色app目录结构 9.执行脚本
[rootansible145 ansible]# ansible-playbook app_role.yml
10.检查结果
[rootnode141 ~]# ss -ntl
users:((httpd,pid10792,fd4),(httpd,pid10791,fd4),(httpd,pid10790,fd4),(httpd,pid10789,fd4),(httpd,pid10788,fd4),(httpd,pid10787,fd4))[rootnode141 ~]# getent passwd app
app:x:123:100::/home/app:/sbin/nologin[rootnode141 ~]# getent group app
app:x:123:[rootnode141 ~]# ps aux | grep app
app 10788 0.0 0.1 221948 2968 ? S 12:01 0:00 /usr/sbin/httpd -DFOREGROUND
app 10789 0.0 0.1 221948 2968 ? S 12:01 0:00 /usr/sbin/httpd -DFOREGROUND
app 10790 0.0 0.1 221948 2968 ? S 12:01 0:00 /usr/sbin/httpd -DFOREGROUND
app 10791 0.0 0.1 221948 2968 ? S 12:01 0:00 /usr/sbin/httpd -DFOREGROUND
app 10792 0.0 0.1 221948 2968 ? S 12:01 0:00 /usr/sbin/httpd -DFOREGROUND
root 10850 0.0 0.0 112660 964 pts/1 S 12:08 0:00 grep --colorauto app(二)练习二——使用运算符//设置缓存大小
要求每台被控机memcached的缓存空间为物理内存的1/4
1.准备工作
[rootansible145 roles]# cd memcached/[rootansible145 memcached]# mkdir tasks templates[rootansible145 memcached]# yum install -y memcached[rootansible145 memcached]# cat /etc/sysconfig/memcached
PORT11211
USERmemcached
MAXCONN1024
CACHESIZE64
OPTIONS2.修改node141机器的内存
(1)node141现在的内存 (2)修改node141的内存 (3)修改node141后内存 (4)查看node142的内存 3.编辑配置文件
[rootansible145 memcached]# cp /etc/sysconfig/memcached templates/memcached.j2[rootansible145 memcached]# vim templates/memcached.j2 PORT11211
USERmemcached
MAXCONN1024
CACHESIZE{{ ansible_memtotal_mb//4 }}
OPTIONS4.准备tasks任务
(1)编写yum.yml
- name: install packageyum: namememcached
(2)编写start.yml
- name: start serviceservice: namememcached statestarted enabledyes
(3)编写templ.yml
- name: copy conftemplate: srcmemcached.j2 dest/etc/sysconfig/memcached(4)编写main.yml
- include: yum.yml
- include: templ.yml
- include: start.yml
5.角色memcached目录结构 6.编写playbook脚本
[rootansible145 ansible]# vim memcached_role.yml- hosts: websrvsremote_user: rootroles:- memcached7.检查并执行playbook脚本
[rootansible145 ansible]# ansible-playbook -C memcached_role.yml[rootansible145 ansible]# ansible-playbook memcached_role.yml
8.脚本执行结果 (三)推荐资料 http://galaxy.ansible.comhttps://galaxy.ansible.com/explore#/http://github.com/http://ansible.com.cn/https://github.com/ansible/ansiblehttps://github.com/ansible/ansible-examples