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

旅游网站建设模板建立自己的网站平台

旅游网站建设模板,建立自己的网站平台,离我最近的广告牌制作,建设商务网站目的及功能定位上午 ansible是⼀种由Python开发的⾃动化运维⼯具#xff0c;集合了众多运维⼯ 具#xff08;puppet、cfengine、chef、func、fabric#xff09;的优点#xff0c;实现了批量 系统配置、批量程序部署、批量运⾏命令等功能。 1、学习ansible的使用 ansible 主机ip|域名|组…上午 ansible是⼀种由Python开发的⾃动化运维⼯具集合了众多运维⼯ 具puppet、cfengine、chef、func、fabric的优点实现了批量 系统配置、批量程序部署、批量运⾏命令等功能。 1、学习ansible的使用 ansible 主机ip|域名|组名|别名 -m ping|copy... ‘参数’ 1下载ansible软件包 [root1 ~]# yum -y install ansible 2创建ansible组 ansible通过⼀个主机清单功能来实现服务器分组。 Ansible的默认主机清单配置⽂件为/etc/ansible/hosts. [root1 ~]# vim /etc/ansible/hosts [group01]10.0.0.1210.0.0.1310.0.0.14[group02]10.0.0.1210.0.0.13 3执行ansible的ping命令 测试网络连通性 主机12和主机13都进行了免密主机14未进行免密 ssh-keygenssh-copy-id -i 10.0.0.12ssh-copy-id -i 10.0.0.13 [root1 ~]# ansible 10.0.0.12 -m ping10.0.0.12 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong}[root1 ~]# ansible group02 -m ping10.0.0.12 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong}10.0.0.13 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong} # 由于group01中的10.0.0.14主机未做免密操作所以会产生报错[root1 ~]# ansible group01 -m pingThe authenticity of host 10.0.0.14 (10.0.0.14) cant be established.ECDSA key fingerprint is SHA256:/p0PnfBbtW2E/MOWaBziXwCBEnuznbx1DiNgh1qJw.ECDSA key fingerprint is MD5:62:73:f0:9f:e3:b5:f1:d2:d4:73:b3:2e:1b:14:16:d0.Are you sure you want to continue connecting (yes/no)? yes10.0.0.14 | UNREACHABLE! {changed: false, msg: Failed to connect to the host via ssh: Warning: Permanently added 10.0.0.14 (ECDSA) to the list of known hosts.\r\nPermission denied (publickey,gssapi-keyex,gssapi-with-mic,password)., unreachable: true} 4为主机设置ansible别名携带用户和密码 没有做免密登录的服务器可以指定⽤户名与密码 [root1 ~]# vim /etc/ansible/hostsother ansible_ssh_host10.0.0.14 ansible_ssh_port22 ansible_ssh_userroot  ansible_ssh_pass1[group01]10.0.0.1210.0.0.13other[root1 ~]# ansible group01 -m ping10.0.0.13 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong}10.0.0.12 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong}other | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong}[root1 ~]# ansible other -m pingother | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong} 5查看ansible帮助信息 查看所有⽀持的模块 [root1 ~]# ansible-doc -l 如果要查看ping模块的⽤法使⽤下⾯命令其它模块以此类推)# ansible-doc ping 6ansible hostname模块的使用 使用ansiblehostname模块批量修改主机名 注意: 它不能修改/etc/hosts⽂件) 基本格式为: ansible 操作的机器名或组名 -m 模块名 -a 参数 1值1 参数2值2 [root1 ~]# ansible group02 -m hostname -a nameab.li 7练习 不论你用哪种环境免密或者不免密端口是否22请最终将两台被管理机器加入到group1组即可 vim /etc/ansible/hostsweb01 ansible_ssh_host10.0.0.12 ansible_ssh_userroot ansible_ssh_pass1 ansible_ssh_port22 web02 ansible_ssh_host10.0.0.13 ansible_ssh_userroot ansible_ssh_pass1 ansible_ssh_port2222[group1]web01web02 下午 1、ansible介绍 ansible是基于模块⼯作的本身没有批量部署的能⼒。真正具有批量部署的是ansible所运⾏的模块ansible只是提供⼀种框架。 2、ansible file模块的使用 file模块⽤于对⽂件相关的操作(创建, 删除, 软硬链接等) 1创建目录 创建目录[root1 ~]# ansible group02 -m file -a path/tmp/abc/def statedirectory 2创建文件 [root1 ~]# ansible group1 -m file -a path/test/111 statetouch 3递归修改owner,group,mode [root1 ~]# ansible group02 -m file -a path/tmp/abc recurseyes ownerbin groupdaemon mode1777[root2 ~]# ll /tmp/总用量 0drwxrwxrwt. 3 bin daemon 17 8月 16 14:09 abc[root2 ~]# ll /tmp/abc/总用量 0drwxrwxrwt. 2 bin daemon 6 8月 16 14:09 def 4删除⽬录 连同⽬录⾥的所有⽂件) [root1 ~]# ansible group02 -m file -a path/tmp/abc stateabsent 5创建⽂件并指定owner,group,mode等 [root1 ~]# ansible group02 -m file -a path/tmp/aaa statetouch ownerbin groupdaemon mode1777 6创建软链接⽂件 软链接指向硬链接硬链接指向文件 [root1 ~]# ansible group02 -m file -a src/etc/fstab path/tmp/xxx statelink [root2 ~]# ll /tmp/lrwxrwxrwx. 1 root root 10 8月 16 14:30 xxx - /etc/fstab 7创建硬链接⽂件 [root1 ~]# ansible group02 -m file -a src/etc/fstab path/tmp/xxx2 statehard[root2 ~]# ll /tmp/-rw-r--r--. 2 root root 502 7月 23 03:23 xxx2 3、ansible stat模块的使用 stat模块类似linux的stat命令⽤于获取⽂件的状态信息。 获取/etc/fstab⽂件的状态信息 [root1 ~]# ansible group02 -m stat -a path/etc/fstab 4、ansible copy模块的使用 copy模块⽤于对⽂件的远程拷⻉操作如把本地的⽂件拷⻉到远程的机器上) 1拷贝文件 拷⻉mysql文件到10.0.0.12主机上 [root1 ~]# ansible 10.0.0.12 -m copy -a src/root/mysql57.tar.gz dest/root/[root1 ~]# ansible group02 -m copy -a src/etc/fstab dest/tmp/a.txt backupyes ownerbin groupdaemon mode1777 2远程向文件中写入数据 使⽤content参数默认会覆盖原内容 [root1 ~]# ansible group01 -m copy -a contentwo dest~/tst# 注意:ansible中-a后⾯的参数⾥也有引号时记得要单引双引交叉使⽤如果都为双引会出现问题 3force参数的使用是否强制覆盖执行命令 如果⽬标⽂件已经存在则会强制覆盖forceyes 如果⽬标⽂件已经存在则不覆盖forceno [root1 ~]# touch tst[root1 ~]# ansible group02 -m copy -a src./tst dest/root/ forceno[root1 ~]# dd if/dev/zero oftst1 bs100M count1[root1 ~]# ansible group01 -m copy -a src./tst1 dest/root/ forceyes[root1 ~]# ansible group01 -m copy -a contentwo dest~/tst forceno# 不执行写入操作操作无意义 4backup参数控制是否备份⽂件 [root1 ~]# ansible group01 -m copy -a src./tst dest~ backupyes ownerbin groupdaemon mode1777# backupyes表示如果拷⻉的⽂件内容与原内容不⼀样则会备份⼀份将原来的文件修改文件名变成备份文件 5拷贝目录 copy模块拷⻉时要注意拷⻉⽬录后⾯是否带/符号 后⾯不带/符号则表示把整个⽬录拷⻉过去 后⾯带/符号则表示把⽬录⾥的所有⽂件拷⻉过去 [root1 ~]# ansible group01 -m copy -a src/etc/yum.repos.d dest/etc/yum.repos.d/ backupyes[root2 ~]# ls /etc/yum.repos.d/CentOS-Base.repo epel.repo epel-testing.repo hh.repo repo.tar.gz yum.repos.d 5、ansible template模块的使用 与copy模块功能⼏乎⼀样 template模块⾸先使⽤变量渲染jinja2模板⽂件成普通⽂件,然后再复制过去.⽽copy模块不⽀持.(jinja2是⼀个基于python的模板引擎) ansible.builtin.template module – Template a file out to a target host — Ansible Community Documentation ansible -m template group01 -a src/etc/hosts dest/tmp/hosts template模块不能拷⻉⽬录 ansible -m template group01 -a src/etc/yum.repos.d/ dest/etc/yum.repos.d/ 6、ansible fatch模块的使用 fetch模块与copy模块类似但作⽤相反。⽤于把远程机器的⽂件拷⻉到本地收文件。 注意: fetch模块不能从远程拷⻉⽬录到本地 [root1 ~]# ansible group01 -m fetch -a src/etc/sysconfig/network-scripts/ifcfg-ens33 dest/tmp# 因为group01⾥有3台机器,为了避免同名⽂件⽂件冲突它使⽤了不同的⽬录)[root1 ~]# tree /tmp//tmp/├── 10.0.0.12│   └── etc│       └── sysconfig│           └── network-scripts│               └── ifcfg-ens33├── 10.0.0.13│   └── etc│       └── sysconfig│           └── network-scripts│               └── ifcfg-ens33├── other│   └── etc│       └── sysconfig│           └── network-scripts│               └── ifcfg-ens33​ 7、ansible user模块的使用 user模块⽤于管理⽤户账号和⽤户属性。 1创建普通用户 [root1 ~]# ansible group02 -m user -a nameaaa statepresent 2创建系统用户并设置shell环境为/sbin/nologin [root1 ~]# ansible group01 -m user -a namemysql statepresent systemyes shell/sbin/nologin 3创建mysql账户并指定uid和密码 # 创建mysql家目录[root1 ~]# ansible group01 -m file -a path/usr/local/mysql statedirectory# 创建mysql-files目录并修改文件的权限和所属主与组[root1 ~]# ansible group01 -m file -a path/usr/local/mysql/mysql-files statedirectory ownermysql groupmysql mode750 [root1 ~]# ansible group01 -m user -a nameabc statepresent uid1999 passwordabc 生成加密密码 [root1 ~]# echo 123456 | openssl passwd -1 -stdin$1$YxSnSopH$0t2l5RUA4m9JKlmjVZbta. 4创建普通用户,并产⽣空密码密钥对 [root1 ~]# ansible group01 -m user -a namehadoop generate_ssh_keyyes 5删除用户默认不删除家目录 [root1 ~]# ansible group01 -m user -a namehadoop stateabsent[root2 ~]# ll /home/总用量 0drwx------. 2 aaa   aaa   62 8月  16 16:03 aaadrwx------. 2 abc   abc   62 8月  16 16:14 abcdrwx------. 3  2000  2000 74 8月  16 16:20 hadoopdrwx------. 2 mysql mysql 62 8月  16 16:06 mysql 7删除用户的同时删除家目录 使⽤removeyes参数 [root1 ~]# ansible group01 -m user -a nameaaa stateabsent removeyes 8、ansible group模块的使用 group模块⽤于管理⽤户组和⽤户组属性。 1创建组 ansible group01 -m group -a namegroupa gid3000 statepresent 2删除组 如果有⽤户的gid为此组则删除不了 ansible group01 -m group -a namegroupa stateabsent 9、ansible cron模块的使用 cron模块⽤于管理周期性时间任务 创建⼀个cron任务,不指定user的话,默认就是root因为这⾥是⽤root用户操作的)。 如果minute,hour,day,month,week不指定的话默认都为* 1添加计划任务 [root1 ~]# ansible group01 -m cron -a nameabc userroot job/usr/sbin/ntpdate cn.ntp.org.cn hour2 2删除cron任务 [root1 ~]# ansible group01 -m cron -a nameabc stateabsent 10、ansible yum_repository模块的使用 yum_repository模块⽤于配置yum仓库。 1增加⼀个/etc/yum.repos.d/local.repo配置⽂件 注意此模块只帮助配置yum仓库,但如果仓库⾥没有软件包安装⼀ 样会失败。 所以可以⼿动去挂载光驱到/mnt⽬录 mount /dev/cdrom /mnt ansible group01 -m yum_repository -a namelocal descriptionlocalyum baseurlfile:///mnt/ enabledyes gpgcheckno 2删除/etc/yum.repos.d/local.repo配置⽂件 ansible group01 -m yum_repository -a namelocal stateabsent 11、ansible yum模块的使用 yum模块⽤于使⽤yum命令来实现软件包的安装与卸载。 1安装软件 [root1 ~]# ansible group01 -m yum -a namentpdate statepresent statelatest表示安装最新版本 ansible group01 -m yum -a namehttpd,httpddevel statelatest 2卸载软件 ansible group1 -m yum -a namehttpd,httpddevel stateabsent 12、ansible service模块的使用 service模块⽤于控制服务的启动,关闭,开机⾃启动等。 1启动服务 # 启动vsftpd服务并设为开机⾃动启动ansible group01 -m service -a namevsftpd statestarted enabledon 2关闭服务 # 关闭filewalld服务并设为开机不⾃动启动[root1 ~]# ansible group01 -m service -a namefirewalld statestopped enabledfalse 13、ansible script模块的使用 script模块⽤于在远程机器上执⾏本地脚本。 此脚本不⽤给执⾏权限) [root1 ~]# vim /tmp/1.sh[root1 ~]# ansible group01 -m script -a /tmp/1.sh 练习使⽤shell脚本实现在group01的被管理机⾥的mariadb⾥创建⼀ 个abc库 [root1 ~]# vim /tmp/2.sh#!/bin/bashyum install mariadb-server -y   /dev/nullsystemctl start mariadbsystemctl enable mariadbmysql EOFcreate database abc;quitEOF[root1 ~]# ansible group01 -m script -a /tmp/2.sh 14、ansible command模块与shell模块的使用 两个模块都是⽤于执⾏linux命令的,这对于命令熟悉的⼯程师来说⽤起来⾮常high。 shell模块与command模块差不多command模块不能执⾏⼀些类似 $HOME,,,|等符号但shell可以) 1使用command模块创建用户 [root1 ~]# ansible group01 -m command -a useradd user1[root1 ~]# ansible group01 -m command -a id user110.0.0.13 | CHANGED | rc0 uid2000(user1) gid2000(user1) 组2000(user1)10.0.0.12 | CHANGED | rc0 uid2000(user1) gid2000(user1) 组2000(user1)other | CHANGED | rc0 uid2000(user1) gid2000(user1) 组2000(user1) 2使用shell模块使用管道符进行统计查询信息 [root1 ~]# ansible group01 -m shell -a cat /etc/passwd | wc -l10.0.0.13 | CHANGED | rc0 2210.0.0.12 | CHANGED | rc0 22other | CHANGED | rc0 22 3使用shell模块使用$HOME变量 [root1 ~]# ansible -m shell  group01 -a cd $HOME;pwd10.0.0.13 | CHANGED | rc0 /rootother | CHANGED | rc0 /root10.0.0.12 | CHANGED | rc0 /root 4使用command模块进行关机 [root1 ~]# ansible group01 -m command -a shutdown -h 010.0.0.12 | FAILED | rc-1 Failed to connect to the host via ssh: ssh: connect to host 10.0.0.12 port 22: Connection refusedother | FAILED | rc-1 Failed to connect to the host via ssh: ssh_exchange_identification: read: Connection reset by peer10.0.0.13 | CHANGED | rc0 Shutdown scheduled for 五 2024-08-16 16:49:28 CST, use shutdown -c to cancel. 注意: shell模块并不是百分之百任何命令都可以,⽐如vim或ll别名就不可以。
http://www.dnsts.com.cn/news/134537.html

