puppet之mysql批量安裝案例
上次簡單介紹了利用puppet批量安裝java的案例,這次來說說puppet自動化安裝mysql。前提是配置好了puppet的服務端和客戶端,puppet安裝配置參考blog http://space.itpub.net/27181165/viewspace-776318/.
mysql模組
[root@master manifests]# tree /etc/puppet/modules/mysql/manifests/
/etc/puppet/modules/mysql/manifests/
|-- add_user.pp
|-- init.pp
`-- install.pp
0 directories, 3 files
在mysql模組的manifests中新建幾個檔案,add_user.pp建立mysql使用者,init.pp puppet初始化檔案,install.pp mysql安裝檔案,各個檔案具體配置如下
初始化檔案
[root@master manifests]# cat init.pp
class mysql {
include mysql::add_user
include mysql::install
}
init.pp是每個puppet模組的必需的初始化檔案。包含有模組中定義的各個類。
[root@master manifests]# cat add_user.pp
class mysql::add_user {
group {"mysql":
ensure => "present",
gid => 501,
name => "mysql";
}
user {"mysql":
ensure => "present",
uid =>501,
gid =>501,
home => "/home/mysql",
managehome=> "true";
}
file {"/home/mysql":
owner => 501,
group => 501,
mode => 700,
ensure => directory;
}
}
在add_user.pp中,我建立了一個mysql組,組名為mysql,gid為501。建立了一個mysql使用者,指定了uid,gid及mysql的家目錄,用file資源給mysql家目錄賦予一定的許可權。
[root@master manifests]# cat install.pp
class mysql::install {
file { "/usr/local/src/mysql-5.1.62.tar.gz":
owner =>root,
group =>root,
mode =>644,
source =>"puppet://$puppetserver/files/mysql-5.1.62.tar.gz",
}
file { "/usr/local/src/myinstall.sh":
owner =>root,
group =>root,
mode =>755,
source =>"puppet://$puppetserver/files/myinstall.sh",
require => File["/usr/local/src/mysql-5.1.62.tar.gz"],
}
exec {"build_mysql":
cwd =>"/usr/local/src",
path =>"/bin:/usr/bin:/sbin:/usr/bin",
creates => "/usr/local/mysql",
command =>"/bin/sh /usr/local/src/myinstall.sh",
timeout => "0",
require => File["/usr/local/src/myinstall.sh"],
}
}
install.pp檔案是用來安裝mysql的,其中定義了2個file資源,一個是從puppet服務端取mysql安裝包的,另一個是取mysql安裝指令碼的。exec是執行mysql安裝指令碼安裝mysql。我把所有獲取到的檔案都放在/usr/local/src下。myinstall.sh是依賴於/usr/local/src/mysql-5.1.62.tar.gz的,因為,只有mysql-5.1.62.tar.gz檔案存在,myinstall.sh才有存在的意義。exec資源中,用creates判斷如果存在/usr/local/mysql說明mysql已經安裝過了,無需執行exec。安裝mysql的過程可能需要一些時間,因此在exec中設定了一個timeout超時時間,timeout=0表示時間不做限制。同樣的exec是依賴於myinstall.sh這個檔案的。
mysql安裝指令碼
mysql安裝指令碼放在puppet的檔案資源庫中,方便客戶端獲取
[root@master files]# cat /etc/puppet/files/myinstall.sh
#!/bin/bash
#Author: Andy
#Time: 20130905
#File:/etc/puppet/files/myinstall.sh
FILE_PATH=/usr/local/src
GROUP=mysql
USER=mysql
PORT=3306
VERSION=5.1.62
MYSQL_BASE=/usr/local/mysql
DATA_HOME=/var/lib/mysql
function add_user ()
{
cat /etc/group|grep "${GROUP}"
if [ $? -ne 0 ];then
echo "mysql group is not exist,create" >/tmp/mysqlinstall
/usr/sbin/groupadd -g 501 ${GROUP}
if [ $? -eq 0 ];then
echo "mysql group is created" >>/tmp/mysqlinstall
fi
else
echo "mysql group is exist">> /tmp/mysqlinstall
fi
id mysql >/dev/null 2>&1
if [ $? -ne 0 ];then
echo "the user mysql is not exist,create" >>/tmp/mysqlinstall
/usr/sbin/useradd -u 501 -g ${GROUP} ${USER}
if [ $? -eq 0 ];then
echo "user mysql is created" >>/tmp/mysqlinstall
fi
else
echo "mysql user is exist" >>/tmp/mysqlinstall
fi
}
function uncomp_tar ()
{
ls `pwd` |grep -w ^mysql-5.1.62$
if [ $? -ne 0 ];then
echo "uncompress mysql target package" >/tmp/mysqlinstall
tar -zxvf mysql-${VERSION}.tar.gz
echo "uncompress target package successful">>/tmp/mysqlinstall
sleep 5
fi
}
function configure()
{
echo "mysql configure" >>/tmp/mysqlinstall
cd ${FILE_PATH}/mysql-${VERSION}
sh configure --prefix=${MYSQL_BASE} \
--sysconfdir=/etc \
--localstatedir=${DATA_HOME} \
--with-tcp-port=${PORT} \
--with-unix-socket-path=/tmp/mysqld.sock \
--with-mysqld-user=${USER} \
--with-plugins=innobase,myisam #innobase要求記憶體大於2GB
echo "mysql configure completed">>/tmp/mysqlinstall
sleep 5
}
function makein()
{
echo "start make">>/tmp/mysqlinstall
cd ${FILE_PATH}/mysql-${VERSION}
make clean
make
echo "make completed">>/tmp/mysqlinstall
sleep 5
echo "start make install">>/tmp/mysqlinstall
make install
echo "make install completed">>/tmp/mysqlinstall
sleep 5
}
function setup()
{
echo "mysql setup" >>/tmp/mysqlinstall
sleep 5
cp ${MYSQL_BASE}/share/mysql/my-innodb-heavy-4G.cnf /etc/my.cnf
sed -i '/storage-engine/ s/MYISAM/INNODB/' /etc/my.cnf
sed -i '/rehash/ s/no-auto-rehash/auto-rehash/' /etc/my.cnf
cp ${MYSQL_BASE}/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
chown -R ${USER} ${MYSQL_BASE}
chgrp -R ${GROUP} ${MYSQL_BASE}
echo "mysql setup successful" >>/tmp/mysqlinstall
}
function initial()
{
echo "mysql initail" >>/tmp/mysqlinstall
sleep 5
${MYSQL_BASE}/bin/mysql_install_db --user=mysql
chown -R root ${MYSQL_BASE}
${MYSQL_BASE}/bin/mysqld_safe --user=mysql &
echo "mysql enviroment configure" >>/tmp/mysqlinstall
cat /etc/profile|grep mysql >/dev/null
if [ $? -ne 0 ];then
echo "export PATH=\$PATH:${MYSQL_BASE}/bin" >>/etc/profile
fi
source /etc/profile
echo "mysql install completed" >>/tmp/mysqlinstall
}
#===============================================
add_user
uncomp_tar
configure
makein
setup
initial
mysql模組
[root@master manifests]# tree /etc/puppet/modules/mysql/manifests/
/etc/puppet/modules/mysql/manifests/
|-- add_user.pp
|-- init.pp
`-- install.pp
0 directories, 3 files
在mysql模組的manifests中新建幾個檔案,add_user.pp建立mysql使用者,init.pp puppet初始化檔案,install.pp mysql安裝檔案,各個檔案具體配置如下
初始化檔案
[root@master manifests]# cat init.pp
class mysql {
include mysql::add_user
include mysql::install
}
init.pp是每個puppet模組的必需的初始化檔案。包含有模組中定義的各個類。
[root@master manifests]# cat add_user.pp
class mysql::add_user {
group {"mysql":
ensure => "present",
gid => 501,
name => "mysql";
}
user {"mysql":
ensure => "present",
uid =>501,
gid =>501,
home => "/home/mysql",
managehome=> "true";
}
file {"/home/mysql":
owner => 501,
group => 501,
mode => 700,
ensure => directory;
}
}
在add_user.pp中,我建立了一個mysql組,組名為mysql,gid為501。建立了一個mysql使用者,指定了uid,gid及mysql的家目錄,用file資源給mysql家目錄賦予一定的許可權。
[root@master manifests]# cat install.pp
class mysql::install {
file { "/usr/local/src/mysql-5.1.62.tar.gz":
owner =>root,
group =>root,
mode =>644,
source =>"puppet://$puppetserver/files/mysql-5.1.62.tar.gz",
}
file { "/usr/local/src/myinstall.sh":
owner =>root,
group =>root,
mode =>755,
source =>"puppet://$puppetserver/files/myinstall.sh",
require => File["/usr/local/src/mysql-5.1.62.tar.gz"],
}
exec {"build_mysql":
cwd =>"/usr/local/src",
path =>"/bin:/usr/bin:/sbin:/usr/bin",
creates => "/usr/local/mysql",
command =>"/bin/sh /usr/local/src/myinstall.sh",
timeout => "0",
require => File["/usr/local/src/myinstall.sh"],
}
}
install.pp檔案是用來安裝mysql的,其中定義了2個file資源,一個是從puppet服務端取mysql安裝包的,另一個是取mysql安裝指令碼的。exec是執行mysql安裝指令碼安裝mysql。我把所有獲取到的檔案都放在/usr/local/src下。myinstall.sh是依賴於/usr/local/src/mysql-5.1.62.tar.gz的,因為,只有mysql-5.1.62.tar.gz檔案存在,myinstall.sh才有存在的意義。exec資源中,用creates判斷如果存在/usr/local/mysql說明mysql已經安裝過了,無需執行exec。安裝mysql的過程可能需要一些時間,因此在exec中設定了一個timeout超時時間,timeout=0表示時間不做限制。同樣的exec是依賴於myinstall.sh這個檔案的。
mysql安裝指令碼
mysql安裝指令碼放在puppet的檔案資源庫中,方便客戶端獲取
[root@master files]# cat /etc/puppet/files/myinstall.sh
#!/bin/bash
#Author: Andy
#Time: 20130905
#File:/etc/puppet/files/myinstall.sh
FILE_PATH=/usr/local/src
GROUP=mysql
USER=mysql
PORT=3306
VERSION=5.1.62
MYSQL_BASE=/usr/local/mysql
DATA_HOME=/var/lib/mysql
function add_user ()
{
cat /etc/group|grep "${GROUP}"
if [ $? -ne 0 ];then
echo "mysql group is not exist,create" >/tmp/mysqlinstall
/usr/sbin/groupadd -g 501 ${GROUP}
if [ $? -eq 0 ];then
echo "mysql group is created" >>/tmp/mysqlinstall
fi
else
echo "mysql group is exist">> /tmp/mysqlinstall
fi
id mysql >/dev/null 2>&1
if [ $? -ne 0 ];then
echo "the user mysql is not exist,create" >>/tmp/mysqlinstall
/usr/sbin/useradd -u 501 -g ${GROUP} ${USER}
if [ $? -eq 0 ];then
echo "user mysql is created" >>/tmp/mysqlinstall
fi
else
echo "mysql user is exist" >>/tmp/mysqlinstall
fi
}
function uncomp_tar ()
{
ls `pwd` |grep -w ^mysql-5.1.62$
if [ $? -ne 0 ];then
echo "uncompress mysql target package" >/tmp/mysqlinstall
tar -zxvf mysql-${VERSION}.tar.gz
echo "uncompress target package successful">>/tmp/mysqlinstall
sleep 5
fi
}
function configure()
{
echo "mysql configure" >>/tmp/mysqlinstall
cd ${FILE_PATH}/mysql-${VERSION}
sh configure --prefix=${MYSQL_BASE} \
--sysconfdir=/etc \
--localstatedir=${DATA_HOME} \
--with-tcp-port=${PORT} \
--with-unix-socket-path=/tmp/mysqld.sock \
--with-mysqld-user=${USER} \
--with-plugins=innobase,myisam #innobase要求記憶體大於2GB
echo "mysql configure completed">>/tmp/mysqlinstall
sleep 5
}
function makein()
{
echo "start make">>/tmp/mysqlinstall
cd ${FILE_PATH}/mysql-${VERSION}
make clean
make
echo "make completed">>/tmp/mysqlinstall
sleep 5
echo "start make install">>/tmp/mysqlinstall
make install
echo "make install completed">>/tmp/mysqlinstall
sleep 5
}
function setup()
{
echo "mysql setup" >>/tmp/mysqlinstall
sleep 5
cp ${MYSQL_BASE}/share/mysql/my-innodb-heavy-4G.cnf /etc/my.cnf
sed -i '/storage-engine/ s/MYISAM/INNODB/' /etc/my.cnf
sed -i '/rehash/ s/no-auto-rehash/auto-rehash/' /etc/my.cnf
cp ${MYSQL_BASE}/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
chown -R ${USER} ${MYSQL_BASE}
chgrp -R ${GROUP} ${MYSQL_BASE}
echo "mysql setup successful" >>/tmp/mysqlinstall
}
function initial()
{
echo "mysql initail" >>/tmp/mysqlinstall
sleep 5
${MYSQL_BASE}/bin/mysql_install_db --user=mysql
chown -R root ${MYSQL_BASE}
${MYSQL_BASE}/bin/mysqld_safe --user=mysql &
echo "mysql enviroment configure" >>/tmp/mysqlinstall
cat /etc/profile|grep mysql >/dev/null
if [ $? -ne 0 ];then
echo "export PATH=\$PATH:${MYSQL_BASE}/bin" >>/etc/profile
fi
source /etc/profile
echo "mysql install completed" >>/tmp/mysqlinstall
}
#===============================================
add_user
uncomp_tar
configure
makein
setup
initial
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-776386/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- puppet之java批量安裝案例Java
- kickstart之批量安裝puppet客戶端客戶端
- puppet之安裝配置
- puppet 安裝
- puppet rpm方式的安裝
- RHEL6下puppet部署管理1之安裝測試
- puppet完全攻略(一)puppet應用原理及安裝部署
- MySQL批量更新死鎖案例分析MySql
- 如何在 Ubuntu 15.04 中安裝 puppetUbuntu
- CentOS 6.3下Puppet安裝配置筆記CentOS筆記
- docker筆記18-案例-安裝mysqlDocker筆記MySql
- Puppet+foreman 本地yum安裝手冊REM
- MySQL 5.6.21下載安裝之安裝篇(二)MySql
- MySQL之——RPM方式安裝MySQL5.6MySql
- Mysql 學習篇之原始碼安裝mysqlMySql原始碼
- Flask+Mysql搭建網站之安裝MysqlFlaskMySql網站
- mysql之 xtrabackup-2.4.12 安裝MySql
- cobbler 批量安裝linux薦Linux
- MySQL Innodb表空間解除安裝和遷移案例MySql
- Mysql之案例分析(一)MySql
- 在centos 5.6 64位用yum安裝puppet 2.6.9(一)薦CentOS
- puppet之crontab時間同步
- mysql安裝 (yum 安裝)MySql
- mysql之tar.gz原始碼安裝MySql原始碼
- python庫批量安裝的方法Python
- 【MySQL】死鎖案例之六MySql
- 【MySQL】死鎖案例之七MySql
- 【MySQL】死鎖案例之八MySql
- 【MySQL】死鎖案例之四MySql
- mysql 安裝MySql
- MySQL安裝MySql
- 安裝mysqlMySql
- solaris mysql 安裝 解除安裝MySql
- [mysql]ubuntu安裝mysqlMySqlUbuntu
- 批量載入效能案例
- 使用adb如何批量給裝置安裝apkAPK
- 安裝PHP之PDO_MYSQL擴充套件PHPMySql套件
- MySQL自動化運維之安裝篇MySql運維