<?php require_once( dirname(dirname(dirname( __FILE__ ))) . '/wp-load.php' ); ?>
<!-- START of header -->
<?php get_header(); ?>
<!-- END of header -->

<!-- warapper -->

<div class="docs-content">
<!-- START of page navigation -->
<?php get_template_part( 'docs_navigation' ); ?>
<!-- END of page navigation -->
<!-- START of pusher -->
<div class="docs-content-body">
<div id="content" class="docs-content-body__inner">

<h1 class="title">5.1.3 Preparation: Environment (server)</h1>
<h2 id="overview">Overview</h2>
<p>This chapter covers setting up a GridDB server to use while running the sample application.</p>
<p><br/></p>
<h2 id="components">Components</h2>
<p>The environment will be configured as follows:</p>
<p><strong>Figure 1 block diagram </strong></p>
<img src="img/machine_daiagram.png" width="523" height="249" alt="Figure 1 block diagram" class="center"/>

<p><strong>Table 2 middleware version</strong></p>
<div class="griddb" markdown="1">

</div>
<table class="table-dl-connector">
<thead>
<tr class="header">
<th style="text-align: left;">middleware</th>
<th style="text-align: left;">version</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">GridDB Community Edition</td>
<td style="text-align: left;">2.8.0</td>
</tr>
<tr class="even">
<td style="text-align: left;">Docker</td>
<td style="text-align: left;">1.12.0</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Docker Compose</td>
<td style="text-align: left;">1.8.0</td>
</tr>
</tbody>
</table>


<p>The environment in which you run GridDB will be built in a container using <a href=https://www.docker.com>Docker</a> but you can apply the same concepts to other VMs or a native OS to suit your environment.  We will install Docker to the host machine's OS (Centos 7), then manually build a single node GridDB server and then a two node GridDB cluster using docker-compose.</p>
<p><br/></p>
<h2 id="install-docker">Install Docker</h2>
<p>Install Docker:</p>
<strong>List.1 Docker installation of</strong>
<pre class="prettyprint linenums">
$ sudo curl -fsSL https://get.docker.com/ | sh
$ sudo usermod -aG docker vagrant
$ sudo systemctl enable docker
$ sudo systemctl start docker
</pre>
<ul>
<li>L.1: Download and run the Docker installation script.</li>
<li>L.2: Create a user who runs Docker.</li>
<li>L.3: Enable boot time start up of Docker.</li>
<li>L.4: Start Docker.</li>
</ul>
<p><br/></p>
<h2 id="create-the-docker-container">Create the Docker container</h2>
<p>These steps create the container where you'll run GridDB:</p>
<strong>List.2 Docker container creation</strong>
<pre class="prettyprint linenums">
$ sudo docker pull centos: 6.7
$ sudo docker network create --subnet=192.168.11.0/24 griddb_default
$ sudo docker run -it --name gsnode1 -h gsnode1 --net=griddb_default --ip=192.168.11.11 -d centos: 6.7
</pre>
<ul>
<li>L.1: Download the CentOS image.</li>
<li>L.2: Create a network for the container to run GridDB.</li>
<li>L.3: Create a container from the CentOS image. This will use the network settings from the previously created network.</li>
</ul>
<p><br/></p>
<h2 id="install-gridddb-in-docker-container.">Install GriddDB in Docker container.</h2>
<p>With the Docker container configured , you can install and configure GridDB.</p>
<strong>List.3 container login</strong>
<pre class="prettyprint linenums">
$ sudo docker exec -it griddb_griddb1_1 bash
</pre>
<p>Line 1: Run a shell on the GridDB container and log in.</p>

<p><strong>List.4 network settings</strong></p>
<pre class="prettyprint linenums">
# hostname -i
192.168.11.11
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
# vi /etc/sysconfig/network
HOSTNAME=<strong> 192.168.11.11 </strong> (to change to 192.168.11.11)
</pre>
<ul>
<li>L.1-2: Make sure the IP address has been set for the hostname.</li>
<li>L.6-7: Set the IP address in the HOSTNAME of/etc/sysconfig/network. <br/></li>
</ul>

