ANATOLIYDIMITROV

Puppet is a powerful automation tool that helps administrators manage complex server setups centrally. You can use Puppet to manage MariaDB — let's see how.

With Puppet, you describe system states that you want the Puppet master server [to enforce] on the managed nodes. If you don't have Puppet installed and configured yet, please check the official Puppet documentation.

Before you can use Puppet to manage MariaDB, you must install a Puppet module that sets the proper repository corresponding to your operating system and version of MariaDB. For Red Hat-based distros, including CentOS, you can use the Yguenane MariaDB [repository] Puppet module. On your Puppet master, install the module with the command puppet module install yguenane/mariadbrepo, which puts the module files in the directory /etc/puppet/modules/mariadbrepo/.

The Yguenane module currently supports only Red Hat 5 and 6, CentOS 5 and 6, and any Fedora version that has the MariaDB repository, which, per the MariaDB 10.0 repository, means versions 19 and 20. If you need support for different versions or operating systems, you must edit the module. Its code is simple and straightforward, so you should be able to adapt it even if you don't know Ruby, the programming language behind Puppet. For example, to add support for Red Hat or CentOS 7, edit the file /etc/puppet/modules/mariadbrepo/manifests/init.pp and change the $os_ver variable. Initially, it looks like this:

$os_ver = $::operatingsystemrelease ? {
    /6.[0-9]/  => '6',
    /5.[0-9]+/ => '5',
    default    => $::operatingsystemrelease,
    }

Change it to:

$os_ver = $::operatingsystemrelease ? {
    /7.[0-9]/  => '7',
    /6.[0-9]/  => '6',
    /5.[0-9]+/ => '5',
    default    => $::operatingsystemrelease,
}

You can edit other variables in the same file, such as $os, to add support for other operating systems. As long as there is an official MariaDB repository for the OS and version, you should be able to add support for it.

MariaDB installation on the Puppet nodes

Once you have the necessary Puppet module on the Puppet master, you can install MariaDB on the Puppet nodes. Let's assume your Puppet manifests are found in the default /etc/puppet/manifests/site.pp file. The first thing you should do is distribute the MariaDB repo to the Puppet nodes that should have MariaDB installed. You can do it by adding code similar to this to site.pp, or to a separate file that you include in site.pp:

node 'host1' {
    class {'mariadbrepo':
        version => '10.0',
    }
}
node 'host2' {
    class {'mariadbrepo':
        version => '10.1',
    }
}

This tells Puppet to use the repository for MariaDB version 10.0 for host1, and the one for MariaDB 10.1 for host2. This is just an example to show that you can have different versions on different hosts; in real life it's better to have the same MariaDB version throughout your whole environment to avoid compatibility issues.

The next time Puppet catalog runs on the nodes, the repository should be added and the file /etc/yum.repos.d/MariaDB.repo should appear.

Next, you can define MariaDB installation by adding a new Puppet class (named block of Puppet code):

class mariadb {
    package { 'MariaDB-server':
        ensure => installed,
    }
    service { 'mysql':
        ensure => running,
        enable => true,
    }
}

This class instructs the nodes to install the package MariaDB-server. On Red Hat or CentOS nodes it will have the same effect as running the command yum install MariaDB-server. Naturally, it will take care of all the dependencies for MariaDB-server.

After the package directive comes the service one. Notice that I am using the service name mysql, which MariaDB uses to ensure compatibility with MySQL, which it can replace. The service directive ensures that the MariaDB service (mysql) is running, which means that it also ensures that it is started for the first time after the installation. Also, the service is set to enabled, meaning that it will automatically start during the OS boot process.

The only thing left is to include this class in the node's declaration. For example, let's extend an example host1 declaration like this:

node 'host1' {
    class {'mariadbrepo':
        version => '10.0',
    }
    include mariadb
}

After the next Puppet catalog run on the node host1, MariaDB should be installed and started.

MariaDB configuration on the Puppet nodes

To managing the MariaDB environment using Puppet you will probably need to edit some configuration files. For example, if you want to set custom configuration values for the MariaDB server, you will have to edit the file /etc/my.cnf.d/server.cnf on each of the Puppet nodes. You can use Puppet itself to ensure that the configuration is centrally managed and consistent over time and across multiple nodes.

To send a custom configuration file such as /etc/my.cnf.d/server.cnf to your Puppet nodes, create the following resource declaration as part of your mariadb class in the site.pp file:

