首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过游戏手册实现mysql_secure_installation?

问如何通过游戏手册实现mysql_secure_installation?
EN

Server Fault用户
提问于 2020-07-24 09:50:28
回答 4查看 13K关注 0票数 6

我使用剧本成功地安装了Apache /Mariadb和PHP。我如何使用ansible来做mysql_secure_installation?

我是Ansible的初学者。我想为MySQL服务器设置一个新的密码,并通过剧本完成所有的安全问题。

EN

回答 4

Server Fault用户

发布于 2020-07-24 12:33:32

一段时间前,我在我的MariaDB安装中自己实现了这一点,在我相信其他人会正确地完成它之前。以下是我执行的步骤:

代码语言:javascript
复制
  # mysql_secure_installation
- name: Update MariaDB root password
  mysql_user: name=root host={{item}} password={{mysql_root_password}}
  with_items:
    - 127.0.0.1
    - ::1
    - localhost

- name: Set ~/.my.cnf file
  template: src=dotmy.cnf.j2 dest=/root/.my.cnf mode=0600

  # mysql_secure_installation
- name: Delete anonymous MySQL user
  mysql_user: name="" host={{item}} state=absent
  with_items:
    - localhost
    - "{{ansible_nodename}}"

  # mysql_secure_installation
- name: Delete Hostname based MySQL user
  mysql_user: name=root host="{{ansible_nodename}}" state=absent

  # mysql_secure_installation
- name: Remove MySQL test database
  mysql_db: name=test state=absent

您必须自己决定如何创建mysql_root_password。

票数 3
EN

Server Fault用户

发布于 2021-03-01 17:18:15

为此,我编写了一个定制的ansible模块:https://github.com/eslam-gomaa/mysql_安全_安装_可抗。

示例

代码语言:javascript
复制
- name: test mysql_secure_installation
  mysql_secure_installation:
    login_password: ''
    new_password: password22
    user: root
    login_host: localhost
    hosts: ['localhost', '127.0.0.1', '::1']
    change_root_password: true
    remove_anonymous_user: true
    disallow_root_login_remotely: true
    remove_test_db: true
  register: mysql_secure
  
# To see detailed output
- debug:
    var: mysql_secure
票数 1
EN

Server Fault用户

发布于 2022-08-03 14:55:25

您可以使用Ansible的期望模块来完成这一任务。下面是一个示例:

代码语言:javascript
复制
- name: secure mariadb
  become: yes
  expect:
    command: mysql_secure_installation
    responses:
      'Enter current password for root': ''
      'Set root password': 'n'
      'Remove anonymous users': 'y'
      'Disallow root login remotely': 'y'
      'Remove test database': 'y'
      'Reload privilege tables now': 'y'
    timeout: 1
  register: secure_mariadb
  failed_when: "'... Failed!' in secure_mariadb.stdout_lines"

请注意:此配置适用于我,但您可能必须根据您的需要调整值!

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1026554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档