惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
罗磊的独立博客
雷峰网
雷峰网
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
爱范儿
爱范儿
B
Blog RSS Feed
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
D
Docker
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
小众软件
小众软件
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
I
InfoQ
S
SegmentFault 最新的问题

博客园 - 北极之光的博客

【转载】解决发版痛点:k8s配置滚动更新pod发版上线时,用户访问系统无感知 Rocky 9最小安装后的初始化 Rocky root远程登录 拒绝访问问题 博文阅读密码验证 - 博客园 Windows和Office激活工具 英特尔台式机CPU功耗规格对比 2024桌面级CPU天梯图性能榜 (更新时间:20241114) 史上最全桌面级CPU天梯图-2024年10月更新(包含13/14代Intel/7000系列锐龙) WordPress手动升级教程 2-12 MySQL字段约束-索引-外键 2-11 mysql-sql语句进阶 2-10-Mysql基本语句和常见数据类型 redis 集群模式原理 Tomcat启动脚本 word设置多级列表样式 Git学习笔记 使用war包完成Jenkins升级 Jenkins设置中文 jenkins用户文档中心 Centos7通过war包部署jenkins(解决tomcat部署jenkins报404错误) CentOS7时间显示不对问题 【自动化运维专题 4】ansible的 playbook 使用及举例
Ansible实战MySQL安装
北极之光的博客 · 2022-08-14 · via 博客园 - 北极之光的博客

先做准备工作,准备一台client,再装备一台master机器。

检查连通性:

  1. [root@ansible-master ~]# ansible mytest -m ping

  2. 10.128.25.175| SUCCESS => {

  3. "ansible_facts": {

  4. "discovered_interpreter_python": "/usr/bin/python"

  5. },

  6. "changed": false,

  7. "ping": "pong"

  8. }

  9. [root@ansible-master ~]#

一.Ansible模块查找使用方法

1.ansible的yum模块查找

yum模块在线文档:https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html

示例:

  1. - name: Install the latest version of Apache

  2. yum:

  3. name: httpd

  4. state: latest

  5. - name: Install a list of packages (suitable replacement for2.11 loop deprecation warning)

  6. yum:

  7. name:

  8. - nginx

  9. - postgresql

  10. - postgresql-server

  11. state: present

  12. - name: Install a list of packages with a list variable

  13. yum:

  14. name: "{{ packages }}"

  15. vars:

  16. packages:

  17. - httpd

  18. - httpd-tools

  19. - name: Remove the Apachepackage

  20. yum:

  21. name: httpd

  22. state: absent

2.ansible systemd服务管理模块

systemd模块在线帮助:https://docs.ansible.com/ansible/latest/collections/ansible/builtin/systemd_module.html

示例:

  1. - name: Make sure a service is running

  2. systemd:

  3. state: started

  4. name: httpd

  5. - name: Stop service cron on debian, if running

  6. systemd:

  7. name: cron

  8. state: stopped

  9. - name: Restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes

  10. systemd:

  11. state: restarted

  12. daemon_reload: yes

  13. name: crond

  14. - name: Reload service httpd, in all cases

  15. systemd:

  16. name: httpd

  17. state: reloaded

  18. - name: Enable service httpd andensure it isnot masked

  19. systemd:

  20. name: httpd

  21. enabled: yes

  22. masked: no

二.安装MySQL到测试机

  1. [root@ansible-master ~]# ansible test -m yum -a "name=mariadb,mariadb-server state=present"

  2. [root@ansible-master ~]#

三.管理测试机的MySQL服务

1.查看服务启动

  1. [root@ansible-master ~]# ansible mytest -m shell -a "ps -ef | grep mysql |grep -v grep"

  2. 10.128.25.175| CHANGED | rc=0>>

  3. mysql 67071010:58? 00:00:00/bin/sh /usr/bin/mysqld_safe --basedir=/usr

  4. mysql 68696707010:58? 00:00:00/usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