file { '/etc/my.cnf.d/server.cnf':
      ensure => file,
      mode   => 644,
      source => 'puppet:///conf_files/mariadb/server.cnf',
}

This code specifies the permissions of the file (644) and its source location. Translated, the location puppet:///conf_files/mariadb/server.cnf means /etc/puppet/conf_files/mariadb/server.cnf on the Puppet master.

The above source directive assumes you have configured the Puppet fileserver already. The configuration file /etc/puppet/fileserver.conf should contain the following code:

[conf_files]
   path /etc/puppet/conf_files
   allow *

Furthermore, you should change the service description to recognize the custom MariaDB server configuration file. For this purpose you can use the subscribe metaparameter. Here is how the complete mariadb class should look:

class mariadb {
    package {'MariaDB-server':
        ensure => installed,
    }
    service { 'mysql':
        ensure => running,
        enable => true,
        subscribe => File['/etc/my.cnf.d/server.cnf'],
    }
    file { '/etc/my.cnf.d/server.cnf':
        ensure => file,
        mode   => 644,
        source => 'puppet:///conf_files/mariadb/server.cnf',
    }
}

When you use the subscribe parameter, the MariaDB server will be restarted whenever you make changes to the server configuration file, and thus your changes will take effect immediately.

As you can see, it's easy to install and configure MariaDB with Puppet. You can install different versions and manage configuration files centrally with just a little code and effort.

Tags: 

About the Author

anatoliydimitrov's picture
Anatoliy Dimitrov

Anatoliy Dimitrov is an open source enthusiast with substantial professional experience in databases and web/middleware technologies. He is as interested in technical writing and documentation as in practical work on complex IT projects. His favourite databases are MariaDB (sometimes MySQL) and PostgreSQL. He is currently graduating his master's degree in IT and aims to a PhD in Bionformatics in his home town University of Sofia.


저작자 표시 비영리 동일 조건 변경 허락
신고


Fig.01: 일본 나리타 공항


Fig.02: 치바 마쿠하리역 근처 다운타운


Fig.03: 일본의 자판기 문화는 어디를 가나 볼 수 있었다.


Fig.04: 출장의 목적인 2014 Japan IT Week


Fig.05: 봄에 열리는 IT Week의 규모가 더욱 크고, 10월에 열리는 행사였지만 정말 배울것이 많았다.


Fig.05: 마쿠하리 APA 호텔의 예약이 잘못되어 Green Tower Hotel에서 머물렀다.

Green Tower Hotel에서 보이는 다운타운의 모습 Aeon Mall의 간판도 보인다.


Fig.06: 둘째날  쇼핑을 간 Aeon Mall

Aeon Mall은 아키타현에서 가장 큰 규모의 쇼핑센터이다. 사진 뒷쪽에 보이는 3개의 큰 몰이 모두 Aeon Mall이다.


Fig.07: 호텔 근처에 잇는 지바 롯데 홈구장 QVC 마린 필드


전시회 개요(2014 Japan IT Week, Autumn)

 1) 일시 : 2014년 10월 29일 ~ 10월 31일

 2) 장소 : 치바현 마쿠하리 메세

 3) 주최 : 리드 익스비전 재팬


주요 일정

 1 일차 : 출국(인천 -> 나리타), 숙소 도착 및 중식, 전시회 참관

 2 일차 : 전시회 참관, Aeon Mall 쇼핑

 3 일차 : 전시회 참관, 업체 미팅, 귀국 (나리타 -> 인천)

              

회사 생활을 하며 첫 해외출장이였다. 사실 해외도 첫 경험이였다. 방사능 때문에 많이 걱정은 했었지만 내가 생각햇었던 일본의 선입견과는 너무 달랐다. 일본인들의 시민의식도 높고, 항상 친절하고 좋은 인상을 받았다. IT Week에 참석하면서 일본에 진출한 한국 기업들과도 미팅을 하고 회사와 제휴 관계를 맺고자 하는 몇개의 업체와 미팅도 했었다. 아쉽게 일본어를 몰라 실장님 뒤를 졸졸 쫓아다니긴 했지만, 생각했다. 이럴 때를 대비해서 영어라도 더욱 공부를 열심히 해야겠다고..



마쿠라히주변_영어.pdf


마쿠하리주변_한국어.pdf


마쿠하리주변_일본어.pdf


저작자 표시 비영리 동일 조건 변경 허락
신고

'Other > Hello, World' 카테고리의 다른 글

