host配置说明
示例如下:
[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: 业务网络IP
- gbaseRole: gbase的角色(管理节点:coor、计算节点:node)
- RoleId:角色ID,请按照顺序填写,
- vc_name:计算节点所属vc名称,管理节点设置为空,兼容模式设置成data
- private_ip1:计算节点私网IP地址1
- private_ip2:计算节点私网IP地址2,如果是单实例,该参数不需要配置
vars说明
#gbase的安装文件名称
gbase_setup_file: 'xxxx.tar.bz2'
#操作系统的root密码
root_passwd: '111111'
#操作系统的gbase设置密码
gbase_passwd: '111111'
#数据库dba用户(root、gbase)的设置密码
dba_password: '111111'
#数据库的字符集类型(utf8、utf8mb4、gbk等等)
db_charset: utf8
vc_lists: ['vc1']
#安装时的管理节点ID列表,一般建议为IP的d段,加,分割
coorHostNodeIDlist: '1,2,3'
tasks说明
前期安装准备
- name: 安装必要的rpm包
yum: name={{ item }} state=installed
with_items:
- bzip2
- expect
- gcc
- '*cgroup*'
- bc
- numactl
- rsync
tags:
init_env
- name: 上传数据库安装包
copy:
src: files/{{ gbase_setup_file }}
dest: /opt/
when: "gbaseRole == 'coor' and RoleId == 1"
tags:
init_env
- name: 解压数据库安装包
unarchive:
src: /opt/{{ gbase_setup_file }}
dest: /opt/
remote_src: yes
when: "gbaseRole == 'coor' and RoleId == 1"
tags:
init_env
- name: 创建gbase用户
user:
name: gbase
state: present
update_password: always
password: '{{ gbase_passwd | password_hash(''sha512'')}}'
tags:
init_env
- name: 更改opt目录属主
file:
path: /opt
state: directory
owner: gbase
group: gbase
recurse: yes
tags:
init_env
- name: 上传系统环境变量初始化脚本
copy:
src: SetSysEnv.py
dest: /tmp
tags:
init_env
- name: 初始化系统环境变量
shell: 'python /tmp/SetSysEnv.py --dbaUser=gbase --installPrefix=/opt --cgroup'
tags:
init_env
* 生成安装配置文件
- name: 生成安装配置文件
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
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
进行环境安装部署
- name: 安装部署
shell: 'sh ansible_install.sh'
when: "gbaseRole == 'coor' and RoleId == 1"
tags:
install
become: true
become_user: gbase
* ansible_install.sh
##!//usr/bin/sh
###########################################################
##creator :
##create time:
##Decription: 静默安装脚本
##Version:
###########################################################
cd /opt/gcinstall
spawn python gcinstall.py --silent=demo.options -i
expect {
"*])?" {send "y\r"; exp_continue}
"*])?" {send "y\r"; exp_continue}
}
重新初始化环境变量
- name: 初始化系统环境变量
shell: 'python /tmp/SetSysEnv.py --dbaUser=gbase --installPrefix=/opt --cgroup'
tags:
init_env
生成创建vc的配置文件
- name: 生成创建vc的配置文件
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
* 生成vc配置文件的模板createvc.xml.j2
<?xml version='1.0' encoding="utf-8"?>
<servers>
{% for host in groups['all'] %}
{% if hostvars[host]['vc_name']==cur_vcname %}
<rack>
<node ip="{{ hostvars[host]['private_ip1'] }}"/>
</rack>
{% endif %}
{% endfor %}
<vc_name name="{{ cur_vcname }}"/>
<comment message="{{ cur_vcname }}"/>
</servers>
* 创建vc
- name: 创建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
* 生成创建distribution的配置文件
- name: 生成初始化配置文件
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
* 生成创建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
创建distribution
- name: 初始化vc的distribution(多vc模式)
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
初始化nodedatamap
- name: 初始化vc的nodedatamap
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