2.查看mariadb数据库运行情况

  1. [root@ansible-master ~]# ansible mytest -m systemd -a "name=mariadb state=started"

  2. 10.128.25.175| SUCCESS => {

  3. "ansible_facts": {

  4. "discovered_interpreter_python": "/usr/bin/python"

  5. },

  6. "changed": false,

  7. "name": "mariadb",

  8. "state": "started",

  9. "status": {

  10. "ActiveEnterTimestamp": "日 2020-09-27 10:58:54 CST",

  11. "ActiveEnterTimestampMonotonic": "7928162332",

  12. "ActiveExitTimestampMonotonic": "0",

  13. "ActiveState": "active",

  14. "After": "network.target tmp.mount -.mount systemd-journald.socket syslog.target basic.target system.slice",

  15. "AllowIsolate": "no",

  16. "AssertResult": "yes",

  17. "AssertTimestamp": "日 2020-09-27 10:58:49 CST",

  18. "AssertTimestampMonotonic": "7922958508",

  19. "Before": "shutdown.target",

  20. "BlockIOAccounting": "no",

  21. "BlockIOWeight": "18446744073709551615",

  22. "CPUAccounting": "no",

  23. "CPUQuotaPerSecUSec": "infinity",

  24. "CPUSchedulingPolicy": "0",

  25. "CPUSchedulingPriority": "0",

  26. "CPUSchedulingResetOnFork": "no",

  27. "CPUShares": "18446744073709551615",

  28. "CanIsolate": "no",

  29. "CanReload": "no",

  30. "CanStart": "yes",

  31. "CanStop": "yes",

  32. "CapabilityBoundingSet": "18446744073709551615",

  33. "ConditionResult": "yes",

  34. "ConditionTimestamp": "日 2020-09-27 10:58:49 CST",

  35. "ConditionTimestampMonotonic": "7922958508",

  36. "Conflicts": "shutdown.target",

  37. "ControlGroup": "/system.slice/mariadb.service",

  38. "ControlPID": "0",

  39. "DefaultDependencies": "yes",

  40. "Delegate": "no",

  41. "Description": "MariaDB database server",

  42. "DevicePolicy": "auto",

  43. "ExecMainCode": "0",

  44. "ExecMainExitTimestampMonotonic": "0",

  45. "ExecMainPID": "6707",

  46. "ExecMainStartTimestamp": "日 2020-09-27 10:58:50 CST",

  47. "ExecMainStartTimestampMonotonic": "7924819268",

  48. "ExecMainStatus": "0",

  49. "ExecStart": "{ path=/usr/bin/mysqld_safe ; argv[]=/usr/bin/mysqld_safe --basedir=/usr ; ignore_errors=no ; start_time=[日 2020-09-27 10:58:50 CST] ; stop_time=[n/a] ; pid=6707 ; code=(null) ; status=0/0 }",

  50. "ExecStartPost": "{ path=/usr/libexec/mariadb-wait-ready ; argv[]=/usr/libexec/mariadb-wait-ready $MAINPID ; ignore_errors=no ; start_time=[日 2020-09-27 10:58:50 CST] ; stop_time=[日 2020-09-27 10:58:54 CST] ; pid=6708 ; code=exited ; status=0 }",

  51. "ExecStartPre": "{ path=/usr/libexec/mariadb-prepare-db-dir ; argv[]=/usr/libexec/mariadb-prepare-db-dir %n ; ignore_errors=no ; start_time=[日 2020-09-27 10:58:49 CST] ; stop_time=[日 2020-09-27 10:58:50 CST] ; pid=6624 ; code=exited ; status=0 }",

  52. "FailureAction": "none",

  53. "FileDescriptorStoreMax": "0",

  54. "FragmentPath": "/usr/lib/systemd/system/mariadb.service",

  55. "Group": "mysql",

  56. "GuessMainPID": "yes",

  57. "IOScheduling": "0",

  58. "Id": "mariadb.service",

  59. "IgnoreOnIsolate": "no",

  60. "IgnoreOnSnapshot": "no",

  61. "IgnoreSIGPIPE": "yes",

  62. "InactiveEnterTimestampMonotonic": "0",

  63. "InactiveExitTimestamp": "日 2020-09-27 10:58:49 CST",

  64. "InactiveExitTimestampMonotonic": "7922964930",

  65. "JobTimeoutAction": "none",

  66. "JobTimeoutUSec": "0",

  67. "KillMode": "control-group",

  68. "KillSignal": "15",

  69. "LimitAS": "18446744073709551615",

  70. "LimitCORE": "18446744073709551615",

  71. "LimitCPU": "18446744073709551615",

  72. "LimitDATA": "18446744073709551615",

  73. "LimitFSIZE": "18446744073709551615",

  74. "LimitLOCKS": "18446744073709551615",

  75. "LimitMEMLOCK": "65536",

  76. "LimitMSGQUEUE": "819200",

  77. "LimitNICE": "0",

  78. "LimitNOFILE": "4096",

  79. "LimitNPROC": "7175",

  80. "LimitRSS": "18446744073709551615",

  81. "LimitRTPRIO": "0",

  82. "LimitRTTIME": "18446744073709551615",

  83. "LimitSIGPENDING": "7175",

  84. "LimitSTACK": "18446744073709551615",

  85. "LoadState": "loaded",

  86. "MainPID": "6707",

  87. "MemoryAccounting": "no",

  88. "MemoryCurrent": "18446744073709551615",

  89. "MemoryLimit": "18446744073709551615",

  90. "MountFlags": "0",

  91. "Names": "mariadb.service",

  92. "NeedDaemonReload": "no",

  93. "Nice": "0",

  94. "NoNewPrivileges": "no",

  95. "NonBlocking": "no",

  96. "NotifyAccess": "none",

  97. "OOMScoreAdjust": "0",

  98. "OnFailureJobMode": "replace",

  99. "PermissionsStartOnly": "no",

  100. "PrivateDevices": "no",

  101. "PrivateNetwork": "no",

  102. "PrivateTmp": "yes",

  103. "ProtectHome": "no",

  104. "ProtectSystem": "no",

  105. "RefuseManualStart": "no",

  106. "RefuseManualStop": "no",

  107. "RemainAfterExit": "no",

  108. "Requires": "basic.target -.mount",

  109. "RequiresMountsFor": "/var/tmp",

  110. "Restart": "no",

  111. "RestartUSec": "100ms",

  112. "Result": "success",

  113. "RootDirectoryStartOnly": "no",

  114. "RuntimeDirectoryMode": "0755",

  115. "SameProcessGroup": "no",

  116. "SecureBits": "0",

  117. "SendSIGHUP": "no",

  118. "SendSIGKILL": "yes",

  119. "Slice": "system.slice",

  120. "StandardError": "inherit",

  121. "StandardInput": "null",

  122. "StandardOutput": "journal",

  123. "StartLimitAction": "none",

  124. "StartLimitBurst": "5",

  125. "StartLimitInterval": "10000000",

  126. "StartupBlockIOWeight": "18446744073709551615",

  127. "StartupCPUShares": "18446744073709551615",

  128. "StatusErrno": "0",

  129. "StopWhenUnneeded": "no",

  130. "SubState": "running",

  131. "SyslogLevelPrefix": "yes",

  132. "SyslogPriority": "30",

  133. "SystemCallErrorNumber": "0",

  134. "TTYReset": "no",

  135. "TTYVHangup": "no",

  136. "TTYVTDisallocate": "no",

  137. "TimeoutStartUSec": "5min",

  138. "TimeoutStopUSec": "5min",

  139. "TimerSlackNSec": "50000",

  140. "Transient": "no",

  141. "Type": "simple",

  142. "UMask": "0022",

  143. "UnitFilePreset": "disabled",

  144. "UnitFileState": "disabled",

  145. "User": "mysql",

  146. "Wants": "system.slice",

  147. "WatchdogTimestamp": "日 2020-09-27 10:58:50 CST",

  148. "WatchdogTimestampMonotonic": "7924819302",

  149. "WatchdogUSec": "0"

  150. }

  151. }

停止服务后再查看:

[root@ansible-master ~]# ansible mytest -m shell -a "ps -ef | grep mysql |grep -v grep"
10.128.25.175| FAILED | rc=1>>
non-zero return code
[root@ansible-master ~]#

原文地址:https://mp.weixin.qq.com/s/0WtWBxjppGj3Kf9R6arbhw