GBASE数据库 | GBase 8a Cluster Automated Installation and Deployment Using ansible

In this article, we will guide you through the process of automating the installation and deployment of a GBase 8a cluster using Ansible. This solution simplifies the deployment of the GBase 8a database (GBase数据库) in a cluster environment, making it easier to manage and scale. Host Configuration An example configuration is as follows: [all] 192.168.56.3 gbaseRole=coor RoleId=1 vc_name='' private_ip1=192.168.56.3 private_ip2=192.168.56.3 192.168.56.4 gbaseRole=newcoor RoleId=1 vc_name=vc1 private_ip1=192.168.56.4 private_ip2=192.168.56.6 192.168.56.5 gbaseRole=newnode RoleId=2 vc_name=vc1 private_ip1=192.168.56.4 private_ip2=192.168.56.6 192.168.56.6 gbaseRole=node RoleId=1 vc_name=vc2 private_ip1=192.168.56.4 private_ip2=192.168.56.6 192.168.56.3: Business network IP gbaseRole: The role of GBase (management node: coor, compute node: node) RoleId: Role ID, fill in sequentially vc_name: Virtual Cluster name for compute nodes, leave empty for management nodes, set to data in compatibility mode private_ip1: Private network IP address 1 for compute nodes private_ip2: Private network IP address 2 for compute nodes (not required for single-instance setups) Variables Explanation # GBase installation package name gbase_setup_file: 'xxxx.tar.bz2' # Operating system root password root_passwd: '111111' # GBase password for the operating system gbase_passwd: '111111' # Database DBA user (root, gbase) password dba_password: '111111' # Database character set (utf8, utf8mb4, gbk, etc.) db_charset: utf8 vc_lists: ['vc1'] # Management node ID list, generally recommended to be the IP address's last segment, separated by commas coorHostNodeIDlist: '1,2,3' Task Descriptions Initial Installation Preparation - name: Install necessary RPM packages yum: name={{ item }} state=installed with_items: - bzip2 - expect - gcc - '*cgroup*' - bc - numactl - rsync tags: init_env - name: Upload GBase installation package copy: src: files/{{ gbase_setup_file }} dest: /opt/ when: "gbaseRole == 'coor' and RoleId == 1" tags: init_env - name: Extract GBase installation package unarchive: src: /opt/{{ gbase_setup_file }} dest: /opt/ remote_src: yes when: "gbaseRole == 'coor' and RoleId == 1" tags: init_env - name: Create GBase user user: name: gbase state: present update_password: always password: '{{ gbase_passwd | password_hash('sha512') }}' tags: init_env - name: Change ownership of /opt directory file: path: /opt state: directory owner: gbase group: gbase recurse: yes tags: init_env - name: Upload system environment variable initialization script copy: src: SetSysEnv.py dest: /tmp tags: init_env - name: Initialize system environment variables shell: 'python /tmp/SetSysEnv.py --dbaUser=gbase --installPrefix=/opt --cgroup' tags: init_env Generate Installation Configuration File - name: Generate installation configuration file template: src: demo.options.j2 dest: /opt/gbase_workspace/setup/gcinstall/demo.options when: "gbaseRole == 'coor' and RoleId == 1 and InstanceType == 0" tags: install become: true become_user: gbase demo.options.j2 Template: installPrefix= /opt coordinateHost = {% for host in groups['all'] -%} {% if hostvars[host]['gbaseRole']=='coor' -%} {% if hostvars[host]['RoleId'] == 1 -%} {{ hostvars[host]['private_ip1'] }} {%- else -%} ,{{ hostvars[host]['private_ip1'] }} {%- endif %} {%- endif %} {%- endfor %} coordinateHostNodeID = {{ coorHostNodeIDlist }} dataHost = {% for host in groups['all'] -%} {% if hostvars[host]['gbaseRole']=='node' -%} {% if hostvars[host]['RoleId'] == 1 -%} {{ hostvars[host]['private_ip1'] }} {%- else -%} ,{{ hostvars[host]['private_ip1'] }} {%- endif %} {%- endif %} {%- endfor %} gcwareHost = {% for host in groups['all'] -%} {% if hostvars[host]['gbaseRole']=='coor' -%} {% if hostvars[host]['RoleId'] == 1 -%} {{ hostvars[host]['private_ip1'] }} {%- else -%} ,{{ hostvars[host]['private_ip1'] }} {%- endif %} {%- endif %} {%- endfor %} gcwareHostNodeID = {{ coorHostNodeIDlist }} dbaUser = gbase dbaGroup = gbase dbaPwd = '{{ gbase_passwd }}' rootPwd = '{{ root_passwd }}' characterSet = {{ db_charset }} Environment Installation and Deployment - name: Install and deploy GBase shell: 'sh ansible_install.sh' when: "gbaseRole == 'coor' and RoleId == 1" tags: install become: true become_user: gbase ansible_install.sh Script

