mirror of
https://github.com/geerlingguy/ansible-role-apache
synced 2025-01-08 02:50:18 +01:00
Reorganised folders
This commit is contained in:
parent
8e27d903c1
commit
46e1eb29a2
203 changed files with 24 additions and 876 deletions
157
README.md
157
README.md
|
@ -1,143 +1,34 @@
|
|||
# Ansible Role: MySQL
|
||||
## WordPress+Nginx+PHP-FPM+MariaDB Deployment
|
||||
|
||||
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-mysql.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-mysql)
|
||||
- Requires Ansible 1.2 or newer
|
||||
- Expects CentOS/RHEL 7.x host/s
|
||||
|
||||
Installs and configures MySQL or MariaDB server on RHEL/CentOS or Debian/Ubuntu servers.
|
||||
RHEL7 version reflects changes in Red Hat Enterprise Linux and CentOS 7:
|
||||
1. Network device naming scheme has changed
|
||||
2. iptables is replaced with firewalld
|
||||
3. MySQL is replaced with MariaDB
|
||||
|
||||
## Requirements
|
||||
These playbooks deploy a simple all-in-one configuration of the popular
|
||||
WordPress blogging platform and CMS, frontend by the Nginx web server and the
|
||||
PHP-FPM process manager. To use, copy the `hosts.example` file to `hosts` and
|
||||
edit the `hosts` inventory file to include the names or URLs of the servers
|
||||
you want to deploy.
|
||||
|
||||
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:
|
||||
Then run the playbook, like this:
|
||||
|
||||
- hosts: database
|
||||
roles:
|
||||
- role: geerlingguy.mysql
|
||||
become: yes
|
||||
ansible-playbook -i hosts site.yml
|
||||
|
||||
## Role Variables
|
||||
The playbooks will configure MariaDB, WordPress, Nginx, and PHP-FPM. When the run
|
||||
is complete, you can hit access server to begin the WordPress configuration.
|
||||
|
||||
Available variables are listed below, along with default values (see `defaults/main.yml`):
|
||||
### Ideas for Improvement
|
||||
|
||||
mysql_user_home: /root
|
||||
Here are some ideas for ways that these playbooks could be extended:
|
||||
|
||||
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.
|
||||
- Parameterize the WordPress deployment to handle multi-site configurations.
|
||||
- Separate the components (PHP-FPM, MySQL, Nginx) onto separate hosts and
|
||||
handle the configuration appropriately.
|
||||
- Handle WordPress upgrades automatically.
|
||||
|
||||
mysql_root_password: root
|
||||
|
||||
The MySQL root user account password.
|
||||
|
||||
mysql_root_password_update: no
|
||||
|
||||
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.
|
||||
|
||||
mysql_enabled_on_startup: yes
|
||||
|
||||
Whether MySQL should be enabled on startup.
|
||||
|
||||
overwrite_global_mycnf: yes
|
||||
|
||||
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.
|
||||
|
||||
mysql_users: []
|
||||
|
||||
The MySQL users and their privileges. A user has the values `name`, `host` (defaults to `localhost`), `password`, `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_port: "3306"
|
||||
mysql_bind_address: '0.0.0.0'
|
||||
mysql_datadir: /var/lib/mysql
|
||||
|
||||
Default MySQL connection configuration.
|
||||
|
||||
mysql_log: ""
|
||||
mysql_log_error: /var/log/mysqld.log
|
||||
mysql_syslog_tag: mysqld
|
||||
|
||||
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: no
|
||||
mysql_slow_query_log_file: /var/log/mysql-slow.log
|
||||
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. 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_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 `mysql_users`, and is created on master servers, and used to replicate on all the slaves.
|
||||
|
||||
### 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](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/).
|
||||
We would love to see contributions and improvements, so please fork this
|
||||
repository on GitHub and send us your changes via pull requests.
|
|
@ -1,34 +0,0 @@
|
|||
## WordPress+Nginx+PHP-FPM+MariaDB Deployment
|
||||
|
||||
- Requires Ansible 1.2 or newer
|
||||
- Expects CentOS/RHEL 7.x host/s
|
||||
|
||||
RHEL7 version reflects changes in Red Hat Enterprise Linux and CentOS 7:
|
||||
1. Network device naming scheme has changed
|
||||
2. iptables is replaced with firewalld
|
||||
3. MySQL is replaced with MariaDB
|
||||
|
||||
These playbooks deploy a simple all-in-one configuration of the popular
|
||||
WordPress blogging platform and CMS, frontend by the Nginx web server and the
|
||||
PHP-FPM process manager. To use, copy the `hosts.example` file to `hosts` and
|
||||
edit the `hosts` inventory file to include the names or URLs of the servers
|
||||
you want to deploy.
|
||||
|
||||
Then run the playbook, like this:
|
||||
|
||||
ansible-playbook -i hosts site.yml
|
||||
|
||||
The playbooks will configure MariaDB, WordPress, Nginx, and PHP-FPM. When the run
|
||||
is complete, you can hit access server to begin the WordPress configuration.
|
||||
|
||||
### Ideas for Improvement
|
||||
|
||||
Here are some ideas for ways that these playbooks could be extended:
|
||||
|
||||
- Parameterize the WordPress deployment to handle multi-site configurations.
|
||||
- Separate the components (PHP-FPM, MySQL, Nginx) onto separate hosts and
|
||||
handle the configuration appropriately.
|
||||
- Handle WordPress upgrades automatically.
|
||||
|
||||
We would love to see contributions and improvements, so please fork this
|
||||
repository on GitHub and send us your changes via pull requests.
|
|
@ -1,76 +0,0 @@
|
|||
---
|
||||
sudo: required
|
||||
|
||||
env:
|
||||
- distribution: centos
|
||||
version: 6
|
||||
init: /sbin/init
|
||||
run_opts: ""
|
||||
playbook: test.yml
|
||||
- distribution: centos
|
||||
version: 7
|
||||
init: /usr/lib/systemd/systemd
|
||||
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
|
||||
playbook: centos-7-test.yml
|
||||
- distribution: ubuntu
|
||||
version: 14.04
|
||||
init: /sbin/init
|
||||
run_opts: ""
|
||||
playbook: test.yml
|
||||
# - distribution: ubuntu
|
||||
# version: 12.04
|
||||
# init: /sbin/init
|
||||
# run_opts: ""
|
||||
# playbook: test.yml
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_install:
|
||||
# Pull container
|
||||
- 'sudo docker pull ${distribution}:${version}'
|
||||
# Customize container
|
||||
- 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
|
||||
|
||||
script:
|
||||
- container_id=$(mktemp)
|
||||
# Run container in detached state
|
||||
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"'
|
||||
|
||||
# Ansible syntax check.
|
||||
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} --syntax-check'
|
||||
|
||||
# Test role.
|
||||
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}'
|
||||
|
||||
# Test role idempotence.
|
||||
- >
|
||||
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}
|
||||
| grep -q 'changed=0.*failed=0'
|
||||
&& (echo 'Idempotence test: pass' && exit 0)
|
||||
|| (echo 'Idempotence test: fail' && exit 1)
|
||||
|
||||
# Some MySQL debugging (show all the logs).
|
||||
- sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ls -lah /var/log
|
||||
- sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql/error.log || true
|
||||
- sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql.err || true
|
||||
|
||||
# Check to make sure we can connect to MySQL via Unix socket.
|
||||
- >
|
||||
sudo docker exec "$(cat ${container_id})" mysql -u root -proot -e 'show databases;'
|
||||
| grep -q 'information_schema'
|
||||
&& (echo 'MySQL running normally' && exit 0)
|
||||
|| (echo 'MySQL not running' && exit 1)
|
||||
|
||||
# Check to make sure we can connect to MySQL via TCP.
|
||||
- >
|
||||
sudo docker exec "$(cat ${container_id})" mysql -u root -proot -h 127.0.0.1 -e 'show databases;'
|
||||
| grep -q 'information_schema'
|
||||
&& (echo 'MySQL running normally' && exit 0)
|
||||
|| (echo 'MySQL not running' && exit 1)
|
||||
|
||||
# Clean up
|
||||
- sudo docker stop "$(cat ${container_id})"
|
||||
|
||||
notifications:
|
||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
|
@ -1,95 +0,0 @@
|
|||
---
|
||||
mysql_user_home: /root
|
||||
mysql_root_username: root
|
||||
mysql_root_password: root
|
||||
|
||||
# Set this to `yes` to forcibly update the root password.
|
||||
mysql_root_password_update: no
|
||||
|
||||
mysql_enabled_on_startup: yes
|
||||
|
||||
# update my.cnf. each time role is run? yes | no
|
||||
overwrite_global_mycnf: yes
|
||||
|
||||
# Pass in a comma-separated list of repos to use (e.g. "remi,epel"). Used only
|
||||
# for RedHat systems (and derivatives).
|
||||
mysql_enablerepo: ""
|
||||
|
||||
# Define a custom list of packages to install; if none provided, the default
|
||||
# package list from vars/[OS-family].yml will be used.
|
||||
# mysql_packages:
|
||||
# - mysql
|
||||
# - mysql-server
|
||||
# - MySQL-python
|
||||
|
||||
# MySQL connection settings.
|
||||
mysql_port: "3306"
|
||||
mysql_bind_address: '0.0.0.0'
|
||||
mysql_datadir: /var/lib/mysql
|
||||
mysql_pid_file: /var/run/mysqld/mysqld.pid
|
||||
mysql_skip_name_resolve: no
|
||||
|
||||
# Slow query log settings.
|
||||
mysql_slow_query_log_enabled: no
|
||||
mysql_slow_query_log_file: /var/log/mysql-slow.log
|
||||
mysql_slow_query_time: 2
|
||||
|
||||
# Memory settings (default values optimized ~512MB RAM).
|
||||
mysql_key_buffer_size: "256M"
|
||||
mysql_max_allowed_packet: "64M"
|
||||
mysql_table_open_cache: "256"
|
||||
mysql_sort_buffer_size: "1M"
|
||||
mysql_read_buffer_size: "1M"
|
||||
mysql_read_rnd_buffer_size: "4M"
|
||||
mysql_myisam_sort_buffer_size: "64M"
|
||||
mysql_thread_cache_size: "8"
|
||||
mysql_query_cache_size: "16M"
|
||||
mysql_max_connections: 151
|
||||
|
||||
# Other settings.
|
||||
mysql_wait_timeout: 28800
|
||||
|
||||
# InnoDB settings.
|
||||
# Set .._buffer_pool_size up to 80% of RAM but beware of setting too high.
|
||||
mysql_innodb_file_per_table: "1"
|
||||
mysql_innodb_buffer_pool_size: "256M"
|
||||
# Set .._log_file_size to 25% of buffer pool size.
|
||||
mysql_innodb_log_file_size: "64M"
|
||||
mysql_innodb_log_buffer_size: "8M"
|
||||
mysql_innodb_flush_log_at_trx_commit: "1"
|
||||
mysql_innodb_lock_wait_timeout: 50
|
||||
|
||||
# mysqldump settings.
|
||||
mysql_mysqldump_max_allowed_packet: "64M"
|
||||
|
||||
# Logging settings.
|
||||
mysql_log: ""
|
||||
mysql_log_error: /var/log/mysql.err
|
||||
mysql_syslog_tag: mysql
|
||||
|
||||
mysql_config_include_files: []
|
||||
# - src: path/relative/to/playbook/file.cnf
|
||||
# - { src: path/relative/to/playbook/anotherfile.cnf, force: yes }
|
||||
|
||||
# Databases.
|
||||
mysql_databases: []
|
||||
# - name: example
|
||||
# collation: utf8_general_ci
|
||||
# encoding: utf8
|
||||
# replicate: 1
|
||||
|
||||
# Users.
|
||||
mysql_users: []
|
||||
# - name: example
|
||||
# host: 127.0.0.1
|
||||
# password: secret
|
||||
# priv: *.*:USAGE
|
||||
|
||||
# Replication settings (replication is only enabled if master/user have values).
|
||||
mysql_server_id: "1"
|
||||
mysql_max_binlog_size: "100M"
|
||||
mysql_expire_logs_days: "10"
|
||||
mysql_replication_role: ''
|
||||
mysql_replication_master: ''
|
||||
# Same keys as `mysql_users` above.
|
||||
mysql_replication_user: []
|
|
@ -1,3 +0,0 @@
|
|||
---
|
||||
- name: restart mysql
|
||||
service: "name={{ mysql_daemon }} state=restarted sleep=5"
|
|
@ -1,22 +0,0 @@
|
|||
---
|
||||
dependencies: []
|
||||
|
||||
galaxy_info:
|
||||
author: geerlingguy
|
||||
description: MySQL server for RHEL/CentOS and Debian/Ubuntu.
|
||||
company: "Midwestern Mac, LLC"
|
||||
license: "license (BSD, MIT)"
|
||||
min_ansible_version: 1.9
|
||||
platforms:
|
||||
- name: EL
|
||||
versions:
|
||||
- 6
|
||||
- 7
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- all
|
||||
- name: Debian
|
||||
versions:
|
||||
- all
|
||||
galaxy_tags:
|
||||
- database
|
0
defaults/main.yml → roles/ansible-role-mysql/defaults/main.yml
Normal file → Executable file
0
defaults/main.yml → roles/ansible-role-mysql/defaults/main.yml
Normal file → Executable file
0
handlers/main.yml → roles/ansible-role-mysql/handlers/main.yml
Normal file → Executable file
0
handlers/main.yml → roles/ansible-role-mysql/handlers/main.yml
Normal file → Executable file
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue