1. 首页 > GoldenGate教程 > 正文

GoldenGate教程FG080-OGG自动化部署脚本(Ansible)开发实战

目录大纲

内容简介

本篇文章介绍如何使用Ansible自动化工具开发OGG部署脚本,实现从环境准备、软件安装到配置调优的全流程自动化。风哥教程参考GoldenGate官方文档自动化部署指南和Ansible最佳实践。

Part01-基础概念与理论知识

1.1 Ansible自动化部署原理

Ansible是一种基于Python开发的自动化工具,通过SSH协议实现无代理部署,具有以下特点:

  • 基于YAML的声明式配置
  • 无代理架构,减少依赖
  • 强大的模块生态系统
  • 支持变量和模板系统

1.2 OGG部署架构与组件

OGG部署架构主要包括以下组件:

  • Manager进程:控制其他OGG进程
  • Extract进程:从源数据库捕获变更数据
  • Replicat进程:将数据应用到目标数据库
  • Data Pump:用于数据分发

更多视频教程www.fgedu.net.cn

Part02-生产环境规划与建议

2.1 系统硬件要求

风哥提示:根据OGG官方文档,生产环境建议配置至少4核CPU、16GB内存,以及足够的存储空间用于安装文件和日志。

2.2 网络与安全配置

网络要求:

  • 源端和目标端之间网络带宽至少1Gbps
  • 开放必要的端口(默认7809)
  • 配置SSH免密登录

Part03-生产环境项目实施方案

3.1 Ansible环境搭建

# 安装Ansible
$ sudo yum install epel-release -y
$ sudo yum install ansible -y

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
–> Running transaction check
—> Package ansible.noarch 0:2.9.27-1.el7 will be installed
–> Processing Dependency: python2-crypto for package: ansible-2.9.27-1.el7.noarch
–> Processing Dependency: python2-jinja2 for package: ansible-2.9.27-1.el7.noarch
–> Processing Dependency: python2-paramiko for package: ansible-2.9.27-1.el7.noarch
–> Processing Dependency: python2-pyyaml for package: ansible-2.9.27-1.el7.noarch
–> Processing Dependency: python2-six for package: ansible-2.9.27-1.el7.noarch
–> Running transaction check
—> Package python2-crypto.x86_64 0:2.6.1-2.el7 will be installed
—> Package python2-jinja2.noarch 0:2.7.2-4.el7 will be installed
—> Package python2-paramiko.noarch 0:2.1.1-9.el7 will be installed
—> Package python2-pyyaml.x86_64 0:3.10-11.el7 will be installed
—> Package python2-six.noarch 0:1.9.0-2.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
ansible noarch 2.9.27-1.el7 epel 16 M
Installing for dependencies:
python2-crypto x86_64 2.6.1-2.el7 base 471 k
python2-jinja2 noarch 2.7.2-4.el7 base 515 k
python2-paramiko noarch 2.1.1-9.el7 base 269 k
python2-pyyaml x86_64 3.10-11.el7 base 153 k
python2-six noarch 1.9.0-2.el7 base 29 k

Transaction Summary
================================================================================
Install 1 Package (+5 Dependencies)

Total download size: 18 M
Installed size: 87 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python2-six-1.9.0-2.el7.noarch 1/6
Installing : python2-pyyaml-3.10-11.el7.x86_64 2/6
Installing : python2-jinja2-2.7.2-4.el7.noarch 3/6
Installing : python2-crypto-2.6.1-2.el7.x86_64 4/6
Installing : python2-paramiko-2.1.1-9.el7.noarch 5/6
Installing : ansible-2.9.27-1.el7.noarch 6/6
Verifying : python2-jinja2-2.7.2-4.el7.noarch 1/6
Verifying : python2-paramiko-2.1.1-9.el7.noarch 2/6
Verifying : python2-pyyaml-3.10-11.el7.x86_64 3/6
Verifying : python2-six-1.9.0-2.el7.noarch 4/6
Verifying : ansible-2.9.27-1.el7.noarch 5/6
Verifying : python2-crypto-2.6.1-2.el7.x86_64 6/6

Installed:
ansible.noarch 0:2.9.27-1.el7

