{"id":34966,"date":"2024-09-11T10:51:29","date_gmt":"2024-09-11T03:51:29","guid":{"rendered":"http:\/\/jupitek.maudemo.vip\/index.php\/2024\/09\/11\/manage-mysql-database-with-puppet-hiera-on-ubuntu-18-04\/"},"modified":"2024-09-11T10:51:29","modified_gmt":"2024-09-11T03:51:29","slug":"manage-mysql-database-with-puppet-hiera-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/jupitek.maudemo.vip\/index.php\/2024\/09\/11\/manage-mysql-database-with-puppet-hiera-on-ubuntu-18-04\/","title":{"rendered":"Qu\u1ea3n l\u00fd MySQL Database v\u1edbi Puppet Hiera tr\u00ean Ubuntu 18.04"},"content":{"rendered":"<p><a href=\"https:\/\/puppet.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Puppet<\/a>&nbsp;l\u00e0 m\u1ed9t h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c s\u1eed d\u1ee5ng v\u00e0 tri\u1ec3n khai c\u00e1c lo\u1ea1i ph\u1ea7n m\u1ec1m kh\u00e1c nhau, gi\u00fap qu\u1ea3n tr\u1ecb h\u1ec7 th\u1ed1ng \u0111\u00e1ng tin c\u1eady v\u00e0 c\u00f3 th\u1ec3 sao ch\u00e9p \u0111\u01b0\u1ee3c h\u01a1n. Trong h\u01b0\u1edbng d\u1eabn n\u00e0y, ch\u00fang t\u00f4i s\u1eed d\u1ee5ng Puppet \u0111\u1ec3 qu\u1ea3n l\u00fd c\u00e0i \u0111\u1eb7t&nbsp;<a href=\"https:\/\/www.mysql.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL<\/a>&nbsp;, m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 ph\u1ed5 bi\u1ebfn \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng cho c\u00e1c \u1ee9ng d\u1ee5ng nh\u01b0 WordPress, Ruby on Rails v\u00e0 c\u00e1c \u1ee9ng d\u1ee5ng kh\u00e1c.&nbsp;<a href=\"https:\/\/docs.puppet.com\/hiera\/\" target=\"_blank\" rel=\"noreferrer noopener\">Hiera<\/a>&nbsp;l\u00e0 ph\u01b0\u01a1ng ph\u00e1p x\u00e1c \u0111\u1ecbnh gi\u00e1 tr\u1ecb c\u1ea5u h\u00ecnh m\u00e0 Puppet s\u1ebd s\u1eed d\u1ee5ng \u0111\u1ec3 \u0111\u01a1n gi\u1ea3n h\u00f3a c\u1ea5u h\u00ecnh MySQL.<\/p>\n<p>Trong h\u01b0\u1edbng d\u1eabn n\u00e0y, b\u1ea1n s\u1ebd s\u1eed d\u1ee5ng Puppet \u0111\u1ec3 tri\u1ec3n khai&nbsp;<a href=\"https:\/\/docs.puppet.com\/puppet\/latest\/modules_fundamentals.html\" target=\"_blank\" rel=\"noreferrer noopener\">c\u00e1c m\u00f4-\u0111un<\/a>&nbsp;tr\u00ean m\u00e1y ch\u1ee7 c\u1ee7a m\u00ecnh. Cu\u1ed1i c\u00f9ng, b\u1ea1n s\u1ebd c\u00e0i \u0111\u1eb7t, c\u1ea5u h\u00ecnh v\u00e0 s\u1eb5n s\u00e0ng s\u1eed d\u1ee5ng MySQL cho nhi\u1ec1u \u1ee9ng d\u1ee5ng kh\u00e1c nhau y\u00eau c\u1ea7u c\u01a1 s\u1edf d\u1eef li\u1ec7u ph\u1ee5 tr\u1ee3.<\/p>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: H\u01b0\u1edbng d\u1eabn n\u00e0y \u0111\u01b0\u1ee3c vi\u1ebft cho ng\u01b0\u1eddi d\u00f9ng kh\u00f4ng ph\u1ea3i root. C\u00e1c l\u1ec7nh y\u00eau c\u1ea7u quy\u1ec1n n\u00e2ng cao \u0111\u01b0\u1ee3c th\u00eam ti\u1ec1n t\u1ed1&nbsp;<code>sudo<\/code>. N\u1ebfu b\u1ea1n kh\u00f4ng quen v\u1edbi&nbsp;<code>sudo<\/code>l\u1ec7nh n\u00e0y, h\u00e3y xem h\u01b0\u1edbng d\u1eabn&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/linux-users-and-groups\/\">Ng\u01b0\u1eddi d\u00f9ng v\u00e0 Nh\u00f3m<\/a>&nbsp;.<\/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\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#before-you-begin\"><\/a><\/h2>\n<ol>\n<li>N\u1ebfu b\u1ea1n ch\u01b0a th\u1ef1c hi\u1ec7n, h\u00e3y t\u1ea1o m\u1ed9t t\u00e0i kho\u1ea3n Linode v\u00e0 Compute Instance. Xem h\u01b0\u1edbng d\u1eabn&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/products\/platform\/get-started\/\">B\u1eaft \u0111\u1ea7u v\u1edbi Linode<\/a>&nbsp;v\u00e0&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/products\/compute\/compute-instances\/guides\/create\/\">T\u1ea1o Compute Instance<\/a>&nbsp;c\u1ee7a ch\u00fang t\u00f4i .<\/li>\n<li>L\u00e0m theo h\u01b0\u1edbng d\u1eabn&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/products\/compute\/compute-instances\/guides\/set-up-and-secure\/\">Thi\u1ebft l\u1eadp v\u00e0 B\u1ea3o m\u1eadt Phi\u00ean b\u1ea3n Compute<\/a>&nbsp;c\u1ee7a ch\u00fang t\u00f4i \u0111\u1ec3 c\u1eadp nh\u1eadt h\u1ec7 th\u1ed1ng c\u1ee7a b\u1ea1n. B\u1ea1n c\u0169ng c\u00f3 th\u1ec3 mu\u1ed1n \u0111\u1eb7t m\u00fai gi\u1edd, c\u1ea5u h\u00ecnh t\u00ean m\u00e1y ch\u1ee7, t\u1ea1o t\u00e0i kho\u1ea3n ng\u01b0\u1eddi d\u00f9ng gi\u1edbi h\u1ea1n v\u00e0 t\u0103ng c\u01b0\u1eddng quy\u1ec1n truy c\u1eadp SSH.<\/li>\n<\/ol>\n<h2 id=\"install-and-configure-puppet\">C\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh Puppet<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#install-and-configure-puppet\"><\/a><\/h2>\n<p>Th\u1ef1c hi\u1ec7n theo c\u00e1c b\u01b0\u1edbc sau \u0111\u1ec3 thi\u1ebft l\u1eadp Puppet cho tri\u1ec3n khai c\u1ee5c b\u1ed9, ch\u1ec9 tr\u00ean m\u1ed9t m\u00e1y ch\u1ee7. N\u1ebfu b\u1ea1n c\u1ea7n c\u1ea5u h\u00ecnh nhi\u1ec1u h\u01a1n m\u1ed9t m\u00e1y ch\u1ee7 ho\u1eb7c tri\u1ec3n khai Puppet master, h\u00e3y l\u00e0m theo&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-configure-puppet\/\">h\u01b0\u1edbng d\u1eabn Puppet \u0111a m\u00e1y ch\u1ee7<\/a>&nbsp;c\u1ee7a ch\u00fang t\u00f4i .<\/p>\n<h3 id=\"install-the-puppet-package\">C\u00e0i \u0111\u1eb7t g\u00f3i Puppet<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#install-the-puppet-package\"><\/a><\/h3>\n<p>1.C\u00e0i \u0111\u1eb7t&nbsp;<code>puppetlabs-release-bionic<\/code>kho l\u01b0u tr\u1eef \u0111\u1ec3 th\u00eam c\u00e1c g\u00f3i Puppet:<\/p>\n<pre class=\"wp-block-code\"><code><code>wget https:\/\/apt.puppet.com\/puppet-release-bionic.deb sudo dpkg -i puppet-release-bionic.deb<\/code><\/code><\/pre>\n<p>2.C\u1eadp nh\u1eadt ch\u1ec9 m\u1ee5c g\u00f3i apt \u0111\u1ec3 l\u00e0m cho c\u00e1c g\u00f3i kho l\u01b0u tr\u1eef Puppet Labs kh\u1ea3 d\u1ee5ng, sau \u0111\u00f3 c\u00e0i \u0111\u1eb7t Puppet. Thao t\u00e1c n\u00e0y s\u1ebd c\u00e0i \u0111\u1eb7t g\u00f3i&nbsp;<code>puppet-agent<\/code>, cung c\u1ea5p&nbsp;<code>puppet<\/code>t\u1ec7p th\u1ef1c thi b\u00ean trong trong m\u00f4i tr\u01b0\u1eddng Ruby t\u01b0\u01a1ng th\u00edch:<\/p>\n<pre class=\"wp-block-code\"><code><code>sudo apt update &amp;&amp; sudo apt install puppet-agent<\/code><\/code><\/pre>\n<p>3.X\u00e1c nh\u1eadn phi\u00ean b\u1ea3n Puppet \u0111\u00e3 c\u00e0i \u0111\u1eb7t:<\/p>\n<pre class=\"wp-block-code\"><code><code>puppet --version <\/code><\/code><\/pre>\n<p>T\u1ea1i th\u1eddi \u0111i\u1ec3m vi\u1ebft b\u00e0i n\u00e0y, phi\u00ean b\u1ea3n Puppet l\u00e0&nbsp;<code>6.1.0<\/code>.<\/p>\n<h3 id=\"install-the-puppet-mysql-module\">C\u00e0i \u0111\u1eb7t M\u00f4-\u0111un Puppet MySQL<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#install-the-puppet-mysql-module\"><\/a><\/h3>\n<p><a href=\"https:\/\/forge.puppet.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Puppet Forge<\/a>&nbsp;l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p&nbsp;<em>c\u00e1c m\u00f4-\u0111un<\/em>&nbsp;h\u1ed7 tr\u1ee3 c\u00e0i \u0111\u1eb7t c\u00e1c lo\u1ea1i ph\u1ea7n m\u1ec1m kh\u00e1c nhau.&nbsp;<a href=\"https:\/\/forge.puppet.com\/puppetlabs\/mysql\" target=\"_blank\" rel=\"noreferrer noopener\">M\u00f4-\u0111un MySQL<\/a>&nbsp;x\u1eed l\u00fd vi\u1ec7c c\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh MySQL m\u00e0 kh\u00f4ng c\u1ea7n b\u1ea1n ph\u1ea3i qu\u1ea3n l\u00fd th\u1ee7 c\u00f4ng nhi\u1ec1u t\u1ec7p c\u1ea5u h\u00ecnh v\u00e0 d\u1ecbch v\u1ee5.<\/p>\n<p>C\u00e0i \u0111\u1eb7t m\u00f4-\u0111un MySQL:<\/p>\n<pre class=\"wp-block-code\"><code><code>sudo puppet module install puppetlabs-mysql --version 7.0.0 <\/code><\/code><\/pre>\n<p>Thao t\u00e1c n\u00e0y s\u1ebd c\u00e0i \u0111\u1eb7t&nbsp;<code>mysql<\/code>m\u00f4-\u0111un v\u00e0o \u0111\u01b0\u1eddng d\u1eabn m\u1eb7c \u0111\u1ecbnh:&nbsp;<code>\/etc\/puppetlabs\/code\/environments\/production\/modules\/<\/code>.<\/p>\n<h3 id=\"puppet-mysql-manifest\">B\u1ea3n k\u00ea khai MySQL c\u1ee7a Puppet<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#puppet-mysql-manifest\"><\/a><\/h3>\n<p>H\u01b0\u1edbng d\u1eabn n\u00e0y s\u1eed d\u1ee5ng Puppet&nbsp;<em>manifest<\/em>&nbsp;\u0111\u1ec3 cung c\u1ea5p cho Puppet h\u01b0\u1edbng d\u1eabn c\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh. Ngo\u00e0i ra, b\u1ea1n c\u00f3 th\u1ec3 c\u1ea5u h\u00ecnh&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-configure-puppet\/\">Puppet master<\/a>&nbsp;.<\/p>\n<p>Trong khi to\u00e0n b\u1ed9 b\u1ea3n&nbsp;<em>k\u00ea khai<\/em>&nbsp;Puppet c\u00f3 th\u1ec3 ch\u1ee9a c\u1ea5u h\u00ecnh mong mu\u1ed1n cho m\u00e1y ch\u1ee7, c\u00e1c gi\u00e1 tr\u1ecb cho&nbsp;<em>c\u00e1c l\u1edbp<\/em>&nbsp;ho\u1eb7c&nbsp;<em>ki\u1ec3u<\/em>&nbsp;Puppet c\u0169ng c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong t\u1ec7p c\u1ea5u h\u00ecnh Hiera \u0111\u1ec3 \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c vi\u1ebft b\u1ea3n k\u00ea khai Puppet trong h\u1ea7u h\u1ebft c\u00e1c tr\u01b0\u1eddng h\u1ee3p. Trong v\u00ed d\u1ee5 n\u00e0y,&nbsp;<code>mysql::server<\/code>c\u00e1c tham s\u1ed1 l\u1edbp s\u1ebd \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong Hiera, nh\u01b0ng l\u1edbp tr\u01b0\u1edbc ti\u00ean ph\u1ea3i \u0111\u01b0\u1ee3c \u00e1p d\u1ee5ng cho m\u00e1y ch\u1ee7.<\/p>\n<p>\u0110\u1ec3 \u00e1p d\u1ee5ng&nbsp;<code>mysql::server<\/code>l\u1edbp n\u00e0y cho t\u1ea5t c\u1ea3 m\u00e1y ch\u1ee7 theo m\u1eb7c \u0111\u1ecbnh, h\u00e3y t\u1ea1o t\u1ec7p k\u00ea khai Puppet sau:<\/p>\n<pre class=\"wp-block-code\"><code>include ::mysql::server<\/code><\/pre>\n<p>L\u01b0u \u00fd r\u1eb1ng \u0111\u00e2y&nbsp;<code>site.pp<\/code>l\u00e0 t\u1ec7p manifest m\u1eb7c \u0111\u1ecbnh. Kh\u00f4ng c\u00f3&nbsp;<code>node { .. }<\/code>d\u00f2ng \u0111\u1ee7 \u0111i\u1ec1u ki\u1ec7n, \u0111i\u1ec1u n\u00e0y \u00e1p d\u1ee5ng l\u1edbp cho b\u1ea5t k\u1ef3 m\u00e1y ch\u1ee7 n\u00e0o \u00e1p d\u1ee5ng manifest. Puppet hi\u1ec7n bi\u1ebft c\u00e1ch \u00e1p d\u1ee5ng l\u1edbp&nbsp;<code>mysql::server<\/code>, nh\u01b0ng v\u1eabn c\u1ea7n c\u00e1c gi\u00e1 tr\u1ecb cho c\u00e1c t\u00e0i nguy\u00ean nh\u01b0 c\u01a1 s\u1edf d\u1eef li\u1ec7u, ng\u01b0\u1eddi d\u00f9ng v\u00e0 c\u00e1c thi\u1ebft l\u1eadp kh\u00e1c. C\u1ea5u h\u00ecnh Hiera \u0111\u1ec3 cung c\u1ea5p c\u00e1c gi\u00e1 tr\u1ecb n\u00e0y trong ph\u1ea7n ti\u1ebfp theo.<\/p>\n<h2 id=\"install-and-configure-puppet-hiera\">C\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh Puppet Hiera<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#install-and-configure-puppet-hiera\"><\/a><\/h2>\n<p>\u0110\u1ec3 hi\u1ec3u c\u00e1ch Hiera ho\u1ea1t \u0111\u1ed9ng, h\u00e3y xem \u0111o\u1ea1n tr\u00edch sau t\u1eeb&nbsp;<code>hiera.yaml<\/code>t\u1ec7p m\u1eb7c \u0111\u1ecbnh:<\/p>\n<pre class=\"wp-block-code\"><code>---\nversion: 5\nhierarchy:\n  - name: \"Per-node data\"\n    path: \"nodes\/%{::trusted.certname}.yaml\"\n  - name: \"Common data\"\n    path: \"common.yaml\"<\/code><\/pre>\n<p>C\u1ea5u h\u00ecnh Hiera n\u00e0y h\u01b0\u1edbng d\u1eabn Puppet ch\u1ea5p nh\u1eadn c\u00e1c gi\u00e1 tr\u1ecb bi\u1ebfn t\u1eeb&nbsp;<code>nodes\/%{::trusted.certname}.yaml<\/code>. N\u1ebfu t\u00ean m\u00e1y ch\u1ee7 Linode c\u1ee7a b\u1ea1n l\u00e0&nbsp;<code>examplehostname<\/code>, h\u00e3y \u0111\u1ecbnh ngh\u0129a m\u1ed9t t\u1ec7p c\u00f3 t\u00ean l\u00e0&nbsp;<code>nodes\/examplehostname.yaml<\/code>). B\u1ea5t k\u1ef3 bi\u1ebfn n\u00e0o \u0111\u01b0\u1ee3c t\u00ecm th\u1ea5y trong c\u00e1c t\u1ec7p YAML cao h\u01a1n trong h\u1ec7 th\u1ed1ng ph\u00e2n c\u1ea5p \u0111\u1ec1u \u0111\u01b0\u1ee3c \u01b0u ti\u00ean, trong khi b\u1ea5t k\u1ef3 t\u00ean bi\u1ebfn n\u00e0o kh\u00f4ng t\u1ed3n t\u1ea1i trong c\u00e1c t\u1ec7p \u0111\u00f3 s\u1ebd chuy\u1ec3n sang c\u00e1c t\u1ec7p th\u1ea5p h\u01a1n trong h\u1ec7 th\u1ed1ng ph\u00e2n c\u1ea5p (trong v\u00ed d\u1ee5 n\u00e0y l\u00e0&nbsp;<code>common.yaml<\/code>).<\/p>\n<p>C\u1ea5u h\u00ecnh sau s\u1ebd \u0111\u1ecbnh ngh\u0129a c\u00e1c bi\u1ebfn Puppet \u0111\u1ec3&nbsp;<code>common.yaml<\/code>\u0111\u01b0a bi\u1ebfn v\u00e0o&nbsp;<code>mysql::server<\/code>l\u1edbp.<\/p>\n<h3 id=\"initial-hiera-configuration\">C\u1ea5u h\u00ecnh Hiera ban \u0111\u1ea7u<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#initial-hiera-configuration\"><\/a><\/h3>\n<p>C\u00e1c t\u1ec7p c\u1ea5u h\u00ecnh Hiera \u0111\u01b0\u1ee3c \u0111\u1ecbnh d\u1ea1ng d\u01b0\u1edbi d\u1ea1ng yaml, v\u1edbi c\u00e1c kh\u00f3a x\u00e1c \u0111\u1ecbnh c\u00e1c tham s\u1ed1 Puppet \u0111\u1ec3 \u0111\u01b0a c\u00e1c gi\u00e1 tr\u1ecb li\u00ean quan c\u1ee7a ch\u00fang v\u00e0o. \u0110\u1ec3 b\u1eaft \u0111\u1ea7u, h\u00e3y \u0111\u1eb7t m\u1eadt kh\u1ea9u g\u1ed1c MySQL. V\u00ed d\u1ee5 sau \u0111\u00e2y v\u1ec1 b\u1ea3n k\u00ea khai Puppet l\u00e0 m\u1ed9t c\u00e1ch \u0111\u1ec3 ki\u1ec3m so\u00e1t m\u1eadt kh\u1ea9u n\u00e0y:<\/p>\n<pre class=\"wp-block-code\"><code>class { '::mysql::server':\n  root_password =&gt; 'examplepassword',\n}<\/code><\/pre>\n<p>Ch\u00fang ta c\u0169ng c\u00f3 th\u1ec3 \u0111\u1ecbnh ngh\u0129a m\u1eadt kh\u1ea9u g\u1ed1c b\u1eb1ng t\u1ec7p c\u1ea5u h\u00ecnh Hiera sau. T\u1ea1o t\u1ec7p YAML sau v\u00e0 l\u01b0u \u00fd c\u00e1ch tham&nbsp;<code>root_password<\/code>s\u1ed1 \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a l\u00e0 Hiera yaml:<\/p>\n<pre class=\"wp-block-code\"><code>mysql::server::root_password: examplepassword<\/code><\/pre>\n<p>Thay th\u1ebf&nbsp;<code>examplepassword<\/code>b\u1eb1ng m\u1eadt kh\u1ea9u an to\u00e0n m\u00e0 b\u1ea1n ch\u1ecdn. Ch\u1ea1y Puppet \u0111\u1ec3 thi\u1ebft l\u1eadp MySQL v\u1edbi c\u00e0i \u0111\u1eb7t m\u1eb7c \u0111\u1ecbnh v\u00e0 m\u1eadt kh\u1ea9u g\u1ed1c \u0111\u00e3 ch\u1ecdn:<\/p>\n<pre class=\"wp-block-code\"><code>sudo -i puppet apply \/etc\/puppetlabs\/code\/environments\/production\/manifests\/site.pp\n<\/code><\/pre>\n<p>Puppet s\u1ebd xu\u1ea5t ti\u1ebfn tr\u00ecnh tr\u01b0\u1edbc khi ho\u00e0n t\u1ea5t. \u0110\u1ec3 x\u00e1c nh\u1eadn MySQL \u0111\u00e3 \u0111\u01b0\u1ee3c c\u1ea5u h\u00ecnh \u0111\u00fang, h\u00e3y ch\u1ea1y l\u1ec7nh:<\/p>\n<pre class=\"wp-block-code\"><code>mysql -u root -p -e 'select version();'\n<\/code><\/pre>\n<p>Nh\u1eadp m\u1eadt kh\u1ea9u v\u00e0 MySQL tr\u1ea3 v\u1ec1 phi\u00ean b\u1ea3n c\u1ee7a n\u00f3:<\/p>\n<pre class=\"wp-block-code\"><code>+-------------------------+\n| version()               |\n+-------------------------+\n| 5.7.24-0ubuntu0.18.04.1 |\n+-------------------------+<\/code><\/pre>\n<h3 id=\"define-mysql-resources\">X\u00e1c \u0111\u1ecbnh t\u00e0i nguy\u00ean MySQL<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#define-mysql-resources\"><\/a><\/h3>\n<p>S\u1eed d\u1ee5ng Hiera, ch\u00fang ta c\u00f3 th\u1ec3 \u0111\u1ecbnh ngh\u0129a ph\u1ea7n c\u00f2n l\u1ea1i c\u1ee7a c\u1ea5u h\u00ecnh MySQL ho\u00e0n to\u00e0n trong yaml. C\u00e1c b\u01b0\u1edbc sau s\u1ebd t\u1ea1o c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 ng\u01b0\u1eddi d\u00f9ng \u0111\u1ec3 s\u1eed d\u1ee5ng trong c\u00e0i \u0111\u1eb7t WordPress.<\/p>\n<p>1.T\u1ea1o m\u1eadt kh\u1ea9u MySQL \u0111\u00e3 b\u0103m tr\u01b0\u1edbc. Thay th\u1ebf m\u1eadt kh\u1ea9u&nbsp;<code>wordpresspassword<\/code>trong v\u00ed d\u1ee5 n\u00e0y v\u00e0 khi \u0111\u01b0\u1ee3c nh\u1eafc nh\u1eadp m\u1eadt kh\u1ea9u MySQL g\u1ed1c, h\u00e3y s\u1eed d\u1ee5ng m\u1eadt kh\u1ea9u g\u1ed1c \u0111\u1ea7u ti\u00ean \u0111\u00e3 ch\u1ecdn trong ph\u1ea7n tr\u01b0\u1edbc \u0111\u1ec3 x\u00e1c th\u1ef1c. L\u01b0u \u00fd chu\u1ed7i b\u1eaft \u0111\u1ea7u b\u1eb1ng a&nbsp;<code>*<\/code>m\u00e0 l\u1ec7nh tr\u1ea3 v\u1ec1 cho B\u01b0\u1edbc 2:<\/p>\n<pre class=\"wp-block-code\"><code>mysql -u root -p -NBe 'select password(\"wordpresspassword\")'\n*E62D3F829F44A91CC231C76347712772B3B9DABC<\/code><\/pre>\n<p>2.V\u1edbi b\u0103m m\u1eadt kh\u1ea9u MySQL \u0111\u00e3 s\u1eb5n s\u00e0ng, ch\u00fang ta c\u00f3 th\u1ec3 \u0111\u1ecbnh ngh\u0129a c\u00e1c gi\u00e1 tr\u1ecb Hiera. YAML sau \u0111\u00e2y \u0111\u1ecbnh ngh\u0129a c\u00e1c tham s\u1ed1 \u0111\u1ec3 t\u1ea1o m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c g\u1ecdi&nbsp;<code>wordpress<\/code>v\u00e0 m\u1ed9t ng\u01b0\u1eddi d\u00f9ng \u0111\u01b0\u1ee3c \u0111\u1eb7t t\u00ean&nbsp;<code>wpuser<\/code>c\u00f3 quy\u1ec1n k\u1ebft n\u1ed1i t\u1eeb&nbsp;<code>localhost<\/code>. YAML c\u0169ng \u0111\u1ecbnh ngh\u0129a m\u1ed9t&nbsp;<code>GRANT<\/code>cho ph\u00e9p&nbsp;<code>wpuser<\/code>ho\u1ea1t \u0111\u1ed9ng tr\u00ean&nbsp;<code>wordpress<\/code>c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u1edbi&nbsp;<code>ALL<\/code>c\u00e1c quy\u1ec1n:<\/p>\n<pre class=\"wp-block-code\"><code>mysql::server::root_password: examplepassword\nmysql::server::databases:\n  wordpress:\n    ensure: present\nmysql::server::users:\n  wpuser@localhost:\n    ensure: present\n    password_hash: '*E62D3F829F44A91CC231C76347712772B3B9DABC'\nmysql::server::grants:\n  wpuser@localhost\/wordpress.*:\n    ensure: present\n    privileges: ALL\n    table: wordpress.*\n    user: wpuser@localhost<\/code><\/pre>\n<p>3.Ch\u1ea1y l\u1ea1i Puppet:<\/p>\n<pre class=\"wp-block-code\"><code>sudo -i puppet apply \/etc\/puppetlabs\/code\/environments\/production\/manifests\/site.pp\n<\/code><\/pre>\n<p>4.B\u00e2y&nbsp;<code>wpuser<\/code>gi\u1edd c\u00f3 th\u1ec3 k\u1ebft n\u1ed1i v\u1edbi&nbsp;<code>wordpress<\/code>c\u01a1 s\u1edf d\u1eef li\u1ec7u. \u0110\u1ec3 x\u00e1c minh, h\u00e3y k\u1ebft n\u1ed1i v\u1edbi daemon MySQL v\u1edbi t\u01b0 c\u00e1ch l\u00e0 ng\u01b0\u1eddi d\u00f9ng&nbsp;<code>wpuser<\/code>v\u1edbi&nbsp;<code>wordpress<\/code>c\u01a1 s\u1edf d\u1eef li\u1ec7u:<\/p>\n<pre class=\"wp-block-code\"><code>mysql -u wpuser -p wordpress\n<\/code><\/pre>\n<p>Sau khi b\u1ea1n nh\u1eadp m\u1eadt kh\u1ea9u cho&nbsp;<code>wpuser<\/code>, h\u00e3y tho\u00e1t kh\u1ecfi d\u1ea5u nh\u1eafc MySQL:<\/p>\n<pre class=\"wp-block-code\"><code>exit<\/code><\/pre>\n<h3 id=\"add-hierarchies-for-specific-environments\">Th\u00eam ph\u00e2n c\u1ea5p cho c\u00e1c m\u00f4i tr\u01b0\u1eddng c\u1ee5 th\u1ec3<a href=\"https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/#add-hierarchies-for-specific-environments\"><\/a><\/h3>\n<p>C\u00f3 th\u1ec3 th\u00eam c\u00e1c c\u1ea5u h\u00ecnh b\u1ed5 sung ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1c m\u00f4i tr\u01b0\u1eddng c\u1ee5 th\u1ec3. V\u00ed d\u1ee5, c\u00e1c t\u00e1c v\u1ee5 sao l\u01b0u ch\u1ec9 c\u00f3 th\u1ec3 \u00e1p d\u1ee5ng cho c\u00e1c m\u00e1y ch\u1ee7 trong m\u1ed9t v\u00f9ng nh\u1ea5t \u0111\u1ecbnh ho\u1eb7c c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u1ee5 th\u1ec3 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c t\u1ea1o trong m\u1ed9t tri\u1ec3n khai c\u1ee5 th\u1ec3.<\/p>\n<p>Trong v\u00ed d\u1ee5 sau, Puppet s\u1ebd c\u1ea5u h\u00ecnh m\u00e1y ch\u1ee7 MySQL v\u1edbi m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u b\u1ed5 sung, nh\u01b0ng ch\u1ec9 khi b\u1ea3n ph\u00e2n ph\u1ed1i c\u1ee7a m\u00e1y ch\u1ee7 \u0111\u00f3 d\u1ef1a tr\u00ean Debian.<\/p>\n<p>1.S\u1eeda \u0111\u1ed5i&nbsp;<code>hiera.yaml<\/code>\u0111\u1ec3 ch\u1ee9a n\u1ed9i dung sau:<\/p>\n<pre class=\"wp-block-code\"><code>---\nversion: 5\nhierarchy:\n  - name: \"Per OS Family\"\n    path: \"os\/%{facts.os.family}.yaml\"\n  - name: \"Other YAML hierarchy levels\"\n    paths:\n      - \"common.yaml\"<\/code><\/pre>\n<p>Thay \u0111\u1ed5i n\u00e0y h\u01b0\u1edbng d\u1eabn Hiera t\u00ecm ki\u1ebfm c\u00e1c tham s\u1ed1 Puppet tr\u01b0\u1edbc ti\u00ean trong&nbsp;<code>\"os\/%{facts.os.family}.yaml\"<\/code>v\u00e0 sau \u0111\u00f3 trong&nbsp;<code>common.yaml<\/code>. Ph\u1ea7n t\u1eed \u0111\u1ea7u ti\u00ean d\u1ef1a tr\u00ean th\u1ef1c t\u1ebf c\u1ee7a h\u1ec7 th\u1ed1ng ph\u00e2n c\u1ea5p l\u00e0 \u0111\u1ed9ng v\u00e0 ph\u1ee5 thu\u1ed9c v\u00e0o m\u00e1y ch\u1ee7 m\u00e0 Puppet v\u00e0 Hiera ki\u1ec3m so\u00e1t. Trong v\u00ed d\u1ee5 d\u1ef1a tr\u00ean Ubuntu n\u00e0y, Hiera s\u1ebd t\u00ecm ki\u1ebfm&nbsp;<code>Debian.yaml<\/code>trong&nbsp;<code>os<\/code>th\u01b0 m\u1ee5c, trong khi tr\u00ean b\u1ea3n ph\u00e2n ph\u1ed1i nh\u01b0 CentOS, t\u1ec7p&nbsp;<code>RedHat.yaml<\/code>s\u1ebd t\u1ef1 \u0111\u1ed9ng \u0111\u01b0\u1ee3c tham chi\u1ebfu thay th\u1ebf.<\/p>\n<p>2.T\u1ea1o t\u1ec7p YAML sau:<\/p>\n<pre class=\"wp-block-code\"><code>lookup_options:\n  mysql::server::databases:\n    merge: deep\n\nmysql::server::databases:\n  ubuntu-backup:\n    ensure: present<\/code><\/pre>\n<p>M\u1eb7c d\u00f9 t\u01b0\u01a1ng t\u1ef1 nh\u01b0&nbsp;<code>common.yaml<\/code>t\u1ec7p \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh trong c\u00e1c b\u01b0\u1edbc tr\u01b0\u1edbc, t\u1ec7p n\u00e0y s\u1ebd&nbsp;<em>ch\u1ec9<\/em><code>ubuntu-backup<\/code>&nbsp;th\u00eam c\u01a1 s\u1edf d\u1eef li\u1ec7u&nbsp;tr\u00ean c\u00e1c m\u00e1y ch\u1ee7 d\u1ef1a tr\u00ean Debian (nh\u01b0 Ubuntu). Ngo\u00e0i ra, c\u00e0i&nbsp;\u0111\u1eb7t \u0111\u1ea3m b\u1ea3o r\u1eb1ng&nbsp;tham s\u1ed1 \u0111\u01b0\u1ee3c&nbsp;<em>h\u1ee3p nh\u1ea5t<\/em>&nbsp;gi\u1eefa&nbsp;v\u00e0&nbsp;\u0111\u1ec3 t\u1ea5t c\u1ea3 c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd. N\u1ebfu kh\u00f4ng&nbsp;\u0111\u1eb7t \u0111\u1ec3 h\u1ee3p nh\u1ea5t s\u00e2u c\u00e1c h\u00e0m b\u0103m n\u00e0y, ch\u1ec9 t\u1ec7p ph\u00e2n c\u1ea5p c\u1ee5 th\u1ec3 nh\u1ea5t s\u1ebd \u0111\u01b0\u1ee3c \u00e1p d\u1ee5ng cho m\u00e1y ch\u1ee7, trong tr\u01b0\u1eddng h\u1ee3p n\u00e0y l\u00e0&nbsp;.<em><\/em><code>lookup_options<\/code><code>mysql::server:databases<\/code><em><\/em><code>Debian.yaml<\/code><code>common.yaml<\/code><code>lookup_options<\/code><code>Debian.yaml<\/code><\/p>\n<ul>\n<li>Ngo\u00e0i ra, v\u00ec t\u1ec7p k\u00ea khai Puppet c\u1ee7a ch\u00fang ta ng\u1eafn n\u00ean ch\u00fang ta c\u00f3 th\u1ec3 ki\u1ec3m tra l\u1ec7nh t\u01b0\u01a1ng t\u1ef1 b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng c\u1edd&nbsp;<code>-e<\/code>\u0111\u1ec3 \u00e1p d\u1ee5ng t\u1ec7p k\u00ea khai n\u1ed9i tuy\u1ebfn:<\/li>\n<\/ul>\n<pre class=\"wp-block-code\"><code>sudo -i puppet apply -e 'include ::mysql::server'\n<\/code><\/pre>\n<p>3.Ch\u1ea1y Puppet v\u00e0 quan s\u00e1t nh\u1eefng thay \u0111\u1ed5i:<\/p>\n<pre class=\"wp-block-code\"><code>sudo -i puppet apply \/etc\/puppetlabs\/code\/environments\/production\/manifests\/site.pp\n<\/code><\/pre>\n<p>4.X\u00e1c minh xem c\u01a1 s\u1edf d\u1eef li\u1ec7u m\u1edbi c\u00f3 t\u1ed3n t\u1ea1i kh\u00f4ng:<\/p>\n<pre class=\"wp-block-code\"><code>mysql -u root -p -e 'show databases;'\n<\/code><\/pre>\n<p>Bao g\u1ed3m&nbsp;<code>ubuntu-backup<\/code>c\u01a1 s\u1edf d\u1eef li\u1ec7u m\u1edbi:<\/p>\n<pre class=\"wp-block-code\"><code>+---------------------+\n| Database            |\n+---------------------+\n| information_schema  |\n| mysql               |\n| performance_schema  |\n| sys                 |\n| ubuntu-backup       |\n| wordpress           |\n+---------------------+<\/code><\/pre>\n<p>Xin ch\u00fac m\u1eebng! B\u00e2y gi\u1edd b\u1ea1n c\u00f3 th\u1ec3 ki\u1ec3m so\u00e1t c\u1ea5u h\u00ecnh Puppet c\u1ee7a m\u00ecnh th\u00f4ng qua c\u00e1c \u0111\u1ecbnh ngh\u0129a Hiera c\u00f3 kh\u1ea3 n\u0103ng c\u1ea5u h\u00ecnh cao.<\/p>\n<h2 id=\"more-information\">Th\u00f4ng tin th\u00eam<\/h2>\n<p>B\u1ea1n c\u00f3 th\u1ec3 mu\u1ed1n tham kh\u1ea3o c\u00e1c ngu\u1ed3n sau \u0111\u1ec3 bi\u1ebft th\u00eam th\u00f4ng tin v\u1ec1 ch\u1ee7 \u0111\u1ec1 n\u00e0y. M\u1eb7c d\u00f9 ch\u00fang t\u00f4i cung c\u1ea5p v\u1edbi hy v\u1ecdng r\u1eb1ng ch\u00fang s\u1ebd h\u1eefu \u00edch, nh\u01b0ng xin l\u01b0u \u00fd r\u1eb1ng ch\u00fang t\u00f4i kh\u00f4ng th\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh ch\u00ednh x\u00e1c ho\u1eb7c t\u00ednh k\u1ecbp th\u1eddi c\u1ee7a c\u00e1c t\u00e0i li\u1ec7u \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef b\u00ean ngo\u00e0i.<\/p>\n<ul>\n<li><a href=\"https:\/\/puppet.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Ph\u00f2ng th\u00ed nghi\u1ec7m r\u1ed1i<\/a><\/li>\n<li><a href=\"https:\/\/puppet.com\/docs\/open-source-puppet\/\" target=\"_blank\" rel=\"noreferrer noopener\">T\u00e0i li\u1ec7u ngu\u1ed3n m\u1edf Puppet<\/a><\/li>\n<li><a href=\"https:\/\/forge.puppet.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">L\u00f2 r\u00e8n con r\u1ed1i<\/a><\/li>\n<li><a href=\"https:\/\/docs.puppet.com\/hiera\/\" target=\"_blank\" rel=\"noreferrer noopener\">T\u00e0i li\u1ec7u Hiera<\/a><\/li>\n<li><a href=\"https:\/\/puppet.com\/docs\/puppet\/7\/facter.html\" target=\"_blank\" rel=\"noreferrer noopener\">Ng\u01b0\u1eddi th\u1ef1c hi\u1ec7n<\/a><\/li>\n<\/ul>\n<p>Ngu\u1ed3n: https:\/\/www.linode.com\/docs\/guides\/install-and-manage-mysql-databases-with-puppet-hiera-on-ubuntu-18-04\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Puppet&nbsp;l\u00e0 m\u1ed9t h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c s\u1eed d\u1ee5ng v\u00e0 tri\u1ec3n khai c\u00e1c lo\u1ea1i ph\u1ea7n m\u1ec1m kh\u00e1c nhau, gi\u00fap qu\u1ea3n tr\u1ecb h\u1ec7 th\u1ed1ng \u0111\u00e1ng tin c\u1eady v\u00e0 c\u00f3 th\u1ec3 sao ch\u00e9p \u0111\u01b0\u1ee3c h\u01a1n. Trong h\u01b0\u1edbng d\u1eabn n\u00e0y, ch\u00fang t\u00f4i s\u1eed d\u1ee5ng Puppet \u0111\u1ec3 qu\u1ea3n l\u00fd c\u00e0i \u0111\u1eb7t&nbsp;MySQL&nbsp;, m\u1ed9t c\u01a1<\/p>\n","protected":false},"author":1,"featured_media":35987,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[],"class_list":["post-34966","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\/34966","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=34966"}],"version-history":[{"count":0,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts\/34966\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/media\/35987"}],"wp:attachment":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/media?parent=34966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/categories?post=34966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/tags?post=34966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}