Feb 7, 2025 - 04:16
 0
GBASE数据库 | GBase 8a Cluster Automated Installation and Deployment Using ansible

In this article, we will guide you through the process of automating the installation and deployment of a GBase 8a cluster using Ansible. This solution simplifies the deployment of the GBase 8a database (GBase数据库) in a cluster environment, making it easier to manage and scale.

Host Configuration

An example configuration is as follows:

[all]
192.168.56.3 gbaseRole=coor RoleId=1 vc_name='' private_ip1=192.168.56.3 private_ip2=192.168.56.3 
192.168.56.4 gbaseRole=newcoor RoleId=1 vc_name=vc1 private_ip1=192.168.56.4 private_ip2=192.168.56.6 
192.168.56.5 gbaseRole=newnode RoleId=2 vc_name=vc1 private_ip1=192.168.56.4 private_ip2=192.168.56.6 
192.168.56.6 gbaseRole=node RoleId=1 vc_name=vc2 private_ip1=192.168.56.4 private_ip2=192.168.56.6
  • 192.168.56.3: Business network IP
  • gbaseRole: The role of GBase (management node: coor, compute node: node)
  • RoleId: Role ID, fill in sequentially
  • vc_name: Virtual Cluster name for compute nodes, leave empty for management nodes, set to data in compatibility mode
  • private_ip1: Private network IP address 1 for compute nodes
  • private_ip2: Private network IP address 2 for compute nodes (not required for single-instance setups)

Variables Explanation

# GBase installation package name
gbase_setup_file: 'xxxx.tar.bz2'
# Operating system root password
root_passwd: '111111'
# GBase password for the operating system
gbase_passwd: '111111'
# Database DBA user (root, gbase) password
dba_password: '111111'
# Database character set (utf8, utf8mb4, gbk, etc.)
db_charset: utf8
vc_lists: ['vc1']
# Management node ID list, generally recommended to be the IP address's last segment, separated by commas
coorHostNodeIDlist: '1,2,3'

Task Descriptions

Initial Installation Preparation

- name: Install necessary RPM packages
  yum: name={{ item }} state=installed
  with_items:
    - bzip2
    - expect
    - gcc
    - '*cgroup*'
    - bc  
    - numactl
    - rsync
  tags:
    init_env

- name: Upload GBase installation package
  copy: 
    src: files/{{ gbase_setup_file }} 
    dest: /opt/
  when: "gbaseRole == 'coor' and RoleId == 1"
  tags:
    init_env

- name: Extract GBase installation package
  unarchive:
    src: /opt/{{ gbase_setup_file }}
    dest: /opt/
    remote_src: yes
  when: "gbaseRole == 'coor' and RoleId == 1"
  tags:
    init_env

- name: Create GBase user
  user:
    name: gbase
    state: present
    update_password: always
    password: '{{ gbase_passwd | password_hash('sha512') }}'
  tags:
    init_env