相关文章:

  • 做动图的网站知乎jquery 炫酷网站
  • wordpress用那个采集器网站优化关键词公司
  • 网站模板 收费东莞企业如何建网站
  • 手机网站一键导航代码启信宝企业查询
  • 在机关网站建设会上讲话河源哪里做网站
  • 北京网站优化效果北京网站建设+知乎
  • 做网站 万户百度大数据查询怎么用
  • 驻马店网站建设熊掌号烟台网站设计公司推荐
  • 湛江做网站优化上海网站建设yes404
  • 先做网站后备案吗页面设置怎么设置
  • 印刷电商网站开发家庭办厂10万左右项目
  • 山东城建设计院网站房产资讯最新消息
  • 公司网站费用如何做网站内容
  • 东莞计算机培训机构哪个最好seo搜索引擎优化推荐
  • 建设学校网站前的需求分析报告外贸网站制作时间及费用
  • 电信网站备案管理系统自己电脑做服务器搭网站
  • 佛山哪有网站建设公司有什么做门窗展厅的设计网站
  • 怎么在网站上做游戏代练上海跨境电商网站制作
  • 台州电子商务网站开发搜索引擎优化包括( )方面的优化
  • 无锡企业建站浙江华企做的网站怎么样
  • 在线设计装修的网站招聘网哪个平台比较好招人
  • 网站登录模板 html魔贝课凡seo课程好吗
  • 广州越秀建网站的公司移动互联网的应用举例
  • 做网站常熟小说网站开发思路
  • 北京网站高端建设建设部网站 合同格式
  • 网站建设仟首先金手指13辽宁平台网站建设平台
  • 做网站市场大不大深圳市罗湖网站建设
  • 东莞网站建设是什么意思建设网站的目标和作用
  • 西安定制网站北京seo优化网站建设
  • 源码建站教程销售网站开发意义