分类: 系统运维
2015-03-31 14:41:25
# modules/perconaserver/manifests/init.pp
define perconaserver::instance(
$binlog_format = 'STATEMENT',
$environment = $environment,
$etc_mycnf = $name,
$long_query_time = '2',
$mount_dir = undef,
$mount_target = "/database/${environment}/${name}",
$mysql_buffer_pool = '25G',
$mysql_dir = "/database/${environment}/${name}/mysql",
$mysql_host = 'localhost',
$mysql_port = "70${name}",
$mysql_pid_file = "/var/lib/mysql/mysql.pid${name}",
$mysql_root_password = 'centos',
$mysql_server_id = "601${name}",
$mysql_socket = "/var/lib/mysql/mysql.sock${name}",
$enable_slow_query_log_rotate = false,
) {
file {
"/etc/my.cnf${etc_mycnf}":
ensure => file,
owner => mysql,
group => mysql,
mode => '0644',
content => template('perconaserver/mycnf.erb');
"/etc/init.d/mysql${etc_mycnf}":
ensure => file,
owner => mysql,
group => mysql,
mode => '0755',
content => template('perconaserver/mysql_initd.erb');
}
}
#nodes.pp
#Puppet will automatically assign classes from Hiera to every node. Note that the hiera_include function uses an array merge lookup to retrieve the classes array; this means every node will get every class from its hierarchy.
# />
hiera_include('classes', [])
# modules/profile/manifests/multi_mysql.pp
class profile::multi_mysql (
$manage_instances = True,
) {
include XXX
$packages = [
'mysql-mmm-agent',
'innotop',
]
common::package { $packages:
ensure => installed,
}
$instance_array = hiera('mysql_instances', [])
$instances_props = hiera_hash('mysql_props', {})
}
# produciton.pp
node /1.db.*/ {
perconaserver::instance { '05':
mysql_buffer_pool => '50G',
mysql_host => 'localhost',
mysql_root_password => 'centos',
mysql_server_id => '170101',
mount_dir => '/data/m01',
}
}
#hieradata/multi_mysql.yaml
---
classes:
- role::multi_mysql
mysql_props:
shard0:
mysql_port: 7000
mysql_socket: /var/lib/mysql/mysql.sock00
......
# 1.db.XXX
[!18 00:01:50 hfu@1.db.XXX ~]$ sudo facter -p |grep role
role => multi_mysql
首先production.pp有import nodes. 那么会
hiera_include('classes', [])
触发hiera的lookup, 此时hiera.yaml里面
:merge_behavior: deeper
会通过hiera.yaml来查找multi_mysql.yaml得到class为role::multi_mysql。
然后role::multi_mysql
modules/role/manifests/multi_mysql.pp
class role::multi_mysql {
include profile::multi_mysql
}
此时profile::multi_mysql又触发查询
production/1.db.prod.slv.yaml
mysql_instances:
- "05"
- "06"
- "19"
- "20"
mysql_props:
"05":
mysql_server_id: 370205
mysql_port: 7005
mysql_socket: /var/lib/mysql/mysql.sock05
"06":
mysql_server_id: 370206
mysql_port: 7006
mysql_socket: /var/lib/mysql/mysql.sock06