{"id":34967,"date":"2024-09-11T14:31:39","date_gmt":"2024-09-11T07:31:39","guid":{"rendered":"http:\/\/jupitek.maudemo.vip\/index.php\/2024\/09\/11\/use-puppet-modules-to-create-a-lamp-stack\/"},"modified":"2024-09-11T14:31:39","modified_gmt":"2024-09-11T07:31:39","slug":"use-puppet-modules-to-create-a-lamp-stack","status":"publish","type":"post","link":"https:\/\/jupitek.maudemo.vip\/index.php\/2024\/09\/11\/use-puppet-modules-to-create-a-lamp-stack\/","title":{"rendered":"S\u1eed d\u1ee5ng Puppet Modules \u0111\u1ec3 t\u1ea1o LAMP Stack"},"content":{"rendered":"<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/Use_Puppet_Modules_to_Create_a_LAMP_Stack_smg_hub950f08959df95642c46525146bf5c5e_45014_1388x0_resize_q71_bgfafafc_catmullrom.jpg\" alt=\"S\u1eed d\u1ee5ng Puppet Modules \u0111\u1ec3 t\u1ea1o m\u1ed9t LAMP Stack\" title=\"S\u1eed d\u1ee5ng Puppet Modules \u0111\u1ec3 t\u1ea1o m\u1ed9t LAMP Stack\"\/><\/figure>\n<p>C\u00e1c m\u00f4-\u0111un Puppet l\u00e0 c\u00e1c kh\u1ed1i x\u00e2y d\u1ef1ng c\u1ee7a m\u00e1y ch\u1ee7 do Puppet qu\u1ea3n l\u00fd c\u1ee7a b\u1ea1n. C\u00e1c m\u00f4-\u0111un c\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh c\u00e1c g\u00f3i, t\u1ea1o th\u01b0 m\u1ee5c v\u00e0 t\u1ea1o b\u1ea5t k\u1ef3 thay \u0111\u1ed5i m\u00e1y ch\u1ee7 n\u00e0o kh\u00e1c m\u00e0 ng\u01b0\u1eddi d\u00f9ng \u0111\u01b0a v\u00e0o m\u00f4-\u0111un. M\u1ed9t m\u00f4-\u0111un Puppet nh\u1eb1m m\u1ee5c \u0111\u00edch th\u1ef1c hi\u1ec7n t\u1ea5t c\u1ea3 c\u00e1c ph\u1ea7n c\u1ee7a m\u1ed9t t\u00e1c v\u1ee5 nh\u1ea5t \u0111\u1ecbnh, ch\u1eb3ng h\u1ea1n nh\u01b0 t\u1ea3i xu\u1ed1ng g\u00f3i Apache, c\u1ea5u h\u00ecnh t\u1ea5t c\u1ea3 c\u00e1c t\u1ec7p, thay \u0111\u1ed5i d\u1eef li\u1ec7u MPM v\u00e0 thi\u1ebft l\u1eadp m\u00e1y ch\u1ee7 \u1ea3o. C\u00e1c m\u00f4-\u0111un, \u0111\u1ebfn l\u01b0\u1ee3t m\u00ecnh, \u0111\u01b0\u1ee3c chia th\u00e0nh c\u00e1c l\u1edbp l\u00e0&nbsp;<code>.pp<\/code>c\u00e1c t\u1ec7p nh\u1eb1m \u0111\u01a1n gi\u1ea3n h\u00f3a m\u00f4-\u0111un th\u00e0nh nhi\u1ec1u t\u00e1c v\u1ee5 kh\u00e1c nhau v\u00e0 c\u1ea3i thi\u1ec7n kh\u1ea3 n\u0103ng \u0111\u1ecdc c\u1ee7a m\u00f4-\u0111un cho b\u1ea5t k\u1ef3 ng\u01b0\u1eddi d\u00f9ng n\u00e0o trong t\u01b0\u01a1ng lai.<\/p>\n<p>Trong h\u01b0\u1edbng d\u1eabn n\u00e0y, b\u1ea1n s\u1ebd t\u1ea1o m\u1ed9t m\u00f4-\u0111un Apache v\u00e0 m\u1ed9t m\u00f4-\u0111un PHP. M\u1ed9t m\u00f4-\u0111un MySQL s\u1ebd \u0111\u01b0\u1ee3c \u0111i\u1ec1u ch\u1ec9nh t\u1eeb m\u00f4-\u0111un MySQL c\u1ee7a Puppet Lab c\u00f3 tr\u00ean&nbsp;<a href=\"https:\/\/forge.puppet.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Puppet Forge<\/a>&nbsp;. C\u00e1c b\u01b0\u1edbc n\u00e0y s\u1ebd t\u1ea1o m\u1ed9t ng\u0103n x\u1ebfp LAMP \u0111\u1ea7y \u0111\u1ee7 tr\u00ean m\u00e1y ch\u1ee7 c\u1ee7a b\u1ea1n v\u00e0 cung c\u1ea5p t\u1ed5ng quan v\u1ec1 c\u00e1c c\u00e1ch kh\u00e1c nhau \u0111\u1ec3 s\u1eed d\u1ee5ng c\u00e1c m\u00f4-\u0111un.<\/p>\n<h2 id=\"before-you-begin\">Tr\u01b0\u1edbc khi b\u1ea1n b\u1eaft \u0111\u1ea7u<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/#before-you-begin\"><\/a><\/h2>\n<p>Thi\u1ebft l\u1eadp m\u1ed9t Puppet Master (Ubuntu 18.04) v\u00e0 hai t\u00e1c nh\u00e2n Puppet (Ubuntu 18.04 v\u00e0 CentOS 7) b\u1eb1ng c\u00e1ch l\u00e0m theo c\u00e1c b\u01b0\u1edbc trong h\u01b0\u1edbng d\u1eabn&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/getting-started-with-puppet-6-1-basic-installation-and-setup\/\">B\u1eaft \u0111\u1ea7u v\u1edbi Puppet &#8211; C\u00e0i \u0111\u1eb7t v\u00e0 thi\u1ebft l\u1eadp c\u01a1 b\u1ea3n<\/a>&nbsp;.<\/p>\n<h2 id=\"create-the-apache-module\">T\u1ea1o m\u00f4-\u0111un Apache<\/h2>\n<p>1.T\u1eeb Puppet Master, \u0111i\u1ec1u h\u01b0\u1edbng \u0111\u1ebfn th\u01b0 m\u1ee5c m\u00f4-\u0111un c\u1ee7a Puppet v\u00e0 t\u1ea1o th\u01b0&nbsp;<code>apache<\/code>m\u1ee5c:<\/p>\n<pre class=\"wp-block-code\"><code><code>cd \/etc\/puppetlabs\/code\/environments\/production\/modules\/ sudo mkdir apache<\/code><\/code><\/pre>\n<p>2.T\u1eeb b\u00ean trong&nbsp;<code>apache<\/code>th\u01b0 m\u1ee5c, t\u1ea1o c\u00e1c th\u01b0 m\u1ee5c&nbsp;<code>manifests<\/code>,&nbsp;<code>templates<\/code>,&nbsp;<code>files<\/code>, v\u00e0&nbsp;<code>examples<\/code>:<\/p>\n<pre class=\"wp-block-code\"><code><code>cd apache sudo mkdir {manifests,templates,files,examples}<\/code><\/code><\/pre>\n<p>3.\u0110i\u1ec1u h\u01b0\u1edbng \u0111\u1ebfn th\u01b0&nbsp;<code>manifests<\/code>m\u1ee5c:<\/p>\n<pre class=\"wp-block-code\"><code><code>cd manifests<\/code><\/code><\/pre>\n<p>T\u1eeb \u0111\u00e2y, m\u00f4-\u0111un s\u1ebd \u0111\u01b0\u1ee3c t\u00e1ch th\u00e0nh c\u00e1c l\u1edbp, d\u1ef1a tr\u00ean m\u1ee5c ti\u00eau c\u1ee7a ph\u1ea7n m\u00e3 c\u1ee5 th\u1ec3 \u0111\u00f3. Trong tr\u01b0\u1eddng h\u1ee3p n\u00e0y, s\u1ebd c\u00f3 m\u1ed9t&nbsp;<code>init.pp<\/code>l\u1edbp \u0111\u1ec3 t\u1ea3i xu\u1ed1ng g\u00f3i Apache, m\u1ed9t&nbsp;<code>params.pp<\/code>t\u1ec7p \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh b\u1ea5t k\u1ef3 bi\u1ebfn v\u00e0 tham s\u1ed1 n\u00e0o,&nbsp;<code>config.pp<\/code>\u0111\u1ec3 qu\u1ea3n l\u00fd b\u1ea5t k\u1ef3 t\u1ec7p c\u1ea5u h\u00ecnh n\u00e0o cho ch\u00ednh d\u1ecbch v\u1ee5 Apache v\u00e0 m\u1ed9t&nbsp;<code>vhosts.pp<\/code>t\u1ec7p \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh m\u00e1y ch\u1ee7 \u1ea3o. M\u00f4-\u0111un n\u00e0y c\u0169ng s\u1ebd s\u1eed d\u1ee5ng d\u1eef li\u1ec7u&nbsp;<a href=\"http:\/\/docs.puppet.com\/hiera\/latest\/\" target=\"_blank\" rel=\"noreferrer noopener\">Hiera<\/a>&nbsp;\u0111\u1ec3 l\u01b0u tr\u1eef c\u00e1c bi\u1ebfn cho m\u1ed7i n\u00fat.<\/p>\n<h3 id=\"create-the-initial-apache-class-and-parameters\">T\u1ea1o l\u1edbp Apache ban \u0111\u1ea7u v\u00e0 c\u00e1c tham s\u1ed1<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/#create-the-initial-apache-class-and-parameters\"><\/a><\/h3>\n<p>1.T\u1eeb b\u00ean trong&nbsp;<code>manifests<\/code>th\u01b0 m\u1ee5c, t\u1ea1o m\u1ed9t&nbsp;<code>init.pp<\/code>t\u1ec7p \u0111\u1ec3 ch\u1ee9a&nbsp;<code>apache<\/code>l\u1edbp. L\u1edbp n\u00e0y s\u1ebd chia s\u1ebb t\u00ean c\u1ee7a n\u00f3 v\u1edbi t\u00ean m\u00f4-\u0111un. T\u1ec7p n\u00e0y s\u1ebd \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 c\u00e0i \u0111\u1eb7t g\u00f3i Apache. V\u00ec Ubuntu 18.04 v\u00e0 CentOS 7 s\u1eed d\u1ee5ng c\u00e1c t\u00ean g\u00f3i kh\u00e1c nhau cho Apache, n\u00ean m\u1ed9t bi\u1ebfn s\u1ebd \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng:<\/p>\n<pre class=\"wp-block-code\"><code>class apache {\n\n  package { 'apache':\n    name    =&gt; $apachename,\n    ensure  =&gt; present,\n  }\n\n}<\/code><\/pre>\n<p>T\u00e0i&nbsp;<code>package<\/code>nguy\u00ean cho ph\u00e9p qu\u1ea3n l\u00fd m\u1ed9t g\u00f3i. \u0110i\u1ec1u n\u00e0y \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 th\u00eam, x\u00f3a ho\u1eb7c \u0111\u1ea3m b\u1ea3o m\u1ed9t g\u00f3i hi\u1ec7n di\u1ec7n. Trong h\u1ea7u h\u1ebft c\u00e1c tr\u01b0\u1eddng h\u1ee3p, t\u00ean c\u1ee7a t\u00e0i nguy\u00ean (&nbsp;<code>apache<\/code>, \u1edf tr\u00ean) ph\u1ea3i l\u00e0 t\u00ean c\u1ee7a g\u00f3i \u0111ang \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd. Tuy nhi\u00ean, do s\u1ef1 kh\u00e1c bi\u1ec7t trong quy \u01b0\u1edbc \u0111\u1eb7t t\u00ean, t\u00e0i nguy\u00ean n\u00e0y ch\u1ec9 \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 , trong khi&nbsp;<em>t\u00ean<\/em><code>apache<\/code>&nbsp;th\u1ef1c t\u1ebf&nbsp;c\u1ee7a g\u00f3i \u0111\u01b0\u1ee3c g\u1ecdi b\u1eb1ng tham&nbsp;chi\u1ebfu.&nbsp;, trong tr\u01b0\u1eddng h\u1ee3p n\u00e0y, g\u1ecdi \u0111\u1ebfn bi\u1ebfn ch\u01b0a x\u00e1c \u0111\u1ecbnh&nbsp;.&nbsp;Tham chi\u1ebfu \u0111\u1ea3m b\u1ea3o r\u1eb1ng g\u00f3i l\u00e0&nbsp;.<em><\/em><code>name<\/code><code>name<\/code><code>$apachename<\/code><code>ensure<\/code><code>present<\/code><\/p>\n<p>T\u1ea1o&nbsp;<code>params.pp<\/code>v\u00e0 th\u00eam \u0111o\u1ea1n m\u00e3 sau:<\/p>\n<pre class=\"wp-block-code\"><code>class apache::params {\n\n  if $::osfamily == 'RedHat' {\n    $apachename   = 'httpd'\n  }\n  elsif $::osfamily == 'Debian' {\n      $apachename   = 'apache2'\n  }\n  else {\n    fail ( 'this is not a supported distro.')\n  }\n\n}<\/code><\/pre>\n<p>B\u00ean ngo\u00e0i&nbsp;<code>init.pp<\/code>l\u1edbp g\u1ed1c, m\u1ed7i t\u00ean l\u1edbp c\u1ea7n ph\u1ea3i ph\u00e2n nh\u00e1nh t\u1eeb&nbsp;<code>apache<\/code>. Do \u0111\u00f3, l\u1edbp n\u00e0y \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0&nbsp;<code>apache::params<\/code>. T\u00ean sau d\u1ea5u hai ch\u1ea5m k\u00e9p ph\u1ea3i chia s\u1ebb t\u00ean v\u1edbi t\u1ec7p.<\/p>\n<p>M\u1ed9t&nbsp;<code>if<\/code>c\u00e2u l\u1ec7nh \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh c\u00e1c tham s\u1ed1, l\u1ea5y th\u00f4ng tin do&nbsp;<a href=\"https:\/\/puppet.com\/docs\/puppet\/7\/facter.html\" target=\"_blank\" rel=\"noreferrer noopener\">Facter<\/a>&nbsp;cung c\u1ea5p , \u0111\u00e3 \u0111\u01b0\u1ee3c c\u00e0i \u0111\u1eb7t tr\u00ean m\u00e1y ch\u1ee7 Puppet. Trong tr\u01b0\u1eddng h\u1ee3p n\u00e0y, Facter s\u1ebd \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 k\u00e9o xu\u1ed1ng h\u1ecd h\u1ec7 \u0111i\u1ec1u h\u00e0nh (&nbsp;<code>osfamily<\/code>), \u0111\u1ec3 ph\u00e2n bi\u1ec7t xem n\u00f3 d\u1ef1a tr\u00ean Red Hat hay Debian.<\/p>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: Trong th\u1eddi gian c\u1ee7a h\u01b0\u1edbng d\u1eabn n\u00e0y, khi c\u1ea7n th\u00eam m\u1ed9t c\u00e1i g\u00ec \u0111\u00f3 v\u00e0o danh s\u00e1ch tham s\u1ed1, c\u00e1c bi\u1ebfn c\u1ea7n thi\u1ebft cho Red Hat v\u00e0 Debian s\u1ebd \u0111\u01b0\u1ee3c cung c\u1ea5p, nh\u01b0ng m\u00e3 m\u1edf r\u1ed9ng s\u1ebd kh\u00f4ng \u0111\u01b0\u1ee3c hi\u1ec3n th\u1ecb.&nbsp;<code>params.pp<\/code>C\u00f3 th\u1ec3 xem b\u1ea3n sao \u0111\u1ea7y \u0111\u1ee7&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/assets\/params.pp\">t\u1ea1i \u0111\u00e2y<\/a>&nbsp;.<\/p>\n<p>3.V\u1edbi c\u00e1c tham s\u1ed1 cu\u1ed1i c\u00f9ng \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh, ch\u00fang ta c\u1ea7n g\u1ecdi t\u1ec7p&nbsp;<code>params.pp<\/code>v\u00e0 c\u00e1c tham s\u1ed1 v\u00e0o&nbsp;<code>init.pp<\/code>. \u0110\u1ec3 l\u00e0m \u0111i\u1ec1u n\u00e0y, c\u00e1c tham s\u1ed1 c\u1ea7n \u0111\u01b0\u1ee3c th\u00eam v\u00e0o sau t\u00ean l\u1edbp, nh\u01b0ng tr\u01b0\u1edbc d\u1ea5u ngo\u1eb7c nh\u1ecdn m\u1edf (&nbsp;<code>{<\/code>):<\/p>\n<pre class=\"wp-block-code\"><code>class apache (\n  $apachename   = $::apache::params::apachename,\n) inherits ::apache::params {<\/code><\/pre>\n<p>Chu\u1ed7i gi\u00e1 tr\u1ecb&nbsp;<code>$::apache::params::value<\/code>y\u00eau c\u1ea7u Puppet l\u1ea5y c\u00e1c gi\u00e1 tr\u1ecb t\u1eeb c\u00e1c&nbsp;<code>apache<\/code>m\u00f4-\u0111un,&nbsp;<code>params<\/code>l\u1edbp, theo sau l\u00e0 t\u00ean tham s\u1ed1. \u0110o\u1ea1n m\u00e3&nbsp;<code>inherits ::apache::params<\/code>cho ph\u00e9p&nbsp;<code>init.pp<\/code>k\u1ebf th\u1eeba c\u00e1c gi\u00e1 tr\u1ecb n\u00e0y.<\/p>\n<h3 id=\"manage-configuration-files\">Qu\u1ea3n l\u00fd t\u1eadp tin c\u1ea5u h\u00ecnh<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/#manage-configuration-files\"><\/a><\/h3>\n<p>T\u1ec7p c\u1ea5u h\u00ecnh Apache s\u1ebd kh\u00e1c nhau t\u00f9y thu\u1ed9c v\u00e0o vi\u1ec7c b\u1ea1n \u0111ang l\u00e0m vi\u1ec7c tr\u00ean h\u1ec7 th\u1ed1ng d\u1ef1a tr\u00ean Red Hat hay Debian. B\u1ea1n c\u00f3 th\u1ec3 xem c\u00e1c t\u1ec7p n\u00e0y t\u1ea1i \u0111\u00e2y:&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/assets\/httpd.conf\">httpd.conf (Red Hat)<\/a>&nbsp;,&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/assets\/apache2.conf\">apache2.conf (Debian)<\/a>&nbsp;.<\/p>\n<p>1.Sao ch\u00e9p n\u1ed9i dung c\u1ee7a&nbsp;<code>httpd.conf<\/code>v\u00e0&nbsp;<code>apache2.conf<\/code>v\u00e0o c\u00e1c t\u1ec7p ri\u00eang bi\u1ec7t v\u00e0 l\u01b0u ch\u00fang v\u00e0o&nbsp;<code>files<\/code>th\u01b0 m\u1ee5c n\u1eb1m t\u1ea1i&nbsp;<code>\/etc\/puppetlabs\/code\/environments\/production\/modules\/apache\/files<\/code>.<\/p>\n<p>2.C\u1ea3 hai t\u1ec7p \u0111\u1ec1u c\u1ea7n \u0111\u01b0\u1ee3c ch\u1ec9nh s\u1eeda \u0111\u1ec3 v\u00f4 hi\u1ec7u h\u00f3a keepalive. B\u1ea1n s\u1ebd c\u1ea7n th\u00eam d\u00f2ng v\u00e0o&nbsp;<code>KeepAlive Off<\/code>t\u1ec7p&nbsp;<code>httpd.conf<\/code>. N\u1ebfu b\u1ea1n kh\u00f4ng mu\u1ed1n thay \u0111\u1ed5i c\u00e0i \u0111\u1eb7t n\u00e0y, h\u00e3y th\u00eam ch\u00fa th\u00edch v\u00e0o \u0111\u1ea7u m\u1ed7i t\u1ec7p:<\/p>\n<pre class=\"wp-block-code\"><code># This file is managed by Puppet<\/code><\/pre>\n<p>3.Th\u00eam c\u00e1c t\u1ec7p n\u00e0y v\u00e0o t\u1ec7p&nbsp;<code>init.pp<\/code>\u0111\u1ec3 Puppet bi\u1ebft ch\u00fang n\u1eb1m \u1edf \u0111\u00e2u tr\u00ean c\u1ea3 m\u00e1y ch\u1ee7 ch\u00ednh v\u00e0 c\u00e1c n\u00fat t\u00e1c nh\u00e2n. \u0110\u1ec3 th\u1ef1c hi\u1ec7n vi\u1ec7c n\u00e0y, t\u00e0i&nbsp;<code>file<\/code>nguy\u00ean \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng:<\/p>\n<pre class=\"wp-block-code\"><code>file { 'configuration-file':\n  path    =&gt; $conffile,\n  ensure  =&gt; file,\n  source  =&gt; $confsource,\n}<\/code><\/pre>\n<p>V\u00ec t\u1ec7p c\u1ea5u h\u00ecnh n\u1eb1m \u1edf hai v\u1ecb tr\u00ed kh\u00e1c nhau n\u00ean t\u00e0i nguy\u00ean \u0111\u01b0\u1ee3c \u0111\u1eb7t t\u00ean chung&nbsp;<code>configuration-file<\/code>v\u1edbi \u0111\u01b0\u1eddng d\u1eabn t\u1ec7p \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh l\u00e0 tham s\u1ed1 c\u00f3&nbsp;<code>path<\/code>thu\u1ed9c t\u00ednh .&nbsp;<code>ensure<\/code>\u0111\u1ea3m b\u1ea3o r\u1eb1ng \u0111\u00f3 l\u00e0 m\u1ed9t t\u1ec7p.&nbsp;<code>source<\/code>cung c\u1ea5p v\u1ecb tr\u00ed tr\u00ean m\u00e1y ch\u1ee7 Puppet c\u1ee7a c\u00e1c t\u1ec7p \u0111\u01b0\u1ee3c t\u1ea1o \u1edf tr\u00ean.<\/p>\n<p>4.M\u1edf&nbsp;<code>params.pp<\/code>t\u1ec7p. C\u00e1c bi\u1ebfn&nbsp;<code>$conffile<\/code>v\u00e0&nbsp;<code>$confsource<\/code>c\u1ea7n \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong&nbsp;<code>if<\/code>c\u00e2u l\u1ec7nh:<\/p>\n<pre class=\"wp-block-code\"><code>if $::osfamily == 'RedHat' {\n\n...\n\n  $conffile     = '\/etc\/httpd\/conf\/httpd.conf'\n  $confsource   = 'puppet:\/\/\/modules\/apache\/httpd.conf'\n}\nelsif $::osfamily == 'Debian' {\n\n...\n\n  $conffile     = '\/etc\/apache2\/apache2.conf'\n  $confsource   = 'puppet:\/\/\/modules\/apache\/apache2.conf'\n}\nelse {\n\n...<\/code><\/pre>\n<p>C\u00e1c tham s\u1ed1 n\u00e0y c\u0169ng c\u1ea7n \u0111\u01b0\u1ee3c th\u00eam v\u00e0o ph\u1ea7n \u0111\u1ea7u c\u1ee7a&nbsp;<code>apache<\/code>khai b\u00e1o l\u1edbp trong&nbsp;<code>init.pp<\/code>t\u1ec7p, t\u01b0\u01a1ng t\u1ef1 nh\u01b0 v\u00ed d\u1ee5 tr\u01b0\u1edbc.&nbsp;<code>init.pp<\/code>B\u1ea1n c\u00f3 th\u1ec3 xem b\u1ea3n sao \u0111\u1ea7y \u0111\u1ee7 c\u1ee7a t\u1ec7p&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/assets\/puppet_apacheinit.pp\">t\u1ea1i \u0111\u00e2y<\/a>&nbsp;\u0111\u1ec3 tham kh\u1ea3o.<\/p>\n<p>5.Khi t\u1ec7p c\u1ea5u h\u00ecnh \u0111\u01b0\u1ee3c thay \u0111\u1ed5i, Apache c\u1ea7n ph\u1ea3i kh\u1edfi \u0111\u1ed9ng l\u1ea1i. \u0110\u1ec3 t\u1ef1 \u0111\u1ed9ng h\u00f3a vi\u1ec7c n\u00e0y, t\u00e0i&nbsp;<code>service<\/code>nguy\u00ean c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng k\u1ebft h\u1ee3p v\u1edbi&nbsp;<code>notify<\/code>thu\u1ed9c t\u00ednh, s\u1ebd g\u1ecdi t\u00e0i nguy\u00ean \u0111\u1ec3 ch\u1ea1y b\u1ea5t c\u1ee9 khi n\u00e0o t\u1ec7p c\u1ea5u h\u00ecnh \u0111\u01b0\u1ee3c thay \u0111\u1ed5i:<\/p>\n<pre class=\"wp-block-code\"><code>file { 'configuration-file':\n  path    =&gt; $conffile,\n  ensure  =&gt; file,\n  source  =&gt; $confsource,\n  notify  =&gt; Service&#91;'apache-service'],\n}\n\nservice { 'apache-service':\n  name          =&gt; $apachename,\n  hasrestart    =&gt; true,\n}<\/code><\/pre>\n<p>T\u00e0i&nbsp;<code>service<\/code>nguy\u00ean s\u1eed d\u1ee5ng tham s\u1ed1 \u0111\u00e3 t\u1ea1o s\u1eb5n \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh t\u00ean Apache tr\u00ean h\u1ec7 th\u1ed1ng Red Hat v\u00e0 Debian. Thu\u1ed9c&nbsp;<code>hasrestart<\/code>t\u00ednh s\u1ebd k\u00edch ho\u1ea1t kh\u1edfi \u0111\u1ed9ng l\u1ea1i d\u1ecbch v\u1ee5 \u0111\u00e3 x\u00e1c \u0111\u1ecbnh.<\/p>\n<h3 id=\"create-the-virtual-hosts-files\">T\u1ea1o c\u00e1c t\u1eadp tin m\u00e1y ch\u1ee7 \u1ea3o<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/#create-the-virtual-hosts-files\"><\/a><\/h3>\n<p>T\u00f9y thu\u1ed9c v\u00e0o b\u1ea3n ph\u00e2n ph\u1ed1i h\u1ec7 th\u1ed1ng c\u1ee7a b\u1ea1n, c\u00e1c t\u1ec7p m\u00e1y ch\u1ee7 \u1ea3o s\u1ebd \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd kh\u00e1c nhau. Do \u0111\u00f3, m\u00e3 cho m\u00e1y ch\u1ee7 \u1ea3o s\u1ebd \u0111\u01b0\u1ee3c bao b\u1ecdc trong m\u1ed9t&nbsp;<code>if<\/code>c\u00e2u l\u1ec7nh, t\u01b0\u01a1ng t\u1ef1 nh\u01b0 c\u00e2u l\u1ec7nh \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong&nbsp;<code>params.pp<\/code>l\u1edbp nh\u01b0ng ch\u1ee9a c\u00e1c t\u00e0i nguy\u00ean Puppet th\u1ef1c t\u1ebf. \u0110i\u1ec1u n\u00e0y s\u1ebd cung c\u1ea5p m\u1ed9t v\u00ed d\u1ee5 v\u1ec1 c\u00e1ch s\u1eed d\u1ee5ng thay th\u1ebf&nbsp;<code>if<\/code>c\u00e1c c\u00e2u l\u1ec7nh trong m\u00e3 c\u1ee7a Puppet.<\/p>\n<p>1.T\u1eeb trong th\u01b0&nbsp;<code>apache\/manifests\/<\/code>m\u1ee5c, t\u1ea1o v\u00e0 m\u1edf m\u1ed9t&nbsp;<code>vhosts.pp<\/code>t\u1ec7p. Th\u00eam khung c\u1ee7a&nbsp;<code>if<\/code>c\u00e2u l\u1ec7nh:<\/p>\n<pre class=\"wp-block-code\"><code>class apache::vhosts {\n\n  if $::osfamily == 'RedHat' {\n\n  } elsif $::osfamily == 'Debian' {\n\n  } else {\n\n  }\n\n}<\/code><\/pre>\n<p>2.V\u1ecb tr\u00ed c\u1ee7a t\u1ec7p virtual hosts tr\u00ean m\u00e1y ch\u1ee7 CentOS 7 c\u1ee7a ch\u00fang t\u00f4i l\u00e0&nbsp;<code>\/etc\/httpd\/conf.d\/vhost.conf<\/code>. T\u1ec7p n\u00e0y s\u1ebd c\u1ea7n \u0111\u01b0\u1ee3c t\u1ea1o d\u01b0\u1edbi d\u1ea1ng m\u1eabu tr\u00ean Puppet master. C\u0169ng c\u1ea7n th\u1ef1c hi\u1ec7n t\u01b0\u01a1ng t\u1ef1 \u0111\u1ed1i v\u1edbi t\u1ec7p virtual hosts c\u1ee7a Ubuntu, n\u1eb1m t\u1ea1i&nbsp;<code>\/etc\/apache2\/sites-available\/example.com.conf<\/code>, thay th\u1ebf&nbsp;<code>example.com<\/code>b\u1eb1ng FQDN c\u1ee7a m\u00e1y ch\u1ee7. \u0110i\u1ec1u h\u01b0\u1edbng \u0111\u1ebfn&nbsp;<code>templates<\/code>t\u1ec7p trong&nbsp;<code>apache<\/code>m\u00f4-\u0111un, sau \u0111\u00f3 t\u1ea1o hai t\u1ec7p cho m\u00e1y ch\u1ee7 \u1ea3o c\u1ee7a b\u1ea1n:<\/p>\n<p>\u0110\u1ed1i v\u1edbi h\u1ec7 th\u1ed1ng Red Hat:<\/p>\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin\t&lt;%= @adminemail %&gt;\n    ServerName &lt;%= @servername %&gt;\n    ServerAlias www.&lt;%= @servername %&gt;\n    DocumentRoot \/var\/www\/&lt;%= @servername -%&gt;\/public_html\/\n    ErrorLog \/var\/www\/&lt;%- @servername -%&gt;\/logs\/error.log\n    CustomLog \/var\/www\/&lt;%= @servername -%&gt;\/logs\/access.log combined\n&lt;\/Virtual Host&gt;<\/code><\/pre>\n<p>\u0110\u1ed1i v\u1edbi h\u1ec7 th\u1ed1ng Debian:<\/p>\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin\t&lt;%= @adminemail %&gt;\n    ServerName &lt;%= @servername %&gt;\n    ServerAlias www.&lt;%= @servername %&gt;\n    DocumentRoot \/var\/www\/html\/&lt;%= @servername -%&gt;\/public_html\/\n    ErrorLog \/var\/www\/html\/&lt;%- @servername -%&gt;\/logs\/error.log\n    CustomLog \/var\/www\/html\/&lt;%= @servername -%&gt;\/logs\/access.log combined\n    &lt;Directory \/var\/www\/html\/&lt;%= @servername -%&gt;\/public_html&gt;\n        Require all granted\n    &lt;\/Directory&gt;\n&lt;\/Virtual Host&gt;<\/code><\/pre>\n<p>Ch\u1ec9 c\u00f3 hai bi\u1ebfn \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong c\u00e1c t\u1ec7p n\u00e0y:&nbsp;<code>adminemail<\/code>v\u00e0&nbsp;<code>servername<\/code>. Ch\u00fang s\u1ebd \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a theo t\u1eebng n\u00fat trong&nbsp;<code>site.pp<\/code>t\u1ec7p.<\/p>\n<p>3.Quay l\u1ea1i&nbsp;<code>vhosts.pp<\/code>t\u1ec7p. C\u00e1c m\u1eabu \u0111\u00e3 t\u1ea1o b\u00e2y gi\u1edd c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c tham chi\u1ebfu trong m\u00e3:<\/p>\n<pre class=\"wp-block-code\"><code>class apache::vhosts {\n\n  if $::osfamily == 'RedHat' {\n    file { '\/etc\/httpd\/conf.d\/vhost.conf':\n      ensure    =&gt; file,\n      content   =&gt; template('apache\/vhosts-rh.conf.erb'),\n    }\n  } elsif $::osfamily == 'Debian' {\n    file { \"\/etc\/apache2\/sites-available\/$servername.conf\":\n      ensure  =&gt; file,\n      content  =&gt; template('apache\/vhosts-deb.conf.erb'),\n    }\n  } else {\n      fail('This is not a supported distro.')\n  }\n\n}<\/code><\/pre>\n<p>C\u1ea3 hai h\u1ecd ph\u00e2n ph\u1ed1i \u0111\u1ec1u g\u1ecdi \u0111\u1ebfn&nbsp;<code>file<\/code>t\u00e0i nguy\u00ean v\u00e0 l\u1ea5y t\u00ean c\u1ee7a v\u1ecb tr\u00ed m\u00e1y ch\u1ee7 \u1ea3o tr\u00ean b\u1ea3n ph\u00e2n ph\u1ed1i t\u01b0\u01a1ng \u1ee9ng. \u0110\u1ed1i v\u1edbi Debian, \u0111i\u1ec1u n\u00e0y m\u1ed9t l\u1ea7n n\u1eefa c\u00f3 ngh\u0129a l\u00e0 tham chi\u1ebfu \u0111\u1ebfn gi\u00e1&nbsp;<code>$servername<\/code>tr\u1ecb.&nbsp;<code>content<\/code>Thu\u1ed9c t\u00ednh g\u1ecdi \u0111\u1ebfn c\u00e1c m\u1eabu t\u01b0\u01a1ng \u1ee9ng.<\/p>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: C\u00e1c gi\u00e1 tr\u1ecb ch\u1ee9a bi\u1ebfn, ch\u1eb3ng h\u1ea1n nh\u01b0 t\u00ean c\u1ee7a t\u00e0i nguy\u00ean t\u1ec7p Debian \u1edf tr\u00ean, c\u1ea7n \u0111\u01b0\u1ee3c \u0111\u1eb7t trong d\u1ea5u ngo\u1eb7c k\u00e9p (&nbsp;<code>\"<\/code>). B\u1ea5t k\u1ef3 bi\u1ebfn n\u00e0o trong d\u1ea5u ngo\u1eb7c \u0111\u01a1n (&nbsp;<code>'<\/code>) \u0111\u1ec1u \u0111\u01b0\u1ee3c ph\u00e2n t\u00edch c\u00fa ph\u00e1p ch\u00ednh x\u00e1c nh\u01b0 \u0111\u00e3 vi\u1ebft v\u00e0 s\u1ebd kh\u00f4ng k\u00e9o v\u00e0o m\u1ed9t bi\u1ebfn.<\/p>\n<p>4.C\u1ea3 hai t\u1ec7p m\u00e1y ch\u1ee7 \u1ea3o \u0111\u1ec1u tham chi\u1ebfu \u0111\u1ebfn hai th\u01b0 m\u1ee5c kh\u00f4ng c\u00f3 tr\u00ean h\u1ec7 th\u1ed1ng theo m\u1eb7c \u0111\u1ecbnh. Ch\u00fang c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c t\u1ea1o th\u00f4ng qua vi\u1ec7c s\u1eed d\u1ee5ng t\u00e0i&nbsp;<code>file<\/code>nguy\u00ean, m\u1ed7i th\u01b0 m\u1ee5c n\u1eb1m trong&nbsp;<code>if<\/code>c\u00e2u l\u1ec7nh.&nbsp;<code>vhosts.conf<\/code>T\u1ec7p ho\u00e0n ch\u1ec9nh s\u1ebd gi\u1ed1ng nh\u01b0 sau:<\/p>\n<pre class=\"wp-block-code\"><code>class apache::vhosts {\n\n  if $::osfamily == 'RedHat' {\n    file { '\/etc\/httpd\/conf.d\/vhost.conf':\n      ensure    =&gt; file,\n      content   =&gt; template('apache\/vhosts-rh.conf.erb'),\n    }\n    file { &#91; '\/var\/www\/$servername',\n             '\/var\/www\/$servername\/public_html',\n             '\/var\/www\/$servername\/log', ]:\n      ensure    =&gt; directory,\n    }\n  } elsif $::osfamily == 'Debian' {\n    file { \"\/etc\/apache2\/sites-available\/$servername.conf\":\n      ensure  =&gt; file,\n      content  =&gt; template('apache\/vhosts-deb.conf.erb'),\n    }\n    file { &#91; '\/var\/www\/$servername',\n             '\/var\/www\/$servername\/public_html',\n             '\/var\/www\/$servername\/logs', ]:\n      ensure    =&gt; directory,\n    }\n  } else {\n    fail ( 'This is not a supported distro.')\n  }\n\n}<\/code><\/pre>\n<h3 id=\"test-and-run-the-module\">Ki\u1ec3m tra v\u00e0 ch\u1ea1y m\u00f4-\u0111un<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/#test-and-run-the-module\"><\/a><\/h3>\n<p>1.T\u1eeb trong th\u01b0&nbsp;<code>apache\/manifests\/<\/code>m\u1ee5c, h\u00e3y ch\u1ea1y l\u1ec7nh&nbsp;<code>puppet parser<\/code>tr\u00ean t\u1ea5t c\u1ea3 c\u00e1c t\u1ec7p \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o m\u00e3 h\u00f3a Puppet kh\u00f4ng c\u00f3 l\u1ed7i:<\/p>\n<pre class=\"wp-block-code\"><code>sudo \/opt\/puppetlabs\/bin\/puppet parser validate init.pp params.pp vhosts.pp\n<\/code><\/pre>\n<p>K\u1ebft qu\u1ea3 s\u1ebd l\u00e0 r\u1ed7ng, tr\u1eeb khi c\u00f3 v\u1ea5n \u0111\u1ec1 g\u00ec x\u1ea3y ra.<\/p>\n<p>2.\u0110i\u1ec1u h\u01b0\u1edbng \u0111\u1ebfn&nbsp;<code>examples<\/code>th\u01b0 m\u1ee5c trong&nbsp;<code>apache<\/code>m\u00f4-\u0111un. T\u1ea1o m\u1ed9t&nbsp;<code>init.pp<\/code>t\u1ec7p v\u00e0 bao g\u1ed3m c\u00e1c l\u1edbp \u0111\u00e3 t\u1ea1o. Thay th\u1ebf c\u00e1c gi\u00e1 tr\u1ecb cho&nbsp;<code>$servername<\/code>v\u00e0&nbsp;<code>$adminemail<\/code>b\u1eb1ng gi\u00e1 tr\u1ecb c\u1ee7a ri\u00eang b\u1ea1n:<\/p>\n<pre class=\"wp-block-code\"><code>$serveremail = 'webmaster@example.com'\n$servername = 'example.com'\n\ninclude apache\ninclude apache::vhosts<\/code><\/pre>\n<p>3.Ki\u1ec3m tra m\u00f4-\u0111un b\u1eb1ng c\u00e1ch ch\u1ea1y&nbsp;<code>puppet apply<\/code>v\u1edbi&nbsp;<code>--noop<\/code>th\u1ebb:<\/p>\n<pre class=\"wp-block-code\"><code>sudo \/opt\/puppetlabs\/bin\/puppet apply --noop init.pp\n<\/code><\/pre>\n<p>N\u00f3 s\u1ebd kh\u00f4ng tr\u1ea3 v\u1ec1 l\u1ed7i n\u00e0o v\u00e0 \u0111\u1ea7u ra s\u1ebd k\u00edch ho\u1ea1t l\u00e0m m\u1edbi t\u1eeb c\u00e1c s\u1ef1 ki\u1ec7n. \u0110\u1ec3 c\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh apache tr\u00ean Puppet master, c\u00f3 th\u1ec3 ch\u1ea1y l\u1ea1i m\u00e0 kh\u00f4ng c\u1ea7n&nbsp;<code>--noop<\/code>, n\u1ebfu mu\u1ed1n.<\/p>\n<p>4.Quay l\u1ea1i th\u01b0 m\u1ee5c Puppet ch\u00ednh r\u1ed3i \u0111\u1ebfn th\u01b0&nbsp;<code>manifests<\/code>m\u1ee5c (&nbsp;<strong>kh\u00f4ng ph\u1ea3i<\/strong>&nbsp;th\u01b0 m\u1ee5c n\u1eb1m trong m\u00f4-\u0111un Apache).<\/p>\n<pre class=\"wp-block-code\"><code>cd \/etc\/puppetlabs\/code\/environments\/production\/manifests<\/code><\/pre>\n<p>N\u1ebfu b\u1ea1n \u0111ang ti\u1ebfp t\u1ee5c h\u01b0\u1edbng d\u1eabn n\u00e0y t\u1eeb h\u01b0\u1edbng d\u1eabn&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/getting-started-with-puppet-6-1-basic-installation-and-setup\/\">B\u1eaft \u0111\u1ea7u v\u1edbi Puppet &#8211; C\u00e0i \u0111\u1eb7t v\u00e0 thi\u1ebft l\u1eadp c\u01a1 b\u1ea3n<\/a>&nbsp;, b\u1ea1n s\u1ebd c\u00f3 m\u1ed9t&nbsp;<code>site.pp<\/code>t\u1ec7p \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ea1o. N\u1ebfu ch\u01b0a, h\u00e3y t\u1ea1o m\u1ed9t t\u1ec7p ngay b\u00e2y gi\u1edd.<\/p>\n<p>5.M\u1edf&nbsp;<code>site.pp<\/code>v\u00e0 bao g\u1ed3m m\u00f4-\u0111un Apache cho m\u1ed7i n\u00fat t\u00e1c nh\u00e2n. C\u0169ng nh\u1eadp c\u00e1c bi\u1ebfn cho c\u00e1c tham s\u1ed1&nbsp;<code>adminemail<\/code>v\u00e0&nbsp;<code>servername<\/code>. N\u1ebfu b\u1ea1n \u0111\u00e3 l\u00e0m theo h\u01b0\u1edbng d\u1eabn&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/getting-started-with-puppet-6-1-basic-installation-and-setup\/\">B\u1eaft \u0111\u1ea7u v\u1edbi Puppet &#8211; C\u00e0i \u0111\u1eb7t v\u00e0 thi\u1ebft l\u1eadp c\u01a1 b\u1ea3n<\/a>&nbsp;, c\u1ea5u h\u00ecnh m\u1ed9t n\u00fat \u0111\u01a1n trong \u0111\u00f3&nbsp;<code>site.pp<\/code>s\u1ebd gi\u1ed1ng nh\u01b0 sau:<\/p>\n<pre class=\"wp-block-code\"><code>node 'ubuntuhost.example.com' {\n  $adminemail = 'webmaster@example.com'\n  $servername = 'hostname.example.com'\n\n  include accounts\n  include apache\n  include apache::vhosts\n\n  resources { 'firewall':\n    purge =&gt; true,\n  }\n\n  Firewall {\n    before        =&gt; Class&#91;'firewall::post'],\n    require       =&gt; Class&#91;'firewall::pre'],\n  }\n\n  class { &#91;'firewall::pre', 'firewall::post']: }\n\n  }\n\nnode 'centoshost.example.com' {\n  $adminemail = 'webmaster@example.com'\n  $servername = 'hostname.example.com'\n\n  include accounts\n  include apache\n  include apache::vhosts\n\n  resources { 'firewall':\n    purge =&gt; true,\n  }\n\n  Firewall {\n    before        =&gt; Class&#91;'firewall::post'],\n    require       =&gt; Class&#91;'firewall::pre'],\n  }\n\n  class { &#91;'firewall::pre', 'firewall::post']: }\n\n  }\n\n    <\/code><\/pre>\n<p>N\u1ebfu b\u1ea1n kh\u00f4ng l\u00e0m theo h\u01b0\u1edbng d\u1eabn&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/getting-started-with-puppet-6-1-basic-installation-and-setup\/\">B\u1eaft \u0111\u1ea7u v\u1edbi Puppet &#8211; C\u00e0i \u0111\u1eb7t v\u00e0 thi\u1ebft l\u1eadp c\u01a1 b\u1ea3n<\/a>&nbsp;, th\u00ec&nbsp;<code>site.pp<\/code>t\u1ec7p c\u1ee7a b\u1ea1n s\u1ebd gi\u1ed1ng nh\u01b0 v\u00ed d\u1ee5 sau:<\/p>\n<pre class=\"wp-block-code\"><code>node 'ubupuppet.ip.linodeusercontent.com' {\n  $adminemail = 'webmaster@example.com'\n  $servername = 'hostname.example.com'\n\n  include apache\n  include apache::vhosts\n\n  }\n\nnode 'centospuppet.ip.linodeusercontent.com' {\n  $adminemail = 'webmaster@example.com'\n  $servername = 'hostname.example.com'\n\n  include apache\n  include apache::vhosts\n\n  }\n        <\/code><\/pre>\n<p>6.Theo m\u1eb7c \u0111\u1ecbnh, d\u1ecbch v\u1ee5 t\u00e1c nh\u00e2n Puppet tr\u00ean c\u00e1c n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd c\u1ee7a b\u1ea1n s\u1ebd t\u1ef1 \u0111\u1ed9ng ki\u1ec3m tra v\u1edbi m\u00e1y ch\u1ee7 sau m\u1ed7i 30 ph\u00fat v\u00e0 \u00e1p d\u1ee5ng b\u1ea5t k\u1ef3 c\u1ea5u h\u00ecnh m\u1edbi n\u00e0o t\u1eeb m\u00e1y ch\u1ee7. B\u1ea1n c\u0169ng c\u00f3 th\u1ec3 g\u1ecdi th\u1ee7 c\u00f4ng quy tr\u00ecnh t\u00e1c nh\u00e2n Puppet gi\u1eefa c\u00e1c l\u1ea7n ch\u1ea1y t\u00e1c nh\u00e2n t\u1ef1 \u0111\u1ed9ng. \u0110\u1ec3 ch\u1ea1y th\u1ee7 c\u00f4ng m\u00f4-\u0111un m\u1edbi tr\u00ean c\u00e1c n\u00fat t\u00e1c nh\u00e2n c\u1ee7a b\u1ea1n, h\u00e3y \u0111\u0103ng nh\u1eadp v\u00e0o c\u00e1c n\u00fat v\u00e0 ch\u1ea1y:<\/p>\n<pre class=\"wp-block-code\"><code>sudo \/opt\/puppetlabs\/bin\/puppet agent -t<\/code><\/pre>\n<h2 id=\"using-the-mysql-module\">S\u1eed d\u1ee5ng M\u00f4-\u0111un MySQL<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/#using-the-mysql-module\"><\/a><\/h2>\n<p>Nhi\u1ec1u m\u00f4-\u0111un c\u1ea7n thi\u1ebft \u0111\u1ec3 ch\u1ea1y m\u00e1y ch\u1ee7 \u0111\u00e3 t\u1ed3n t\u1ea1i trong&nbsp;<a href=\"https:\/\/forge.puppet.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Puppet Forge<\/a>&nbsp;c\u1ee7a Puppet Labs . Ch\u00fang c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c c\u1ea5u h\u00ecnh chi ti\u1ebft nh\u01b0 m\u1ed9t m\u00f4-\u0111un m\u00e0 b\u1ea1n \u0111\u00e3 t\u1ea1o v\u00e0 c\u00f3 th\u1ec3 ti\u1ebft ki\u1ec7m th\u1eddi gian v\u00ec m\u00f4-\u0111un kh\u00f4ng c\u1ea7n ph\u1ea3i \u0111\u01b0\u1ee3c t\u1ea1o t\u1eeb \u0111\u1ea7u.<\/p>\n<p>\u0110\u1ea3m b\u1ea3o b\u1ea1n \u0111ang \u1edf trong&nbsp;<code>\/etc\/puppetlabs\/code\/environments\/production\/modules<\/code>th\u01b0 m\u1ee5c v\u00e0 c\u00e0i \u0111\u1eb7t&nbsp;<a href=\"https:\/\/forge.puppet.com\/puppetlabs\/mysql\" target=\"_blank\" rel=\"noreferrer noopener\">m\u00f4-\u0111un MySQL c\u1ee7a Puppet Forge<\/a>&nbsp;c\u1ee7a PuppetLabs. Thao t\u00e1c n\u00e0y c\u0169ng s\u1ebd c\u00e0i \u0111\u1eb7t b\u1ea5t k\u1ef3 m\u00f4-\u0111un ti\u00ean quy\u1ebft n\u00e0o.<\/p>\n<pre class=\"wp-block-code\"><code>cd \/etc\/puppetlabs\/code\/environments\/production\/modules\nsudo \/opt\/puppetlabs\/bin\/puppet module install puppetlabs-mysql\n<\/code><\/pre>\n<h3 id=\"use-hiera-to-create-databases\">S\u1eed d\u1ee5ng Hiera \u0111\u1ec3 t\u1ea1o c\u01a1 s\u1edf d\u1eef li\u1ec7u<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/#use-hiera-to-create-databases\"><\/a><\/h3>\n<p>Tr\u01b0\u1edbc khi b\u1ea1n b\u1eaft \u0111\u1ea7u t\u1ea1o c\u00e1c t\u1ec7p c\u1ea5u h\u00ecnh cho m\u00f4-\u0111un MySQL, h\u00e3y c\u00e2n nh\u1eafc r\u1eb1ng b\u1ea1n c\u00f3 th\u1ec3 kh\u00f4ng mu\u1ed1n s\u1eed d\u1ee5ng c\u00f9ng m\u1ed9t gi\u00e1 tr\u1ecb tr\u00ean t\u1ea5t c\u1ea3 c\u00e1c n\u00fat t\u00e1c nh\u00e2n. \u0110\u1ec3 cung c\u1ea5p cho Puppet d\u1eef li\u1ec7u ch\u00ednh x\u00e1c cho m\u1ed7i n\u00fat, Hiera \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng. Trong tr\u01b0\u1eddng h\u1ee3p n\u00e0y, b\u1ea1n s\u1ebd s\u1eed d\u1ee5ng m\u1eadt kh\u1ea9u g\u1ed1c kh\u00e1c nhau cho m\u1ed7i n\u00fat, do \u0111\u00f3 t\u1ea1o ra c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u MySQL kh\u00e1c nhau.<\/p>\n<p>1.\u0110i\u1ec1u h\u01b0\u1edbng \u0111\u1ebfn&nbsp;<code>\/etc\/puppet<\/code>v\u00e0 t\u1ea1o t\u1ec7p c\u1ea5u h\u00ecnh Hiera&nbsp;<code>hiera.yaml<\/code>trong th\u01b0 m\u1ee5c ch\u00ednh&nbsp;<code>puppet<\/code>. B\u1ea1n s\u1ebd s\u1eed d\u1ee5ng c\u00e1c gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh c\u1ee7a Hiera:<\/p>\n<pre class=\"wp-block-code\"><code>---\nversion: 5\nhierarchy:\n  - name: Common\n    path: common.yaml\ndefaults:\n  data_hash: yaml_data\n  datadir: data<\/code><\/pre>\n<p>2.T\u1ea1o file&nbsp;<code>common.yaml<\/code>. File n\u00e0y s\u1ebd \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh&nbsp;<code>root<\/code>m\u1eadt kh\u1ea9u m\u1eb7c \u0111\u1ecbnh cho MySQL:<\/p>\n<pre class=\"wp-block-code\"><code>mysql::server::root_password: 'password'<\/code><\/pre>\n<p>T\u1ec7p&nbsp;<code>common.yaml<\/code>\u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng khi m\u1ed9t bi\u1ebfn kh\u00f4ng \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a \u1edf n\u01a1i kh\u00e1c. \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 t\u1ea5t c\u1ea3 c\u00e1c m\u00e1y ch\u1ee7 s\u1ebd chia s\u1ebb c\u00f9ng m\u1ed9t m\u1eadt kh\u1ea9u g\u1ed1c MySQL. Nh\u1eefng m\u1eadt kh\u1ea9u n\u00e0y c\u0169ng c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c b\u0103m \u0111\u1ec3 t\u0103ng t\u00ednh b\u1ea3o m\u1eadt.<\/p>\n<p>3.\u0110\u1ec3 s\u1eed d\u1ee5ng c\u00e1c gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh c\u1ee7a m\u00f4-\u0111un MySQL, b\u1ea1n ch\u1ec9 c\u1ea7n th\u00eam m\u1ed9t&nbsp;<code>include '::mysql::server'<\/code>d\u00f2ng v\u00e0o&nbsp;<code>site.pp<\/code>t\u1ec7p. Tuy nhi\u00ean, trong v\u00ed d\u1ee5 n\u00e0y, b\u1ea1n s\u1ebd ghi \u0111\u00e8 m\u1ed9t s\u1ed1 gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh c\u1ee7a m\u00f4-\u0111un \u0111\u1ec3 t\u1ea1o c\u01a1 s\u1edf d\u1eef li\u1ec7u cho t\u1eebng n\u00fat c\u1ee7a m\u00ecnh. Ch\u1ec9nh s\u1eeda&nbsp;<code>site.pp<\/code>t\u1ec7p v\u1edbi c\u00e1c gi\u00e1 tr\u1ecb sau:<\/p>\n<pre class=\"wp-block-code\"><code>node 'ubupuppet.ip.linodeusercontent.com' {\n  $adminemail = 'webmaster@example.com'\n  $servername = 'hostname.example.com'\n\n  include apache\n  include apache::vhosts\n  include php\n\n  mysql::db { \"mydb_${fqdn}\":\n    user     =&gt; 'myuser',\n    password =&gt; 'mypass',\n    dbname   =&gt; 'mydb',\n    host     =&gt; $::fqdn,\n    grant    =&gt; &#91;'SELECT', 'UPDATE'],\n    tag      =&gt; $domain,\n  }\n\n}\n\nnode 'centospuppet.ip.linodeusercontent.com' {\n  $adminemail = 'webmaster@example.com'\n  $servername = 'hostname.example.com'\n\n  include apache\n  include apache::vhosts\n  include mysql::server\n  include php\n\n  mysql::db { \"mydb_${fqdn}\":\n    user     =&gt; 'myuser',\n    password =&gt; 'mypass',\n    dbname   =&gt; 'mydb',\n    host     =&gt; $::fqdn,\n    grant    =&gt; &#91;'SELECT', 'UPDATE'],\n    tag      =&gt; $domain,\n  }\n\n }\n    <\/code><\/pre>\n<p>4.B\u1ea1n c\u00f3 th\u1ec3 ch\u1ea1y c\u00e1c b\u1ea3n c\u1eadp nh\u1eadt n\u00e0y theo c\u00e1ch th\u1ee7 c\u00f4ng tr\u00ean t\u1eebng n\u00fat b\u1eb1ng c\u00e1ch SSH v\u00e0o t\u1eebng n\u00fat v\u00e0 \u0111\u01b0a ra l\u1ec7nh sau:<\/p>\n<pre class=\"wp-block-code\"><code> sudo \/opt\/puppetlabs\/bin\/puppet agent -t\n<\/code><\/pre>\n<p>N\u1ebfu kh\u00f4ng, d\u1ecbch v\u1ee5 t\u00e1c nh\u00e2n Puppet tr\u00ean c\u00e1c n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd c\u1ee7a b\u1ea1n s\u1ebd t\u1ef1 \u0111\u1ed9ng ki\u1ec3m tra v\u1edbi m\u00e1y ch\u1ee7 ch\u00ednh sau m\u1ed7i 30 ph\u00fat v\u00e0 \u00e1p d\u1ee5ng m\u1ecdi c\u1ea5u h\u00ecnh m\u1edbi t\u1eeb m\u00e1y ch\u1ee7 ch\u00ednh.<\/p>\n<h2 id=\"create-the-php-module\">T\u1ea1o Module PHP<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/#create-the-php-module\"><\/a><\/h2>\n<p>1.T\u1ea1o&nbsp;<code>php<\/code>th\u01b0 m\u1ee5c trong&nbsp;<code>\/etc\/puppetlabs\/code\/environments\/production\/modules<\/code>\u0111\u01b0\u1eddng d\u1eabn v\u00e0 t\u1ea1o c\u00e1c th\u01b0 m\u1ee5c&nbsp;<code>files<\/code>,&nbsp;<code>manifests<\/code>,&nbsp;<code>templates<\/code>, v\u00e0&nbsp;<code>examples<\/code>sau \u0111\u00f3:<\/p>\n<pre class=\"wp-block-code\"><code>sudo mkdir php\ncd php\nsudo mkdir {files,manifests,examples,templates}<\/code><\/pre>\n<p>2.T\u1ea1o&nbsp;<code>init.pp<\/code>. T\u1ec7p n\u00e0y s\u1ebd s\u1eed d\u1ee5ng&nbsp;<code>package<\/code>t\u00e0i nguy\u00ean \u0111\u1ec3 c\u00e0i \u0111\u1eb7t PHP. Hai g\u00f3i s\u1ebd \u0111\u01b0\u1ee3c c\u00e0i \u0111\u1eb7t: G\u00f3i PHP v\u00e0 kho l\u01b0u tr\u1eef \u1ee9ng d\u1ee5ng v\u00e0 ti\u1ec7n \u00edch m\u1edf r\u1ed9ng PHP. Th\u00eam n\u1ed9i dung sau v\u00e0o t\u1ec7p c\u1ee7a b\u1ea1n:<\/p>\n<pre class=\"wp-block-code\"><code>class php {\n\n  package { 'php':\n    name: $phpname,\n    ensure: present,\n  }\n\n  package { 'php-pear':\n    ensure: present,\n  }\n\n}<\/code><\/pre>\n<p>3.Th\u00eam&nbsp;<code>include php<\/code>v\u00e0o m\u00e1y ch\u1ee7 trong&nbsp;<code>sites.pp<\/code>t\u1ec7p c\u1ee7a b\u1ea1n:<\/p>\n<pre class=\"wp-block-code\"><code>    node 'ubupuppet.ip.linodeusercontent.com' {\n      $adminemail = 'webmaster@example.com'\n      $servername = 'hostname.example.com'\n\n      include apache\n      include apache::vhosts\n      include mysql::database\n      include php\n\n      }\n\n    node 'centospuppet.ip.linodeusercontent.com' {\n      $adminemail = 'webmaster@example.com'\n      $servername = 'hostname.example.com'\n\n      include apache\n      include apache::vhosts\n      include mysql::database\n      include php\n\n      }\n    <\/code><\/pre>\n<p>4.Ch\u1ea1y l\u1ec7nh sau tr\u00ean c\u00e1c n\u00fat t\u00e1c nh\u00e2n c\u1ee7a b\u1ea1n \u0111\u1ec3 k\u00e9o b\u1ea5t k\u1ef3 thay \u0111\u1ed5i n\u00e0o v\u00e0o m\u00e1y ch\u1ee7 c\u1ee7a b\u1ea1n.<\/p>\n<pre class=\"wp-block-code\"><code>sudo \/opt\/puppetlabs\/bin\/puppet agent -t\n<\/code><\/pre>\n<p>N\u1ebfu kh\u00f4ng, d\u1ecbch v\u1ee5 t\u00e1c nh\u00e2n Puppet tr\u00ean c\u00e1c n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd c\u1ee7a b\u1ea1n s\u1ebd t\u1ef1 \u0111\u1ed9ng ki\u1ec3m tra v\u1edbi m\u00e1y ch\u1ee7 ch\u00ednh sau m\u1ed7i 30 ph\u00fat v\u00e0 \u00e1p d\u1ee5ng m\u1ecdi c\u1ea5u h\u00ecnh m\u1edbi t\u1eeb m\u00e1y ch\u1ee7 ch\u00ednh.<\/p>\n<p>B\u00e2y gi\u1edd b\u1ea1n s\u1ebd c\u00f3 m\u1ed9t ng\u0103n x\u1ebfp LAMP ho\u1ea1t \u0111\u1ed9ng \u0111\u1ea7y \u0111\u1ee7 tr\u00ean m\u1ed7i n\u00fat do Puppet qu\u1ea3n l\u00fd.<\/p>\n<p>Ngu\u1ed3n: https:\/\/www.linode.com\/docs\/guides\/use-puppet-modules-to-create-a-lamp-stack-ubuntu-18-04-master\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C\u00e1c m\u00f4-\u0111un Puppet l\u00e0 c\u00e1c kh\u1ed1i x\u00e2y d\u1ef1ng c\u1ee7a m\u00e1y ch\u1ee7 do Puppet qu\u1ea3n l\u00fd c\u1ee7a b\u1ea1n. C\u00e1c m\u00f4-\u0111un c\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh c\u00e1c g\u00f3i, t\u1ea1o th\u01b0 m\u1ee5c v\u00e0 t\u1ea1o b\u1ea5t k\u1ef3 thay \u0111\u1ed5i m\u00e1y ch\u1ee7 n\u00e0o kh\u00e1c m\u00e0 ng\u01b0\u1eddi d\u00f9ng \u0111\u01b0a v\u00e0o m\u00f4-\u0111un. M\u1ed9t m\u00f4-\u0111un Puppet nh\u1eb1m m\u1ee5c \u0111\u00edch th\u1ef1c hi\u1ec7n t\u1ea5t c\u1ea3<\/p>\n","protected":false},"author":1,"featured_media":35988,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[],"class_list":["post-34967","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-puppet"],"_links":{"self":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts\/34967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/comments?post=34967"}],"version-history":[{"count":0,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts\/34967\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/media\/35988"}],"wp:attachment":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/media?parent=34967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/categories?post=34967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/tags?post=34967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}