[Hello, World] 2014.10 Japan, Chiba, Narita  (2) 2014.11.06
[Hello, World] 2014.08 JEJU island  (0) 2014.08.24


디렉토리 구조를 트리 형으로 보여주는 Tree Package

트리 구조로 디렉토리 구조를 보고 싶을 경우, 기존 리눅스에서는 볼 수 없지만 Tree Package를 설치하게 되면 디렉토리를 Tree 구조로 확인 할 수 있습니다.


Tree Package 설치 및 테스트

1) RHEL / CentOS / Fedora Linux

기본적으로 트리 명령은 설치되어 있지 않습니다.

[root@localhost ~]# tree
bash: tree: command not found...

## tree pakcage install
 [root@localhost ~]# yum install tree
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                                                                                                                                                     | 3.6 kB  00:00:00     
extras                                                                                                                                                                                                                                   | 3.4 kB  00:00:00     
mariadb                                                                                                                                                                                                                                  | 1.9 kB  00:00:00     
http://yum.puppetlabs.com/el/7/dependencies/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: yum.puppetlabs.com; Name or service not known"
Trying other mirror.
puppetlabs-devel                                                                                                                                                                                                                         | 2.5 kB  00:00:00     
puppetlabs-products                                                                                                                                                                                                                      | 2.5 kB  00:00:00     
updates                                                                                                                                                                                                                                  | 3.4 kB  00:00:00     
(1/3): extras/7/x86_64/primary_db                                                                                                                                                                                                        |  33 kB  00:00:00     
(2/3): updates/7/x86_64/primary_db                                                                                                                                                                                                       | 4.2 MB  00:00:00     
puppetlabs-products/x86_64/pri FAILED                                                                             99% [====================================================================================================== ]  98 kB/s | 4.2 MB  00:00:00 ETA 
http://yum.puppetlabs.com/el/7/products/x86_64/repodata/c16896632f46758106aca64ff9e1c3f6b2e0cc1b-primary.sqlite.bz2: [Errno -1] Metadata file does not match checksum======================================================== ]  98 kB/s | 4.2 MB  00:00:00 ETA 
Trying other mirror.
mariadb/primary_db                                                                                                                                                                                                                       |  20 kB  00:00:00     
Determining fastest mirrors
 * base: centos.mirror.cdnetworks.com
 * extras: centos.mirror.cdnetworks.com
 * updates: centos.mirror.cdnetworks.com
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================================================================================================================================================
 Package                                                    Arch                                                         Version                                                               Repository                                                  Size
================================================================================================================================================================================================================================================================
Installing:
 tree                                                       x86_64                                                       1.6.0-10.el7                                                          base                                                        46 k

Transaction Summary
================================================================================================================================================================================================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]: y
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm                                                                                                                                                                                                             |  46 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tree-1.6.0-10.el7.x86_64                                                                                                                                                                                                                     1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64                                                                                                                                                                                                                     1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                                                                                                                                                                                                                                    

Complete!

2) Debian / Mint / Ubuntu Linux

[root@localhost ~]# sudo apt-get install tree
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  tree
0 upgraded, 1 newly installed, 0 to remove and 381 not upgraded.
Need to get 36.7 kB of archives.
After this operation, 112 kB of additional disk space will be used.
Get:1 http://kr.archive.ubuntu.com/ubuntu/ trusty/universe tree i386 1.6.0-1 [36.7 kB]
Fetched 36.7 kB in 0s (102 kB/s)
Selecting previously unselected package tree.
(Reading database ... 169637 files and directories currently installed.)
Preparing to unpack .../archives/tree_1.6.0-1_i386.deb ...
Unpacking tree (1.6.0-1) ...
Processing triggers for man-db (2.6.7.1-1) ...
Setting up tree (1.6.0-1) ...

3) 테스트

[root@localhost ~]# tree -L 2 /app
/app
├── batch
├── test_demo
│  ├── webapps
│  └── webhome
├── test_mariadb
│  ├── webapps
│  └── webhome
├── test_monitoring
│  ├── webapps
│  └── webhome
└── tomcat
    ├── bin
    ├── conf
    ├── lib
    ├── LICENSE
    ├── logs
    ├── NOTICE
    ├── RELEASE-NOTES
    ├── RUNNING.txt
    ├── temp
    ├── webapps
    └── work

4) Syntax

tree
tree /path/to/directory
tree [options]
tree [options] /path/to/directory


저작자 표시 비영리 동일 조건 변경 허락
신고