- name: Change ownership of /opt directory
  file:
    path: /opt
    state: directory
    owner: gbase
    group: gbase
    recurse: yes
  tags:
    init_env

- name: Upload system environment variable initialization script
  copy: 
    src: SetSysEnv.py
    dest: /tmp
  tags:
    init_env

- name: Initialize system environment variables
  shell: 'python /tmp/SetSysEnv.py --dbaUser=gbase --installPrefix=/opt --cgroup'
  tags:
    init_env

Generate Installation Configuration File

- name: Generate installation configuration file
  template: 
    src: demo.options.j2
    dest: /opt/gbase_workspace/setup/gcinstall/demo.options
  when: "gbaseRole == 'coor' and RoleId == 1 and InstanceType == 0"
  tags:
    install           
  become: true
  become_user: gbase
demo.options.j2 Template:
installPrefix= /opt
coordinateHost = {% for host in groups['all'] -%}
        {% if hostvars[host]['gbaseRole']=='coor' -%}
                {% if hostvars[host]['RoleId'] == 1 -%}
                        {{ hostvars[host]['private_ip1'] }}
                {%- else -%}
                        ,{{ hostvars[host]['private_ip1'] }}
                {%- endif %}
        {%- endif %}
{%- endfor %}

coordinateHostNodeID = {{ coorHostNodeIDlist }}
dataHost = {% for host in groups['all'] -%}
        {% if hostvars[host]['gbaseRole']=='node' -%}
                {% if hostvars[host]['RoleId'] == 1 -%}
                        {{ hostvars[host]['private_ip1'] }}
                {%- else -%}
                        ,{{ hostvars[host]['private_ip1'] }}
                {%- endif %}
        {%- endif %}
{%- endfor %}

gcwareHost = {% for host in groups['all'] -%}
        {% if hostvars[host]['gbaseRole']=='coor' -%}
                {% if hostvars[host]['RoleId'] == 1 -%}
                        {{ hostvars[host]['private_ip1'] }}
                {%- else -%}
                        ,{{ hostvars[host]['private_ip1'] }}
                {%- endif %}
        {%- endif %}
{%- endfor %}

gcwareHostNodeID = {{ coorHostNodeIDlist }}
dbaUser = gbase
dbaGroup = gbase
dbaPwd = '{{ gbase_passwd }}'
rootPwd = '{{ root_passwd }}'
characterSet = {{ db_charset }}

Environment Installation and Deployment

- name: Install and deploy GBase
  shell: 'sh ansible_install.sh'
  when: "gbaseRole == 'coor' and RoleId == 1"
  tags:
    install
  become: true
  become_user: gbase
ansible_install.sh Script:
#!/usr/bin/sh
###########################################################
##creator :                                               
##create time:                                       
##Description: Silent installation script
##Version:                                            
###########################################################

cd /opt/gcinstall
spawn python gcinstall.py --silent=demo.options -i
expect {
  "*])?" {send "y\r"; exp_continue}
  "*])?" {send "y\r"; exp_continue}
}

Re-initialize System Environment Variables

- name: Reinitialize system environment variables
  shell: 'python /tmp/SetSysEnv.py --dbaUser=gbase --installPrefix=/opt --cgroup'
  tags:
    init_env

Generate VC Creation Configuration File

- name: Generate VC creation configuration file
  vars:
    cur_vcname: "{{ item }}"  
  template: 
    src: createvc.xml.j2
    dest: /opt/gcinstall/createvc_{{ item }}.xml
  when: "gbaseRole == 'coor' and RoleId == 1"
  with_items:
    "{{ vc_lists }}"
  tags:
    install          
  become: true
  become_user: gbase
createvc.xml.j2 Template:



{% for host in groups['all'] %}
{% if hostvars[host]['vc_name']==cur_vcname %}
    
         ip="{{ hostvars[host]['private_ip1'] }}"/>
    
{% endif %}
{% endfor %}

     name="{{ cur_vcname }}"/>
     message="{{ cur_vcname }}"/>