Dependency Installed:
python2-crypto.x86_64 0:2.6.1-2.el7 python2-jinja2.noarch 0:2.7.2-4.el7
python2-paramiko.noarch 0:2.1.1-9.el7 python2-pyyaml.x86_64 0:3.10-11.el7
python2-six.noarch 0:1.9.0-2.el7

Complete!

3.2 OGG自动化部署脚本开发

创建Ansible Playbook结构:

# 目录结构
ogg_deploy/
├── inventory/
│ └── hosts
├── roles/
│ ├── ogg_install/
│ │ ├── tasks/
│ │ │ └── main.yml
│ │ ├── templates/
│ │ │ ├── manager.prm.j2
│ │ │ └── extract.prm.j2
│ │ └── files/
│ │ └── fbo_ggs_Linux_x64_shiphome.zip
│ └── ogg_config/
│ └── tasks/
│ └── main.yml
└── ogg_deploy.yml

inventory/hosts文件:

[ogg_servers]
fgedu.net.cn ansible_ssh_user=root

ogg_deploy.yml主Playbook:


– name: OGG Automation Deployment
hosts: ogg_servers
become: yes
roles:
– ogg_install
– ogg_config

roles/ogg_install/tasks/main.yml:


– name: Install required packages
yum:
name:
– unzip
– gcc
– libaio
state: present

– name: Create OGG user
user:
name: ogg
groups: oinstall,dba
shell: /bin/bash
home: /GoldenGate/app/ogg

– name: Create OGG directories
file:
path: “{{ item }}”
state: directory
owner: ogg
group: oinstall
mode: ‘0755’
with_items:
– /GoldenGate/app/ogg
– /GoldenGate/app/ogg/dirprm
– /GoldenGate/app/ogg/dirrpt
– /GoldenGate/app/ogg/dirdat
– /GoldenGate/app/ogg/dirchk

– name: Copy OGG installation file
copy:
src: files/fbo_ggs_Linux_x64_shiphome.zip
dest: /GoldenGate/app/ogg/
owner: ogg
group: oinstall

– name: Unzip OGG installation file
unarchive:
src: /GoldenGate/app/ogg/fbo_ggs_Linux_x64_shiphome.zip
dest: /GoldenGate/app/ogg/
remote_src: yes
owner: ogg
group: oinstall

– name: Install OGG
shell: |
cd /GoldenGate/app/ogg/fbo_ggs_Linux_x64_shiphome/Disk1
./runInstaller -silent -responseFile /GoldenGate/app/ogg/response.rsp
become: yes
become_user: ogg

– name: Create OGG manager parameter file
template:
src: templates/manager.prm.j2
dest: /GoldenGate/app/ogg/dirprm/mgr.prm
owner: ogg
group: oinstall

– name: Start OGG Manager
shell: |
cd /GoldenGate/app/ogg
./ggsci << EOF start mgr exit EOF become: yes become_user: ogg

学习交流加群风哥微信: itpux-com

Part04-生产案例与实战讲解

4.1 单机部署实战

# 执行Ansible Playbook进行单机部署
$ ansible-playbook -i inventory/hosts ogg_deploy.yml

PLAY [OGG Automation Deployment] ****************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************
ok: [fgedu.net.cn]

TASK [ogg_install : Install required packages] **************************************************************************************
ok: [fgedu.net.cn]

TASK [ogg_install : Create OGG user] ***********************************************************************************************
ok: [fgedu.net.cn]

TASK [ogg_install : Create OGG directories] ****************************************************************************************
ok: [fgedu.net.cn] => (item=/GoldenGate/app/ogg)
ok: [fgedu.net.cn] => (item=/GoldenGate/app/ogg/dirprm)
ok: [fgedu.net.cn] => (item=/GoldenGate/app/ogg/dirrpt)
ok: [fgedu.net.cn] => (item=/GoldenGate/app/ogg/dirdat)
ok: [fgedu.net.cn] => (item=/GoldenGate/app/ogg/dirchk)

TASK [ogg_install : Copy OGG installation file] ************************************************************************************
ok: [fgedu.net.cn]

TASK [ogg_install : Unzip OGG installation file] ***********************************************************************************
ok: [fgedu.net.cn]

TASK [ogg_install : Install OGG] ***************************************************************************************************
ok: [fgedu.net.cn]

TASK [ogg_install : Create OGG manager parameter file] ****************************************************************************
ok: [fgedu.net.cn]

