使用 puppet 安装 mysql 一例,供大家学习参考。
目录结构如下:
[root@puppet puppet]# tree
.
|-- auth.conf
|-- fileserver.conf
|-- manifests
| |-- nodes.pp
| `-- site.pp
|-- modules
| |-- avahi-daemon
| | |-- files
| | `-- manifests
| | |-- init.pp
| | `-- service.pp
| |-- mysql
| | |-- files
| | | `-- my.cnf
| | `-- manifests
| | |-- config.pp
| | |-- init.pp
| | |-- install.pp
| | |-- mysqluser.pp
| | `-- service.pp
| |-- ssh
| | |-- files
| | |-- manifests
| | | |-- config.pp
| | | |-- init.pp
| | | |-- install.pp
| | | `-- service.pp
| | `-- templates
| `-- web
| |-- files
| | |-- nginx-0.8.55.tar.gz
| | `-- nginx_install.sh
| |-- manifests
| | |-- init.pp
| | `-- nginx.pp
| `-- templates
|-- puppet.conf
`-- ssl
|-- ca
| |-- ca_crl.pem
| |-- ca_crt.pem
| |-- ca_key.pem
| |-- ca_pub.pem
| |-- inventory.txt
| |-- private
| | `-- ca.pass
| |-- requests
| |-- serial
| `-- signed
| |-- mysql.cctvcjw.com.pem
| |-- puppet.cctvcjw.com.pem
| |-- web1.cctvcjw.com.pem
| `-- web2.cctvcjw.com.pem
|-- certificate_requests
|-- certs
| |-- ca.pem
| `-- puppet.cctvcjw.com.pem
|-- crl.pem
|-- private
|-- private_keys
| `-- puppet.cctvcjw.com.pem
`-- public_keys
`-- puppet.cctvcjw.com.pem
配置过程
cd /etc/puppet/manifests
cat site.pp
import 'nodes.pp'
# cat nodes.pp
node 'mysql.cctvcjw.com' {
include mysql
}
mkdir -p mkdir -p /etc/puppet/modules/mysql/{manifests,file,templates}
cd /etc/puppet/modules/mysql/manifests
cat init.pp
class mysql {
include mysql::mysqluser,mysql::install,mysql::config,mysql::service
}
[root@puppet manifests]# cat mysqluser.pp
class mysql::mysqluser {
group { "mysql-group":
ensure =>'present',
gid =>1001,
name =>'mysql',
}
user { "mysql-user":
ensure =>'present',
comment =>'mysqluser',
name=>'mysql',
gid =>1001,
home =>'/dev/null',
# password=>'123456',
shell =>'/sbin/nologin',
}
}
[root@puppet manifests]# cat install.pp
class mysql::install {
package { "mysql-server":
ensure => 'present',
}
}
[root@puppet manifests]# cat config.pp
class mysql::config {
file { "/etc/my.cnf":
source => 'puppet:///modules/mysql/my.cnf',
owner =>'mysql',
group =>'mysql',
mode =>'0700',
require =>Class["mysql::install"],
notify =>Class["mysql::service"];
}
}
[root@puppet manifests]# cat service.pp
class mysql::service {
service { "mysqld":
ensure =>'running',
hasstatus =>'true',
hasrestart =>'true',
enable =>'true',
require =>Class["mysql::config"],
}
}
[root@puppet manifests]# cat /etc/puppet/modules/mysql/files/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
客户端执行:puppet --agent --test --server=puppet.manwrx.com