puppet 搭建lnmp架构

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了puppet 搭建lnmp架构相关的知识,希望对你有一定的参考价值。


pupppet 搭建lnmp架构:

[[email protected] puppet]# tree modules/

modules/

|-- httpd

|   |-- files

|   |   `-- httpd.conf

|   `-- manifests

|       |-- config.pp

|       |-- init.pp

|       |-- install.pp

|       `-- service.pp

|-- mysqld

|   |-- files

|   |   |-- cmake-2.8.4.tar.gz

|   |   |-- my.cnf

|   |   |-- mysql-5.5.12.tar.gz

|   |   `-- mysql_install.sh

|   `-- manifests

|       |-- config.pp

|       |-- init.pp

|       |-- install.pp

|       `-- service.pp

|-- nginx

|   |-- files

|   |   |-- nginx-1.10.1.tar.gz

|   |   |-- nginx.conf

|   |   `-- nginx_install.sh

|   `-- manifests

|       |-- config.pp

|       |-- init.pp

|       |-- install.pp

|       `-- service.pp

`-- php

    |-- files

    |   |-- libmcrypt-2.5.8.tar.bz2

    |   |-- php-5.3.6.tar.bz2

    |   |-- php-fpm.conf

    |   `-- php_install.sh

    `-- manifests

        |-- config.pp

        |-- init.pp

        |-- install.pp

        `-- service.pp

 

12 directories, 28 files

nginx模块:

[[email protected] manifests]# ls

config.pp  init.pp  install.pp  service.pp

[[email protected] manifests]# cat init.pp 

class nginx {

include nginx::install,nginx::config,nginx::service

}

[[email protected] manifests]# cat install.pp 

class nginx::install {

file {

"/mnt/nginx-1.10.1.tar.gz":

source => "puppet:///modules/nginx/nginx-1.10.1.tar.gz";

"/mnt/nginx_install.sh":

source => "puppet:///modules/nginx/nginx_install.sh",

mode => 775

}

exec {

"nginx-install":

command => ‘/mnt/nginx_install.sh‘,

timeout => 9999,

path => ‘/bin:/sbin:/usr/bin:/usr/sbin‘,

creates => ‘/usr/local/nginx/sbin/nginx‘,

require => File ["/mnt/nginx_install.sh"],

}

}

[[email protected] manifests]# cat config.pp 

class nginx::config {

file {

"/usr/local/nginx/conf/nginx.conf":

source => "puppet:///modules/nginx/nginx.conf",

notify => Exec["reload-nginx"],

require => Class[nginx::install]

}

}

[[email protected] manifests]# cat service.pp 

class nginx::service {

exec {

"start-nginx":

command =>‘/usr/local/nginx/sbin/nginx‘,

require => Class[‘nginx::config‘],

creates => ‘/usr/local/nginx/logs/nginx.pid‘

}

exec {

"reload-nginx":

command => ‘/usr/local/nginx/sbin/nginx -s reload‘,

refreshonly => true

}

}

[[email protected] manifests]# 

 

 

[[email protected] nginx]# cd files/

[[email protected] files]# ls

nginx-1.10.1.tar.gz  nginx.conf  nginx_install.sh

[[email protected] files]# cat nginx_install.sh 

#!/bin/bash

yum install -y gcc  pcre-devel openssl-devel zlib-devel &>/dev/null

cd /mnt/

tar -xf nginx-1.10.1.tar.gz &>/dev/null

cd nginx-1.10.1

./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module &> /dev/null

sed -i.bak ‘s/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g‘ auto/cc/gcc

make &> /dev/null 

make install &> /dev/null

[[email protected] files]# 

技术分享 

mysql模块:

[[email protected] nginx]# ls

files  manifests

[[email protected] nginx]# cd manifests/

[[email protected] manifests]# cat init.pp 

class nginx {

include nginx::install,nginx::config,nginx::service

}

[[email protected] manifests]# cat install.pp 

class nginx::install {

file {

"/mnt/nginx-1.10.1.tar.gz":

source => "puppet:///modules/nginx/nginx-1.10.1.tar.gz";

"/mnt/nginx_install.sh":

source => "puppet:///modules/nginx/nginx_install.sh",

mode => 775

}

exec {

"nginx-install":

command => ‘/mnt/nginx_install.sh‘,

timeout => 9999,

path => ‘/bin:/sbin:/usr/bin:/usr/sbin‘,

creates => ‘/usr/local/nginx/sbin/nginx‘,

require => File ["/mnt/nginx_install.sh"],

}

}

[[email protected] manifests]# cat config.pp 

class nginx::config {

file {

"/usr/local/nginx/conf/nginx.conf":

source => "puppet:///modules/nginx/nginx.conf",

notify => Exec["reload-nginx"],

require => Class[nginx::install]

}

}

[[email protected] manifests]# cat service.pp 

class nginx::service {

exec {

"start-nginx":

command =>‘/usr/local/nginx/sbin/nginx‘,

require => Class[‘nginx::config‘],

creates => ‘/usr/local/nginx/logs/nginx.pid‘

}

exec {

"reload-nginx":

command => ‘/usr/local/nginx/sbin/nginx -s reload‘,

refreshonly => true

}

}

[[email protected] nginx]# cd files/

[[email protected] files]# ls

nginx-1.10.1.tar.gz  nginx.conf  nginx_install.sh

[[email protected] files]# cat nginx_install.sh 

#!/bin/bash

yum install -y gcc  pcre-devel openssl-devel zlib-devel &>/dev/null

cd /mnt/

tar -xf nginx-1.10.1.tar.gz &>/dev/null

cd nginx-1.10.1

./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module &> /dev/null

sed -i.bak ‘s/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g‘ auto/cc/gcc

make &> /dev/null 

make install &> /dev/null

useradd mysql

cd /usr/local/lnmp/mysql

cd support-files

cp my-large.cnf  /etc/my.cnf

cp mysql.server  /etc/init.d/mysqld

sed -i ‘10s/^/#/g‘ ~/.bash_profile

echo "PATH=\$PATH:\$HOME/bin:/usr/local/lnmp/mysql/bin" >> ~/.bash_profile

source ~/.bash_profile

chown -R mysql:mysql /usr/local/lnmp/mysql/

cd /usr/local/lnmp/mysql/scripts

./mysql_install_db --user=mysql --basedir=/usr/local/lnmp/mysql --datadir=/usr/local/lnmp/mysql/data

chown -R root.root /usr/local/lnmp/mysql/

cd /usr/local/lnmp/mysql/

chown  mysql data/ -R

[[email protected] files]# 

 

[[email protected] files]# 

技术分享 

[[email protected] php]# cd manifests/

[[email protected] manifests]# vim in

init.pp     install.pp  

[[email protected] manifests]# vim init.pp 

[[email protected] manifests]# cat init.pp 

class php {

include php::install,php::config,php::service

}

[[email protected] manifests]# cat install.pp 

class php::install {

file {

"/mnt/php_install.sh":

source => ‘puppet:///modules/php/php_install.sh‘,

mode => 775;

"/mnt/php-5.3.6.tar.bz2":

source => ‘puppet:///modules/php/php-5.3.6.tar.bz2‘;

"/mnt/libmcrypt-2.5.8.tar.bz2":

source => ‘puppet:///modules/php/libmcrypt-2.5.8.tar.bz2‘;


}

exec {

"php-install":

command => ‘/mnt/php_install.sh ‘,

timeout =>99999,

path =>‘/bin:/usr/bin:/usr/sbin:/sbin‘,

creates => ‘/etc/init.d/php-fpm‘,

require => File ["/mnt/php_install.sh"]


}

 

}

[[email protected] manifests]# cat config.pp 

class php::config {

file {

"/usr/local/lnmp/php/etc/php-fpm.conf":

source =>‘puppet:///modules/php/php-fpm.conf‘,

notify =>Exec["php-fpm_reload"],

require =>Class[php::install]

}


}

[[email protected] manifests]# cat service.pp 

class php::service {

service {

"php-fpm":

ensure =>running,

require =>Class[‘php::config‘],

#creates => ‘/usr/local/lnmp/php/data/server3.example.com.pid‘

}

exec {

"php-fpm_reload":

command =>‘/etc/init.d/php-fpm reload‘,

refreshonly => true

}

}

[[email protected] manifests]# 

[[email protected] php]# cd files/

[[email protected] files]# ls

libmcrypt-2.5.8.tar.bz2  php-5.3.6.tar.bz2  php-fpm.conf  php_install.sh

[[email protected] files]# cat php_install.sh 

#!/bin/bash

cd /mnt/

tar -xf libmcrypt-2.5.8.tar.bz2

cd libmcrypt-2.5.8

./configure --libdir=/usr/local/lib64 &>/dev/null

make && make install &>/dev/null

cd libltdl/

./configure libdir=/usr/local/lib64 --enable-ltdl-install &>/dev/null

make &> /dev/null

make install &> /dev/null

yum install -y net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel &>/dev/null

cd /mnt/

tar jxf php-5.3.6.tar.bz2

cd php-5.3.6

./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=/usr/local/lnmp/mysql/lib/ --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir  --with-pear --with-gettext --with-gmp --with-mcrypt --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-libdir=lib64 &> /dev/null

ln -s /usr/local/lnmp/mysql/lib /usr/local/lnmp/mysql/lib64

make &> /dev/null 

make install &> /dev/null

 

#make test

cp /usr/local/lnmp/php/etc/php.ini-production /usr/local/lnmp/php/etc/php.ini

cp /mnt/php-5.3.6/sapi/fpm/php-fpm /etc/init.d/

chmod +x /etc/init.d/php-fpm

sed -i "843a cgi.fix_pathinfo=0" /usr/local/lnmp/php/etc/php.ini

sed -i "998a date.timezone = Asia/Shanghai" /usr/local/lnmp/php/etc/php.ini

sed -i " 152a pm.start_servers = 10 \n pm.min_spare_servers = 5 \n pm.max_spare_servers = 15 \n pm.max_requests = 500" /usr/local/lnmp/php/etc/php-fpm.conf

 

 

 

[[email protected] files]# 

技术分享 

技术分享 


以上是关于puppet 搭建lnmp架构的主要内容,如果未能解决你的问题,请参考以下文章

LNMP架构搭建与优化

LNMP架构搭建

lnmp 架构搭建

详述Linux系统中搭建LNMP架构+Discuz论坛

在LNMP架构中搭建zabbix监控服务!!!

LNMP架构基础搭建