TASK [ogg_install : Start OGG Manager] ********************************************************************************************
ok: [fgedu.net.cn]

TASK [ogg_config : Configure OGG] **************************************************************************************************
ok: [fgedu.net.cn]

PLAY RECAP **************************************************************************************************************************
fgedu.net.cn : ok=10 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

4.2 分布式部署实战

修改inventory/hosts文件,添加多个节点:

[ogg_servers]
fgedu01.net.cn ansible_ssh_user=root
fgedu02.net.cn ansible_ssh_user=root

[source]
fgedu01.net.cn

[target]
fgedu02.net.cn

执行分布式部署:

$ ansible-playbook -i inventory/hosts ogg_distributed_deploy.yml

PLAY [OGG Distributed Deployment] **************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************
ok: [fgedu01.net.cn]
ok: [fgedu02.net.cn]

TASK [ogg_install : Install required packages] **************************************************************************************
ok: [fgedu01.net.cn]
ok: [fgedu02.net.cn]

TASK [ogg_install : Create OGG user] ***********************************************************************************************
ok: [fgedu01.net.cn]
ok: [fgedu02.net.cn]

TASK [ogg_install : Create OGG directories] ****************************************************************************************
ok: [fgedu01.net.cn] => (item=/GoldenGate/app/ogg)
ok: [fgedu02.net.cn] => (item=/GoldenGate/app/ogg)
ok: [fgedu01.net.cn] => (item=/GoldenGate/app/ogg/dirprm)
ok: [fgedu02.net.cn] => (item=/GoldenGate/app/ogg/dirprm)
ok: [fgedu01.net.cn] => (item=/GoldenGate/app/ogg/dirrpt)
ok: [fgedu02.net.cn] => (item=/GoldenGate/app/ogg/dirrpt)
ok: [fgedu01.net.cn] => (item=/GoldenGate/app/ogg/dirdat)
ok: [fgedu02.net.cn] => (item=/GoldenGate/app/ogg/dirdat)
ok: [fgedu01.net.cn] => (item=/GoldenGate/app/ogg/dirchk)
ok: [fgedu02.net.cn] => (item=/GoldenGate/app/ogg/dirchk)

TASK [ogg_install : Copy OGG installation file] ************************************************************************************
ok: [fgedu01.net.cn]
ok: [fgedu02.net.cn]

TASK [ogg_install : Unzip OGG installation file] ***********************************************************************************
ok: [fgedu01.net.cn]
ok: [fgedu02.net.cn]

TASK [ogg_install : Install OGG] ***************************************************************************************************
ok: [fgedu01.net.cn]
ok: [fgedu02.net.cn]

TASK [ogg_install : Create OGG manager parameter file] ****************************************************************************
ok: [fgedu01.net.cn]
ok: [fgedu02.net.cn]

TASK [ogg_install : Start OGG Manager] ********************************************************************************************
ok: [fgedu01.net.cn]
ok: [fgedu02.net.cn]

TASK [ogg_config : Configure OGG on source] ****************************************************************************************
ok: [fgedu01.net.cn]

TASK [ogg_config : Configure OGG on target] ****************************************************************************************
ok: [fgedu02.net.cn]

PLAY RECAP **************************************************************************************************************************
fgedu01.net.cn : ok=11 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
fgedu02.net.cn : ok=11 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

学习交流加群风哥QQ113257174

Part05-风哥经验总结与分享

5.1 常见问题与解决方案

  • 问题1:Ansible执行时报错”Permission denied”

    解决方案:确保目标主机已配置SSH免密登录,或使用–ask-pass参数
  • 问题2:OGG安装失败

    解决方案:检查系统依赖包是否安装,确保磁盘空间充足
  • 问题3:Manager进程无法启动

    解决方案:检查端口是否被占用,查看ggserr.log日志

5.2 最佳实践建议

  • 使用版本控制管理Ansible Playbook
  • 配置变量文件,实现环境隔离
  • 定期备份OGG配置文件
  • 使用Ansible Vault加密敏感信息
  • 实现部署后的健康检查
风哥提示:在生产环境中,建议先在测试环境验证Ansible脚本,确保部署过程稳定可靠后再应用到生产环境。

更多学习教程公众号风哥教程itpux_com

from GoldenGate视频:www.itpux.com

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息