ansible 部署基于windows 2008 r2+rsync+alwaysUp(守护进程)
准备:升级PowerShell3.0 及打开WinRM模块alwaysUp https://www.coretechnologies.com/products/AlwaysUp/
AlwaysUpCLT https://www.coretechnologies.com/products/AlwaysUp/AlwaysUpCLT/
inno setup http://www.jrsoftware.org/isinfo.php 本机安装制作AlwaysUpCLT 安装包
rsync服务器文件同步使用,alwaysUp 守护进程工具应用程序启动使用 为了安全不提供安装文件
1、ansible 目录结构
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
├── alwaysUp
│ └── daemon_alwaysup.xml.j2 #alwaysup添加apps模板
├── AlwaysUpCLT.iss # AlwaysUpCLT 安装包 官方提供的是zip包 ansible 替换文件问题很多做成exe静默安装更快
├── alwaysUp.retry # ansible 运行产生的hosts文件
├── alwaysUp.yml # 使用ansible 导入alwaysup模板文件
├── hosts # 服务器ip存放文件
├── roles
│ ├── alwaysup
│ │ ├── defaults
│ │ ├── files
│ │ │ ├── AlwaysUpCLT.exe #客户机安装使用
│ │ │ └── AlwaysUp_Installer.exe #客户机安装使用
│ │ ├── handlers
│ │ ├── meta
│ │ ├── tasks
│ │ │ └── main.yml #ansible 安装守护进程文件
│ │ ├── templates
│ │ └── vars
│ └── cwRsyncServer
│ ├── defaults
│ ├── files
│ │ ├── cwRsyncServer_4.1.0_Installer.exe # rsync 服务器安装文件
│ │
│ ├── handlers
│ ├── meta
│ ├── tasks
│ │ └── main.yml #ansible 安装rsync文件
│ ├── templates
│ │ └── rsyncd.conf.j2 # rsync 服务器配置文件
│ └── vars
├── site.retry # ansible 运行产生的hosts文件
├── site.yml# ansible 安装守护进程及rsync服务器使用
└── win_env.bat # 环境变量文件 ansible 操作 windows 环境变量很麻烦为了通
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
site.yml 说明:
- hosts: '{{host}}' #变量安装服务器别名
# gather_facts: False # 是否获取客户机的setup变量 部署软件建议注释掉
vars:
rsync_port: 9999 # rsync 服务器端口
rsync_node: test # 访问rsync路径标签
rsync_path: c/test # rsync 服务器配置路径
sync_file: c:\test # 创建rsync 服务器数据路径
rsync_ip: 192.168.0.210 , 192.168.7.233 # rsync 服务器允许访问IP
win_env: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\ # 使用ansible 操作环境变量默认系统环境变量每台服务器环境变量不一样不通用本案例没使用
rsync_env: C:\"Program Files (x86)"\ICW\bin # rsync path变量
alwaysup_env: C:\"Program Files (x86)"\AlwaysUp # AlwaysUppath 变量
roles:
- cwRsyncServer #ansible 安装 cwRsyncServer
- alwaysup #ansible 安装alwaysup
tasks:
- name: evn
#win_environment: #ansible 操作Windows 环境变量
#state: present
#name: Path
#value: '{{ win_env }};"{{ rsync_env }}";"{{ alwaysup_env }}"'
#level: machine
# when: ( rsync_path_register.stat.exists == False ) and (alwaysup_path_register.stat.exists == False)
script: win_env.bat {{ rsync_env }} {{ alwaysup_env }} # 使用脚本操作系统环境变量
when: ( rsync_path_register.stat.exists == False ) and (alwaysup_path_register.stat.exists == False)
alwaysup 安装文件说明
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
- win_stat: path='C:/Program Files (x86)/AlwaysUp' #获取是否安装路径
register: alwaysup_path_register
- win_stat: path='C:/temp' #获取是否创建 C:/temp
register: temp_path_register
- name: create c:\temp toclient
raw:'CMD /C "mkdirc:\temp "' # 创建C:/temp 如果没有
when: temp_path_register.stat.exists == False
#copy AlwaysUp_Installer.exe config to client
- win_copy: src={{ item }} dest=c:/TEMP/{{ item }} # 上传文件到客户机c:/TEMP
with_items:
- AlwaysUp_Installer.exe
- AlwaysUpCLT.exe
when: alwaysup_path_register.stat.exists == False
- name: intsatll AlwaysUp to clien # 安装AlwaysUp
raw: c:/TEMP/AlwaysUp_Installer.exe/sp- /verysilent /norestart
when: alwaysup_path_register.stat.exists == False
- name: intsatll AlwaysUpCLT to clien # 安装AlwaysUpCLT
raw: c:/TEMP/AlwaysUpCLT.exe /VERYSILENT -SP
when: alwaysup_path_register.stat.exists == False
- name: rd c:\temp 删除 c:\temp 文件
raw: CMD /C 'del /s /q /f c:\temp\*.*'
when: alwaysup_path_register.stat.exists == False
cwRsyncServer 说明
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- win_stat: path='C:/Program Files (x86)/ICW/bin' # 判断是否安装rsync
register: rsync_path_register
- win_stat: path='C:/temp' # 判断是否创建 C:/temp
register: temp_path_register
- name: create c:\temp toclient
raw:'CMD /C "mkdirc:\temp" ' #没有就创建C:/temp
when: temp_path_register.stat.exists == False
#create c:\{{ sync_file }} rsyncserver to clien
- win_file: path={{ sync_file }} state=directory # 创建rsync 数据存放文件夹
when: rsync_path_register.stat.exists == False
#copy rsync config to client
- win_copy: src=cwRsyncServer_4.1.0_Installer.exe dest=c:/TEMP/cwRsyncServer_4.1.0_Installer.exe # 上传rsync 安装文件
when: rsync_path_register.stat.exists == False
- name: intsatll rsyncserver to clien
raw: CMD /C 'c:\TEMP\cwRsyncServer_4.1.0_Installer.exe /S' # 安装rsync服务 文件名字有改变请修改脚本文件
when: rsync_path_register.stat.exists == False
#cp rsyncd.conf # 上传rsync 配置文件
- win_template:
src=\'#\'" /C 'del /s /q /f c:\temp\*.*' # 删除 c:\temp 文件
when: rsync_path_register.stat.exists == False
alwaysUp.yml 说明
1
2
3
4
5
6
7
8
9
10
11
12
13
14
- hosts: '{{host}}' # host 标签
#gather_facts: False
vars:
daemon_ver: 9.7.2.88 # AlwaysUp 版本好apps xml文件用到
daemon_name: notepad # AlwaysUp 友好名字
daemon_path: C:\Windows\system32\notepad.exe # 服务器启动路径绝对路径
daemon_parameter:# 文件启动参数如:.\.\test.ini -d 参数
tasks:
- win_file: path=c:/alwaysUp state=directory # 创建appsxml文件存放文件夹
- win_template:
src=\'#\'" /daemon_alwaysup.xml.j2 # 上传 apps 文件
dest: 'c:/alwaysUp/{{ daemon_name }}_alwaysup.xml'
- name: Import "{{ daemon_name }}"_alwaysup.xml
raw: CMD /C 'InstallService.exe -xml c:\alwaysUp\{{ daemon_name }}_alwaysup.xml' 导入xml 到 alwaysUp 守护进程
rsync 使用简单说明:
1
2
3
4
5
6
7
上传文件到rsync服务器
cd /d C:\Program Files (x86)\cwRsync\bin
rsync --port=9999 -rvzc --ignore-errors --no-iconv --delete --progress --exclude-from='/cygdrive/F/scripts/exclude' 排除文件配置 /cygdrive/F/test/ 本地地址rsync://192.168.1.19/test/ 服务器路径
下载rsync 文件
cd /d C:\Program Files (x86)\cwRsync\bin
rsync --port=9999 -rvzc --ignore-errors --no-iconv --delete --progress --exclude-from='/cygdrive/F/scripts/exclude' 排除文件配置rsync://192.168.1.19/test/ 服务器路径/cygdrive/F/test/ 本地地址
可以使用Jenkins 推送文件到服务器 也可以使用ansible拉去文件
AlwaysUp 使用说明:
1
2
3
4
5
6
7
8
9
10
11
UninstallService.exe "test" # 删除守护进程apps
InstallService.exe -xml c:\test_alwaysup.xml # 导入apps守护进程
AlwaysUp.exe -start-all-in-current-session # 启动所有程序并显示界面
AlwaysUp.exe -start-all # 启动所有程序
AlwaysUp.exe -restart-all-in-current-session # 重启所有程序
AlwaysUp.exe -start-in-current-session "test" # 启动某个程序并显示界面 如果有
AlwaysUp.exe -start-in "test" #启动摸个程序
AlwaysUp.exe -restart-in-current-session "test" #重启某个程序并显示界面 如果有
AlwaysUp.exe -restart "test" #重启某个程序
AlwaysUp.exe -stop "test" #关闭某个程序
AlwaysUp.exe -stop-all # 关闭所有程序守护进程不在守护
AlwaysUpCLT.iss 说明:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
;------------------------------------------------
;
; AlwaysUpCLT安装脚本
;------------------------------------------------
;公司信息
AppName=AlwaysUpCLTUpCLT
AppVerName=AlwaysUpCLT
AppPublisher=www.coretechnologies.com
AppCopyright=www.coretechnologies.com
AppPublisherURL=www.coretechnologies.com
AppId =www.coretechnologies.com
;版本信息
VersionInfoVersion=6.0.1.0
VersionInfoDescription="AlwaysUpCLTUpCLT"
;安装目录
DefaultDirName=C:\Program Files (x86)\AlwaysUp # 安装路径
DefaultGroupName=AlwaysUpCLTUpCLT
;输出配置
OutputDir= D:\桌面\aa # 打包输出exe 路径
SourceDir= D:\桌面\aa\AlwaysUpCLT # 打包源码路径
OutputBaseFilename=AlwaysUpCLT # 打包生成的exe文件名字
;编译选项
Compression=zip/9 # 压缩比例
SolidCompression=yes
;环境选项
Uninstallable=no
DisableDirPage=yes
CreateUninstallRegKey=no
UsePreviousAppDir=no
;AlwaysUpCLT
Source: "AlwaysUpService.exe"; DestDir: "{app}"; Flags: igNoreversion
Source: "InstallService.exe"; DestDir: "{app}"; Flags: igNoreversion
Source: "UninstallService.exe"; DestDir: "{app}"; Flags: igNoreversion
Source: "EventMessageFile.dll"; DestDir: "{app}"; Flags: igNoreversion
Source: "GHCrUtils.dll"; DestDir: "{app}"; Flags: igNoreversion
Source: "XML\*"; DestDir: "{app}\XML\"; Flags: igNoreversion recursesubdirs createallsubdirs
Source: "SanityCheck\*"; DestDir: "{app}\SanityCheck\"; Flags: igNoreversion recursesubdirs createallsubdirs
Source: "Documentation\*"; DestDir: "{app}\Documentation\"; Flags: igNoreversion recursesubdirs createallsubdirs
其它:
1
2
3
4
5
6
7
使用ansible 安装程序
ansible-playbook -i hosts site.yml -verbose --extra-vars "host=test(hosts 文件配置节点)"
导入 alwaysUp 守护进程apps配置文件
ansible-playbook -i hosts alwaysUp.yml -verbose --extra-vars "host=test daemon_name=calc daemon_path=C:\Windows\System32\calc.exe daemon_parameter=-a" 强制使用外部参数这样就能随机创建启动apps
xml 模板文件还可以根据自己情况进行修改添加邮件报警端口监控等等。
alwaysUp注册机附带附件建议在本地电脑运行,不用复制到服务器。
所有脚本放到附件
页:
[1]