当前位置: 首页 > 软件库 > 数据库相关 > >

ansible-role-mysql

Ansible Role - MySQL
授权协议 MIT License
开发语言 C/C++
所属分类 数据库相关
软件类型 开源软件
地区 不详
投 递 者 蒯胜泫
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Ansible Role: MySQL

CI

Installs and configures MySQL or MariaDB server on RHEL/CentOS or Debian/Ubuntu servers.

Requirements

No special requirements; note that this role requires root access, so either run it in a playbook with a global become: yes, or invoke the role in your playbook like:

- hosts: database
  roles:
    - role: geerlingguy.mysql
      become: yes

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

mysql_user_home: /root
mysql_user_name: root
mysql_user_password: root

The home directory inside which Python MySQL settings will be stored, which Ansible will use when connecting to MySQL. This should be the home directory of the user which runs this Ansible role. The mysql_user_name and mysql_user_password can be set if you are running this role under a non-root user account and want to set a non-root user.

mysql_root_home: /root
mysql_root_username: root
mysql_root_password: root

The MySQL root user account details.

mysql_root_password_update: false

Whether to force update the MySQL root user's password. By default, this role will only change the root user's password when MySQL is first configured. You can force an update by setting this to yes.

Note: If you get an error like ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) after a failed or interrupted playbook run, this usually means the root password wasn't originally updated to begin with. Try either removing the .my.cnf file inside the configured mysql_user_home or updating it and setting password='' (the insecure default password). Run the playbook again, with mysql_root_password_update set to yes, and the setup should complete.

Note: If you get an error like ERROR 1698 (28000): Access denied for user 'root'@'localhost' (using password: YES) when trying to log in from the CLI you might need to run as root or sudoer.

mysql_enabled_on_startup: true

Whether MySQL should be enabled on startup.

mysql_config_file: *default value depends on OS*
mysql_config_include_dir: *default value depends on OS*

The main my.cnf configuration file and include directory.

overwrite_global_mycnf: true

Whether the global my.cnf should be overwritten each time this role is run. Setting this to no tells Ansible to only create the my.cnf file if it doesn't exist. This should be left at its default value (yes) if you'd like to use this role's variables to configure MySQL.

mysql_config_include_files: []

A list of files that should override the default global my.cnf. Each item in the array requires a "src" parameter which is a path to a file. An optional "force" parameter can force the file to be updated each time ansible runs.

mysql_databases: []

The MySQL databases to create. A database has the values name, encoding (defaults to utf8), collation (defaults to utf8_general_ci) and replicate (defaults to 1, only used if replication is configured). The formats of these are the same as in the mysql_db module.