Create VC

- name: Create VC
  shell: 'source ~/.bash_profile; cd /opt/gcinstall; gcadmin createvc createvc_{{ item }}.xml'
  when: "gbaseRole == 'coor' and RoleId == 1"
  with_items:
    "{{ vc_lists }}"
  tags:
    install
  become: true
  become_user: gbase

Generate Distribution Creation Configuration File

- name: Generate initialization configuration file
  vars:
    cur_vcname: "{{ item }}"  
  template: 
    src: gcChangeInfo_vcname.xml.j2
    dest: /opt/gcinstall/gcChangeInfo_{{ item }}.xml
  when: "gbaseRole == 'coor' and RoleId == 1"
  with_items:
    "{{ vc_lists }}"
  tags:
    install          
  become: true
  become_user: gbase

Generate Configuration File Template for Creating Distribution (gcChangeInfo_vcname.xml.j2)

installPrefix= /opt
coordinateHost = {% for host in groups['all'] -%}
        {% if hostvars[host]['gbaseRole']=='coor' -%}
                {% if hostvars[host]['RoleId'] == 1 -%}
                        {{ hostvars[host]['private_ip1'] }}
                {%- else -%}
                        ,{{ hostvars[host]['private_ip1'] }}
                {%- endif %}
        {%- endif %}
{%- endfor %}

coordinateHostNodeID = {{ coorHostNodeIDlist }}
dataHost = {% for host in groups['all'] -%}
        {% if hostvars[host]['gbaseRole']=='node' -%}
                {% if hostvars[host]['RoleId'] == 1 -%}
                        {{ hostvars[host]['private_ip1'] }}
                {%- else -%}
                        ,{{ hostvars[host]['private_ip1'] }}
                {%- endif %}
        {%- endif %}
{%- endfor %}

#existCoordinateHost =
#existDataHost =
#existGcwareHost=
gcwareHost = {% for host in groups['all'] -%}
        {% if hostvars[host]['gbaseRole']=='coor' -%}
                {% if hostvars[host]['RoleId'] == 1 -%}
                        {{ hostvars[host]['private_ip1'] }}
                {%- else -%}
                        ,{{ hostvars[host]['private_ip1'] }}
                {%- endif %}
        {%- endif %}
{%- endfor %}

gcwareHostNodeID = {{ coorHostNodeIDlist }}
dbaUser = gbase
dbaGroup = gbase
dbaPwd = '{{ gbase_passwd }}'
rootPwd = '{{ root_passwd }}'
#dbRootPwd = ''
#rootPwdFile = rootPwd.json
characterSet = {{ db_charset }}
#sshPort = 22

Create Distribution

- name: Initialize distribution for VC (multi-VC mode)
    shell: "source ~/.bash_profile; cd /opt/gcinstall; gcadmin distribution gcChangeInfo_{{ item }}.xml p 1 d 1 db_user gbase db_pwd 'gbase20110531' dba_os_password '{{ gbase_passwd }}' vc {{ item }}"
    when: "gbaseRole == 'coor' and RoleId == 1"
    with_items:
      "{{ vc_lists }}"
    tags:
      install
    become: true
    become_user: gbase

Initialize nodedatamap

- name: Initialize nodedatamap for VC
    vars:
      cur_vcname: "{{ item }}"  
    shell: 'source ~/.bash_profile; gccli -ugbase -pgbase20110531 -e"use vc {{ item }}; initnodedatamap;"'
    when: "gbaseRole == 'coor' and RoleId == 1"
    with_items:
      "{{ vc_lists }}"
    tags:
      install    
    become: true
    become_user: gbase

Conclusion

By automating the installation and deployment of GBase 8a clusters (GBase数据库) with Ansible, you can significantly reduce manual intervention and increase the efficiency of your database environment. This method is particularly useful for large-scale deployments and environments where consistency is crucial.

If you have any questions or need further clarification, feel free to reach out in the comments or via direct messages.