root 1848214 0.0 0.1 1298368 7488 ? Ssl 5月20 1:11 ./bin/redis-server *:6380
Note:
-
如果不指定模块,则默认采用
command
模块; -
基础的
Linux
命令,都可以通过command
与shell
模块执行,区别在于command
模块不支持管道命令。
管理安装包
安装当前最新的Apache软件
[root@ecs-kunpeng-0001 ~]# ansible cache -m yum -a “name=httpd state=latest”
192.168.0.166 | SUCCESS => {
“ansible_facts”: {
“pkg_mgr”: “dnf”
},
“changed”: false,
“msg”: “Nothing to do”,
“rc”: 0,
“results”: []
}
通过公网URL安装rpm软件
[root@ecs-kunpeng-0001 ~]# ansible cache -m yum -a “name=https://mirrors.huaweicloud.com/openeuler/openEuler-20.03-LTS/everything/aarch64/Packages/httpd-2.4.34-15.oe1.aarch64.rpm state=latest”
通过本地包安装rpm软件
[root@ecs-kunpeng-0001 ~]# ansible cache -m yum -a “name=/tmp/package.rpm state=present”
卸载删除httpd软件
[root@ecs-kunpeng-0001 ~]# ansible cache -m yum -a “name=httpd state=absent”
管理文件
file copy get_url
- file:创建文件、目录,授权模块
创建文件,并设定属主、属组、权限
[root@ecs-kunpeng-0001 ~]# ansible cache -m file -a “path=/var/www/html/index.html state=touch owner=apache group=apache mode=644”
192.168.0.166 | CHANGED => {
“changed”: true,
“dest”: “/var/www/html/index.html”,
“gid”: 48,
“group”: “apache”,
“mode”: “0644”,
“owner”: “apache”,
“size”: 0,
“state”: “file”,
“uid”: 48
}
创建目录,并设定属主、属组、权限
[root@ecs-kunpeng-0001 ~]# ansible cache -m file -a “path=/var/www/html/dir state=directory owner=apache group=apache mode=755”
192.168.0.166 | CHANGED => {
“changed”: true,
“gid”: 48,
“group”: “apache”,
“mode”: “0755”,
“owner”: “apache”,
“path”: “/var/www/html/dir”,
“size”: 4096,
“state”: “directory”,
“uid”: 48
}
通过shell模块验证下是否创建了文件与目录
[root@ecs-kunpeng-0001 ~]# ansible cache -m shell -a “ls -l /var/www/html”
192.168.0.166 | CHANGED | rc=0 >>
总用量 4
drwxr-xr-x 2 apache apache 4096 5月 21 22:20 dir
-rw-r–r-- 1 apache apache 0 5月 21 22:17 index.html
- copy:文件传输模块
将本地的file.txt文件推送到远端服务
[root@ecs-kunpeng-0001 ~]# ansible cache -m copy -a “src=./file.txt dest=/var/www/html/file.txt owner=root group=root mode=644”
192.168.0.166 | CHANGED => {
“changed”: true,
“checksum”: “d4d55684a3d4d6a3c31c36f788f01f30d0d22d02”,
“dest”: “/var/www/html/file.txt”,
“gid”: 0,
“group”: “root”,
“md5sum”: “1ae9367e28d7d3173e93a92d09e76708”,
“mode”: “0644”,
“owner”: “root”,
“size”: 25,
“src”: “/root/.ansible/tmp/ansible-tmp-1621607368.0554242-3109318-111286480082069/source”,
“state”: “file”,
“uid”: 0
}
往远程的主机文件中写入内容
[root@ecs-kunpeng-0001 ~]# ansible cache -m copy -a “content=writesomething… dest=/var/www/html/file.txt”
192.168.0.166 | CHANGED => {
“changed”: true,
“checksum”: “dd3c25def1f5204fd618a0a3346b68feac393c1e”,
“dest”: “/var/www/html/file.txt”,
“gid”: 0,
“group”: “root”,
“md5sum”: “b30d3b6c1a4327a291e271d7e502247e”,
“mode”: “0644”,
“owner”: “root”,
“size”: 16,
“src”: “/root/.ansible/tmp/ansible-tmp-1621607386.0447457-3110984-150399809437238/source”,
“state”: “file”,
“uid”: 0
}
通过shell模块验证下是否创建了文件与目录
[root@ecs-kunpeng-0001 ~]# ansible cache -m shell -a “cat /var/www/html/file.txt”
192.168.0.166 | CHANGED | rc=0 >>
writesomething…
- get_url:下载文件模块
下载互联网的软件至本地,url支持http, https, ftp,这里以之前中招的挖矿病毒脚本为例测试下载
[root@ecs-kunpeng-0001 ~]# ansible cache -m get_url -a “url=http://45.9.148.37/cf67356a3333e6999999999/init.sh dest=/var/www/html/”
192.168.0.166 | CHANGED => {
“changed”: true,
“checksum_dest”: null,
“checksum_src”: “1bf6b644228a468e6f90643d7a5efdd447dd169d”,
“dest”: “/var/www/html/init.sh”,
“elapsed”: 0,
“gid”: 0,
“group”: “root”,
“md5sum”: “179fd51fe6b061e8b54b0f3ca2e8bd26”,
“mode”: “0600”,
“msg”: “OK (37907 bytes)”,
“owner”: “root”,
“size”: 37907,
“src”: “/root/.ansible/tmp/ansible-tmp-1621607722.632395-3141898-83452532208350/tmpbt07hddb”,
“state”: “file”,
“status_code”: 200,
“uid”: 0,
“url”: “http://45.9.148.37/cf67356a3333e6999999999/init.sh”
}
验证是否下载成功init.sh
[root@ecs-kunpeng-0001 ~]# ansible cache -m shell -a “ls -l /var/www/html”
192.168.0.166 | CHANGED | rc=0 >>
总用量 48
drwxr-xr-x 2 apache apache 4096 5月 21 22:20 dir
-rw-r–r-- 1 root root 16 5月 21 22:29 file.txt
-rw-r–r-- 1 apache apache 0 5月 21 22:17 index.html
-rw------- 1 root root 37907 5月 21 22:35 init.sh
使用默认命令模块删除文件时,有个警告,并建议使用file模块来操作文件的删除。
[root@ecs-kunpeng-0001 ~]# ansible cache -a “rm /var/www/html/init.sh”
[WARNING]: Consider using the file module with state=absent rather than running ‘rm’. If you
need to use command because file is insufficient you can add ‘warn: false’ to this command
task or set ‘command_warnings=False’ in ansible.cfg to get rid of this message.
192.168.0.166 | CHANGED | rc=0 >>
使用file模块删除文件
[root@ecs-kunpeng-0001 ~]# ansible cache -m file -a “path=/var/www/html/file.txt state=absent”
192.168.0.166 | CHANGED => {
“changed”: true,
“path”: “/var/www/html/file.txt”,
“state”: “absent”
}
验证是否已经删除了init.sh以及file.txt
[root@ecs-kunpeng-0001 ~]# ansible cache -m shell -a “ls -l /var/www/html”
192.168.0.166 | CHANGED | rc=0 >>
总用量 4
drwxr-xr-x 2 apache apache 4096 5月 21 22:20 dir
-rw-r–r-- 1 apache apache 0 5月 21 22:17 index.html
管理服务
启动httpd服务
[root@ecs-kunpeng-0001 ~]# ansible cache -m service -a “name=httpd state=started”
192.168.0.166 | CHANGED => {
“changed”: true,
“name”: “httpd”,
“state”: “started”,
“status”: {
“ActiveEnterTimestampMonotonic”: “0”,
“ActiveExitTimestampMonotonic”: “0”,
…
停止httpd服务
[root@ecs-kunpeng-0001 ~]# ansible cache -m service -a “name=httpd state=stopped”
重启httpd服务
[root@ecs-kunpeng-0001 ~]# ansible cache -m service -a “name=httpd state=restarted”
启动httpd服务,并加入开机自启
[root@ecs-kunpeng-0001 ~]# ansible cache -m service -a “name=httpd state=started enabled=yes”
管理用户
- group: 分组模块
创建grpone基本组,指定uid为1234
[root@ecs-kunpeng-0001 ~]# ansible cache -m group -a “name=grpone gid=1234 state=present”
192.168.0.166 | CHANGED => {
“changed”: true,
“gid”: 1234,
“name”: “grpone”,
“state”: “present”,
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
最后
还有Java核心知识点+全套架构师学习资料和视频+一线大厂面试宝典+面试简历模板可以领取+阿里美团网易腾讯小米爱奇艺快手哔哩哔哩面试题+Spring源码合集+Java架构实战电子书+2021年最新大厂面试题。
xR-1711729658997)]
[外链图片转存中…(img-s2gcvOoF-1711729658998)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-48ruaK7i-1711729658998)]
最后
还有Java核心知识点+全套架构师学习资料和视频+一线大厂面试宝典+面试简历模板可以领取+阿里美团网易腾讯小米爱奇艺快手哔哩哔哩面试题+Spring源码合集+Java架构实战电子书+2021年最新大厂面试题。
[外链图片转存中…(img-iaX87wva-1711729658999)]