<p><strong>List.5 GridDB installation</strong></p>
<pre class="prettyprint linenums">
# curl -L -O https://github.com/griddb/griddb_nosql/releases/download/v2.8.0/griddb_nosql-2.8.0-1.el6.x86_64.rpm
# rpm -Uvh griddb_nosql-2.8.0-1.el6.x86_64.rpm
</pre>
<ul>
<li>L.1: Fetch the GridDB RPM file from Github/</li>
<li>L.2: Install the RPM.</li>
</ul>
<p>Then perform the initial configuration of GridDB.</p>
<strong>List.6 gs_cluster.json</strong>
<pre class="prettyprint linenums">
# cat /var/lib/gridstore/conf/gs_cluster.json
(Snip)
"Cluster": {
"ClusterName": "",
(Snip)
"LoadbalanceCheckInterval": "180s"
(Snip)
# vi /var/lib/gridstore/conf/gs_cluster.json
(Snip)
"Cluster": {
"ClusterName": "<strong> GSCLUSTER </strong>", (to set the cluster name clusterName)
(Snip)
"LoadbalanceCheckInterval": "180s",
"NotificationMember": [
{
"cluster": { "address": "192.168.11.11", "port": 10010},
"cync": { "address": "192.168.11.11", "port": 10020},
"system": { "address": "192.168.11.11", "port": 10040},
"sransaction": { "address": "192.168.11.11", "port": 10001},
"sql": { "address": "192.168.11.11", "port": 20001}
}
]
(Snip)
</pre>
<ul>
<li>L.4: The initial clusterName will be empty(&quot;&quot;) and GridDB will fail to start.</li>
<li>L.9: Set clusterName to <strong>GSCLUSTER</strong>. This setting will be used by applications to connect later.</li>
<li>L.14-22: Contains address and port information using GridDB's fixed list format. If you want to configure a cluster of multiple nodes, all nodes information must be listed here.</li>
</ul>
<br/> <strong>List.7 Set default user password</strong>
<pre class="prettyprint linenums">
# su - gsadm
$ gs_passwd admin
Password: <strong> admin </strong> (enter the password)
Retype password: <strong> admin </strong> (and then re-enter the password)
</pre>
<ul>
<li>L.1: Internal GridDB commands need to be run as the gsadm user.</li>
<li>L.2 to 4: Sets the admin user's password, which is the default user on GridDB.<br>
<strong>(Note) This admin user is not a user of the OS.</strong> The GridDB user name and password will be required for the sample application to connect later.</li>
</ul>
<p>Now GridDB can be started.</p>
<strong>List.8 Start GridDB </strong>
<pre class="prettyprint linenums">
# su - gsadm
$ gs_startnode -u <strong> admin/admin </strong> -w 0
.......
It started node.
$ gs_joincluster -c <strong> GSCLUSTER </strong> -u <strong> admin/admin </strong> -w 0
.
Joined node
</pre>
<ul>
<li>L.2: Start the GridDB service. Wait until the start-up in the <code>-w 0</code> option. You will need to specify the user name and password with the -u flag, such as -u <user name>/<password>.</li>
<li>L.5: Either join or create a cluster. Specify the cluster name with the -c option that was set in Listing 6.</li>
</ul>
<p>Setting of one of GridDB node is now complete.</p>
<p><br/></p>
<h2 id="dockerfile">Dockerfile</h2>
<p>The Dockerfile contains all the previous work and is able to perform the above configuration steps automatically. It is useful for creating many nodes.</p>
<strong>List 9 Dockerfile</strong>
<pre class="prettyprint linenums">
FROM centos: 6.7

RUN set -x &&\
HOST=`hostname` &&\
sed -i "s/^ \ (HOSTNAME=\). */\ 1 $ HOST /"/etc/sysconfig/network &&\
curl -L -O https://github.com/griddb/griddb_nosql/releases/download/v2.8.0/griddb_nosql-2.8.0-1.el6.x86_64.rpm &&\
rpm -Uvh griddb_nosql-2.8.0-1.el6.x86_64.rpm

ARG CLUSTER_CONF
RUN echo $CLUSTER_CONF
ADD $CLUSTER_CONF /var/lib/gridstore/conf/

RUN set -x &&\
chown gsadm: gridstore/var/lib/gridstore/conf/$ CLUSTER_CONF &&\
chmod 640/var/lib/gridstore/conf/$ CLUSTER_CONF &&\
su - gsadm -c "gs_passwd admin -p admin"

CMD su - gsadm -c \
"gs_startnode -u admin/admin -w 0 &&gs_joincluster -c GSCLUSTER -n 2 -u admin/admin" &&\
tail -f/dev/null
</pre>
<p>It summarizes the settings that were set manually in the above.</p>
<ul>
<li>L.9: Allows the gs_cluster.conf  input to be specified for use with docker-compose.yml</li>
<li>L.19: Too build a cluster of multiple nodes, the  <code>gs_joincluster</code> command needs the <code>-n</code> that specifies the number of nodes.</li>
</ul>
<p><br/></p>
<h2 id="install-docker-compose">Install Docker Compose</h2>
<p>If you create more than one similar Docker container, it is worth while to use <a href="https://docs.docker.com/compose/">Docker Compose</a> which can automatically create and boot multiple containers.</p>

<strong>List.10 Install Docker Compose</strong>
<pre class="prettyprint linenums">
$ curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` -O
$ chmod + x docker-compose-*
$ sudo mv docker-compose-* /usr/local/bin/docker-compose
</pre>
<ul>
<li>L.1: Get the Docker Compose for your system binary from Github.</li>
<li>L.2: Grant executable permissions to the binary.</li>
<li>L.3: Move the binary to /usr/local/bin, renaming it docker-compose</li>
</ul>
<p>The following is the contents of Docker Compose's configuration file, docker-compose.yml:</p>
<strong>List.11 Docker Compose configuration file</strong>
<pre class="prettyprint linenums">
version: '2'
services:
    griddb1:
        build:
            context .
            args:
                CLUSTER_CONF: "gs_cluster.json"
        container_name: gsnode1
        networks:
            default:
                ipv4_address: 192.168.11.11
        ports:
            - "10001:10001"
            - "20001:20001"
        expose:
            - "10010"
            - "10020"
            - "10040"
            - "10001"
            - "20001"
    griddb2:
        build:
            context .
            args:
                CLUSTER_CONF: "gs_cluster.json"
        container_name: gsnode2
        networks:
            default:
                ipv4_address: 192.168.11.12
        ports:
            - "12001:10001"
            - "22001:20001"
        expose:
            - "10010"
            - "10020"
            - "10040"
            - "10001"
            - "20001"

networks:
    default:
        ipam:
            config:
                - subnet: 192.168.11.0/24
</pre>
<p>In the Docker compose file, you have to specify the parameters of the container that had been specified. It also specifies the respective configuration files which need to represent configured values.</p>
<p>The files that will be used in the Docker Compose are placed in a directory as follows:</p>
<strong>List.12 Docker Compose configuration file configuration</strong>
<pre class="prettyprint linenums">
griddb /
 - Docker-compose.yml
 - Dockerfile
 - gs_cluster_1.json
 - gs_cluster_2.json
</pre>
<p>From that directory, run the commands that will create the Container, installer GridDB, and then start the container.</p>
<strong>List.13 Docker Compose configuration file placement</strong>
<pre class="prettyprint linenums">
$ cd griddb
$ sudo /usr/local/bin/docker-compose up -d
$ sudo /usr/local/bin/docker-compose ps
 Name Command State Ports
-------------------------------------------------- -------------------------------------------------- --------------------------------------
gsnode1/bin/sh -c su - gsadm -c "... Up 127.0.0.1:10001->10001/tcp, 10010/tcp, 10020/tcp, 10040/tcp, 127.0.0.1:20001->20001/tcp
gsnode2/bin/sh -c su - gsadm -c "... Up 0.0.0.0:12001->10001/tcp, 10010/tcp, 10020/tcp, 10040/tcp, 0.0.0.0:22001->20001/tcp
</pre>
<ul>
<li>L.1: Change directory to where the above configuration files were created.</li>
<li>L.2: In accordance with the docker-compose command in the configuration file, if Docker container has not yet been created then create and start a container. If the container has already been created, it will only be started.</li>
<li>L.3 to 7: it displays the status of the container that was started in the docker-compose.</li>
</ul>
<p><br/></p>
<h2 id="files">Files</h2>
<p>The set of files used in this chapter can be downloaded from: <a href="img/griddb-server-conf.zip">griddb-server-conf.zip</a></p>
<p><br/></p>
</div>
</div>
</div>
</div>
</div>
<!-- / main -->

<?php get_footer(); ?>