You can also delete a database (or ensure it's not on the server) by setting state to absent (defaults to present).

mysql_users: []

The MySQL users and their privileges. A user has the values:

  • name
  • host (defaults to localhost)
  • password (can be plaintext or encrypted—if encrypted, set encrypted: yes)
  • encrypted (defaults to no)
  • priv (defaults to *.*:USAGE)
  • append_privs (defaults to no)
  • state (defaults to present)

The formats of these are the same as in the mysql_user module.

mysql_packages:
  - mysql
  - mysql-server

(OS-specific, RedHat/CentOS defaults listed here) Packages to be installed. In some situations, you may need to add additional packages, like mysql-devel.

mysql_enablerepo: ""

(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. remi,epel). This can be handy, as an example, if you want to install later versions of MySQL.

mysql_python_package_debian: python3-mysqldb

(Ubuntu/Debian only) If you need to explicitly override the MySQL Python package, you can set it here. Set this to python-mysqldb if using older distributions running Python 2.

mysql_port: "3306"
mysql_bind_address: '0.0.0.0'
mysql_datadir: /var/lib/mysql
mysql_socket: *default value depends on OS*
mysql_pid_file: *default value depends on OS*

Default MySQL connection configuration.

mysql_log_file_group: mysql *adm on Debian*
mysql_log: ""
mysql_log_error: *default value depends on OS*
mysql_syslog_tag: *default value depends on OS*

MySQL logging configuration. Setting mysql_log (the general query log) or mysql_log_error to syslog will make MySQL log to syslog using the mysql_syslog_tag.

mysql_slow_query_log_enabled: false
mysql_slow_query_log_file: *default value depends on OS*
mysql_slow_query_time: 2

Slow query log settings. Note that the log file will be created by this role, but if you're running on a server with SELinux or AppArmor, you may need to add this path to the allowed paths for MySQL, or disable the mysql profile. For example, on Debian/Ubuntu, you can run sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/usr.sbin.mysqld && sudo service apparmor restart.

mysql_key_buffer_size: "256M"
mysql_max_allowed_packet: "64M"
mysql_table_open_cache: "256"
[...]

The rest of the settings in defaults/main.yml control MySQL's memory usage and some other common settings. The default values are tuned for a server where MySQL can consume ~512 MB RAM, so you should consider adjusting them to suit your particular server better.

mysql_server_id: "1"
mysql_max_binlog_size: "100M"
mysql_binlog_format: "ROW"
mysql_expire_logs_days: "10"
mysql_replication_role: ''
mysql_replication_master: ''
mysql_replication_user: {}

Replication settings. Set mysql_server_id and mysql_replication_role by server (e.g. the master would be ID 1, with the mysql_replication_role of master, and the slave would be ID 2, with the mysql_replication_role of slave). The mysql_replication_user uses the same keys as individual list items in mysql_users, and is created on master servers, and used to replicate on all the slaves.

mysql_replication_master needs to resolve to an IP or a hostname which is accessable to the Slaves (this could be a /etc/hosts injection or some other means), otherwise the slaves cannot communicate to the master.

Later versions of MySQL on CentOS 7

If you want to install MySQL from the official repository instead of installing the system default MariaDB equivalents, you can add the following pre_tasks task in your playbook:

pre_tasks:
    - name: Install the MySQL repo.
      yum:
        name: http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
        state: present
      when: ansible_os_family == "RedHat"
  
    - name: Override variables for MySQL (RedHat).
      set_fact:
        mysql_daemon: mysqld
        mysql_packages: ['mysql-server']
        mysql_log_error: /var/log/mysqld.err
        mysql_syslog_tag: mysqld
        mysql_pid_file: /var/run/mysqld/mysqld.pid
        mysql_socket: /var/lib/mysql/mysql.sock
      when: ansible_os_family == "RedHat"

MariaDB usage

This role works with either MySQL or a compatible version of MariaDB. On RHEL/CentOS 7+, the mariadb database engine was substituted as the default MySQL replacement package. No modifications are necessary though all of the variables still reference 'mysql' instead of mariadb.

Ubuntu 14.04 and 16.04 MariaDB configuration

On Ubuntu, the package names are named differently, so the mysql_package variable needs to be altered. Set the following variables (at a minimum):

mysql_packages:
  - mariadb-client
  - mariadb-server
  - python-mysqldb

Dependencies

None.

Example Playbook

- hosts: db-servers
  become: yes
  vars_files:
    - vars/main.yml
  roles:
    - { role: geerlingguy.mysql }

Inside vars/main.yml:

mysql_root_password: super-secure-password
mysql_databases:
  - name: example_db
    encoding: latin1
    collation: latin1_general_ci
mysql_users:
  - name: example_user
    host: "%"
    password: similarly-secure-password
    priv: "example_db.*:ALL"

License

MIT / BSD

Author Information

This role was created in 2014 by Jeff Geerling, author of Ansible for DevOps.

  • ansible-playbook部署mysql主从 设置主机清单 [root@server ansible]# vim hosts [mysql] node2 node3 [mysql_master] node2 [mysqk_slave] node3 创建角色 [root@server ansible]# cd roles/ [root@server roles]# ansible-g

  • ansible写roles的时候tasks里面需要多个yum的服务需要一起安装,不需要指定多个name,看下面的,正常写是yum: name=ipset state=present 这样一般就安装一个像多个包一起安装这样更方便 - name: 安装ipvsadm管理工具 yum: name: - ipset - ipvsadm state: presen

  • 配置主机 [root@ansible ~]# cd /etc/ansible/ [mysql] node4 node5 [my_master] node4 [my_slave] node5 创建角色 [root@ansible ansible]# ansible-galaxy init roles/mysqld - Role roles/mysqld was created successful

  • 简介 ansible-playbook实战之批量安装mysql介绍了如何批量安装mysql,本篇博文用于按照自定义的参数批量部署mysql主从同步。 ansible-playbook配置思路: ansible配合使用mysql_user、mysql_db、mysql_replication在客户端创建数据库、创建用户及配置主从。 playbook的目录结构 |____hosts |____mysq

  • 一、业务场景 大规模集群(几十上百台服务器)搭建ambari,频繁更换登录服务器操作不便并且容易出现操作失误的情况,集群特点是环境基本一致,各节点的操作大部分相同,由此想到做一键部署脚本。 二、选用技术 ansible:新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运

  • 创建角色 [root@server ansible]# cd roles/ [root@server roles]# ansible-galaxy init mariadb - Role mariadb was created successfully 编写角色playbook [root@server mariadb]# cat tasks/main.yml --- # tasks fil

  • 描述角色结构 利用角色构造ansible playbook 随着开发更多的playbook,我们可能会发现有很多机会重复利用以前缩写的playbook中的代码。或许,一个用于为某一应用配置MySQL数据库的play可以改变用途,通过利用不同的主机名、密码和用户来为另一个应用配置MySQL数据库。 但在现实中,这个play可能比较冗长且复杂,有许多包含或导入的文件,以及用于管理各种情况的任务和处理程

  • 角色安装mysql5.6服务 //之前我们提前创建好了目录文件 [root@node-17 roles]# ls /data/ansible/roles/ httpd mysql nginx [root@node-17 roles]# tree ./mysql/ ./mysql/ ├── files ├── handlers ├── tasks ├── templates └── vars

  • 自动化管理利器Ansible-角色 Ansible Roles 介绍 一个数据中心有可能存在好多类型的服务器。比如WEB类型、DB类型、开发人员使用的开发类型、QA使用的测试类型等等。 实际生产中,基本每个类型的服务器的初始化行为都不一致。 那要在一个PlayBook中将这些动作完成,这个PlayBook将变得臃肿、庞大,且难以后续维护和更新。 如果能够针对每个类型的服务器单独编写PlayBook

 相关资料
  • 在了解 playbook 的基本架構與運行方式後,我會在接下來的章節內介紹如何使用 Ansible 搭建起 Jenkins 的運行環境。透過實際的例子,相信讀者會對操作 Ansible 將會更加熟練與靈活。 使用 Docker 運行 Jenkins 安裝 Jenkins 有許多方法,根據作業環境的不同也有可能會有安裝上的差異。這次我會介紹如何在 managed node 上安裝 Docker 這個

  • 项目介绍 Vue-role 是基于 Vue 的可视化权限管理库,让开发定义权限简单,让非技术人员分配权限更简单 使用说明 按 ctr+/ 开启权限管理模式,所有可定义权限的位置都会出现(红,绿,黄)点,点击点点分配权限,右上角的红点可以定义当前页面(路由)的访问权限,右上角可以模拟某个角色查看他的可访问视图 有图有真像 颜色说明 红色已非配过权限; 绿色没分配过权限,任何人可查看; 黄色没分配过权

  • This tool will request and set temporary credentials in your shell environment variables for a given role. Installation On OS X, the best way to get it is to use homebrew: brew install remind101/formu

  • 这是一个为传统角色扮演游戏提供相关工具的开源项目。当前包括的工具有:MapTool:这是一个可在C/S架构上为多个玩家提供地图与地图数据共享的图 形工具。DiceTool:这是一个能够在角色扮演游戏中推测死亡表达式的工具,它还可通过JavaScripts扩展各种计算。TokenTool:方 便创建MapTool标记(tokens).

  • 我在css中的任何地方都看不到角色按钮 我在试着做我自己的版本。

  • 新增类 net.wendal.nutzbook.bean.Role ,请自行补齐getter/setter package net.wendal.nutzbook.bean; import java.util.List; import org.nutz.dao.entity.annotation.ColDefine; import org.nutz.dao.entity.annotation.