这期内容当中小编将会给大家带来有关如何理解ansible自动化运维数据库,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
通过ansible简单对数据库主机检查和数据库表空间的检查,前提数据库主机有统一的用户名和密码.
运维环境: rhel 7.2, ansible 1.9
数据库环境:Oracle 11.2.0.4, Suse 11sp4,统一用户是Oracle和usercs
ansible配置文件/etc/ansible/ansible.cfg,否则在运行ansible时需要制定host位置
--配置host组
[root@DBAMONITOR usercs]# more /ansible/hosts
[Suse]
192.168.15.21
192.168.15.22
192.168.15.46
192.168.15.47
--简单测试
[root@DBAMONITOR .ssh]# ansible Suse -m ping -u usercs -k
SSH password:
192.168.15.22 | success >> {
"changed": false,
"ping": "pong"
}
192.168.15.46 | success >> {
"changed": false,
"ping": "pong"
}
192.168.15.47 | success >> {
"changed": false,
"ping": "pong"
}
192.168.15.21 | success >> {
"changed": false,
"ping": "pong"
}
--查看空间
[root@DBAMONITOR .ssh]# ansible Suse -m command -a "df -hT" -u usercs -k
password:
[root@DBAMONITOR .ssh]# ansible Suse -m command -a "ls -l /tmp" -u usercs -k
password:
--复制文件:
[root@DBAMONITOR .ssh]# ansible Suse -m copy -a "src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg" -u usercs -k
password:
{"src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=usercs group=usercs mode=0644" }
--远程执行脚本
ansible Suse -m shell -a "/tmp/rocketzhang_test.sh"
password:
--远程创建目录
ansible Suse -m command -a "mkdir /home/oracle/scripts" -u oracle -k
password:
--配置脚本
source ~/.profile
sqlplus -S "/as sysdba"<<EOF
set lin 200 pages 100
select current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from gv\$database;
set pagesize 9999
set linesize 132
select
a.tablespace_name,
a.Total_mb,
f.Free_mb,
round(a.total_MB-f.free_mb,2) Used_mb,
round((f.free_MB/a.total_MB)*100) "%_Free"
from
(select tablespace_name, sum(bytes/(1024*1024)) total_MB from dba_data_files group by tablespace_name) a,
(select tablespace_name, round(sum(bytes/(1024*1024))) free_MB from dba_free_space group by tablespace_name) f
WHERE a.tablespace_name = f.tablespace_name(+)
order by "%_Free"
/
exit
EOF
--拷贝文件
ansible Suse -m copy -a "src=/ansible/check_db.sh dest=/home/oracle/scripts" -u oracle -k
password:
--执行脚本
ansible Suse -m command -a "chmod +x /home/oracle/scripts/check_db.sh" -u oracle -k
password:
ansible Suse -m shell -a "/home/oracle/scripts/check_db.sh" -u oracle -k
password:
上述就是小编为大家分享的如何理解ansible自动化运维数据库了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。