Fleet问题
来源:互联网 发布:网络老虎机平台 编辑:程序博客网 时间:2024/06/05 16:30
机器:10.58.9.85 / 10.58.9.82 / 10.58.9.83 / 10.58.9.86
概念:(以下名称中Unit也可以称作Service,如UnitFile也可以叫ServiceFile)
(1)UnitFile :单元文件,类似Java类的概念,例子https://github.com/coreos/fleet/blob/master/Documentation/examples/example-deployment.md
(2)Unit:单元实例,对应概念Java实例</p>
(3)TemplateUnitFile:示例:wys-wpa@.service, 这是一个TemplateUnitFile,如果我们想通过这个模板UnitFile来启动多个Unit,可以这样
fleetctl start wys-wpa@{1..3}.service
wys-wpa@1.service <span style="font-family: Arial, Helvetica, sans-serif;">336043c3.../10.58.9.85 active running</span>
wys-wpa@2.service 364cd1ff.../10.58.9.83 active runningwys-wpa@3.service 364cd1ff.../10.58.9.83 active running
这里面的每一个在跑的Unit我们叫做一个Unit的实例,如wys-wpa@1.service可以称作wys-wpa实例1,他们都对应一个UntFile,只是可能通过Unit名称传进去的参数不同
另外还有语法如fleetctl start wys-wpa@{1,5,7}.service
(4)如何传参数进Unit
3中提到通过启动Unit的名称传递参数,这是systemd的特性,官方文档是这样的http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers
"%i
"Instance nameFor instantiated units: this is the string between the "@
" character and the suffix of the unit name."%p
"Prefix nameFor instantiated units, this refers to the string before the "@
" character of the unit name. For non-instantiated units, this refers to the name of the unit with the type suffix removed.也就是说我们启动wys-wpa@1.service时,%i=1,%p=wys-wpa如果我们wys-wpa@.service这个UnitFile中有这样一句话
ExecStart=/usr/bin/docker run -name wpa%i -p 1000%i:80 wordpress那么就可以相当于在启动时动态指定某些参数,最重要的在于可以动态指定端口
1. 是否能 自由部署fleetservices 在1台或多台 machine 上。(可以指定部署1个服务在某台机器上,或者指定某个服务在多台机器上)
答:可以通过UnitFile 的 MachineID 参数来精准控制这个UnitFile对应的Unit应该跑在哪个机器上; 可以通过UnitFIle中Gloable=true 来将这个Unit跑到所有的集群中的机器上,注意此时并不通过Fleet的engine来进行调度,而只是会参考UnitFIle中[X-Fleet]的参数来判断符合条件的机器,把Unit跑在上面;另外我认为同一服务的不同实例(如对应wys-wpa@service这个UnitFile的wys-wpa@1.service,wys-wpa@2.service也可以指定跑在同一个Machine上,只要他们的端口不冲突
实验:
(1)指定一个Unit(Service)跑在一台机器上(注意--etcd-key-prefix指定了前缀,所有命令都要加上这一个参数,否则fleetctl会默认去/_coreos.com/fleet/下找key value)
1.fleetctl --etcd-key-prefix=/fleet list-machines -l
MACHINE IP METADATA336043c3dba3e566192154d0544f626d 10.58.9.85 role=default364cd1ff8ac5dc300e15c293544f7cec 10.58.9.83 'role=default'93499a83f33431a60235662254573164 10.58.9.86 'role=default'e3583575125c30bdf50d4473544f7eba 10.58.9.82 'role=default'2.vim wys-wpa@.service ,Template Unit File 如下
[Unit]Descrption=Wordpress All Service (Connect to MOSSIN DB instance)After=docker.serviceRequires=docker.service[Service]EnvironementFile=/lib/systemd/system/wys-wpa-envTimeoutStartSec=0ExecStartPre=-/usr/bin/docker kill wpa%iExecStartPre=-/usr/bin/docker rm wpa%iExecStart=/usr/bin/docker run -p 1000%i:80 -name wpa%i tutum/wordpressExecStop=/usr/bin/docker stop wpa%iExecStop=/usr/bin/docker kill wpa%i[X-Fleet]MachineID=e3583575125c30bdf50d4473544f7eba3.systemctl daemon-reload
4.fleetctl -etcd-key-prefix=/fleet start wys-wpa@{2..3}.service
Unit wys-wpa@2.service launched on e3583575.../10.58.9.82Unit wys-wpa@3.service launched on e3583575.../10.58.9.82
5.fleetctl -etcd-key-prefix=/fleet list-units
wys-wpa@2.service e3583575.../10.58.9.82 active runningwys-wpa@3.service e3583575.../10.58.9.82 active running可以看到两个service都在指定的机器上跑了
6.在82上netstat -tulpn可以看到docker-proxy占用了10002,10003端口
这个实验也解决了“同一服务的不同实例”是否可以跑在同一个机器上的问题,只要端口不冲突,都是可以的
7.另一种方法:我们也可以通过
MachineMetadata
Limit eligible machines to those with this specific metadata.这个参数来匹配Unit到不同的Machine上,这需要在启动fleetd的时候加上-metadata这样的参数,需要在UnitFile中改动设想:我觉得在实际运维过程中应该使用MetaData这样的方法,这样的方法更灵活,比如一个机器可以设置两个Meatadata参数:“AppServerMachineCluster”,“10.58.9.83”
假设我们有一个Unit file叫做Appserver@.service,我们可以在这个基础上搞出一个Appserver-cluster@.service这样的TemplateUnitFile,并且在里面设置Matadata包含AppServerMachineCluster,这样就可以部署到对应的集群上面。如果想专门部署到83上,则可以搞一个Appserver-83@.service,并在里面设置Metadata包含10.58.9.83,这样这个Unit就会只跑在83上了
(2)一个service部署在多台机器上
将wys-wpa@.service中加入,
[X-Fleet]Global=truefleetctl --etcd-key-prefix=/fleet start wys-wpa@{3..3}.service
可以看到
wys-wpa@3.service 2855ac14.../10.58.9.82 active runningwys-wpa@3.service da060b6c.../10.58.9.85 active running两个服务同名,使用
fleetctl --etcd-key-prefix=fleet destroy wys-wpa@3.service
可以将两个Unit一起destroy掉
根据官方的说法,这种global unit用于在每台机器上采集信息这样的程序
global unit的schedule尽管不通过Engine,但也会考虑Metadata的匹配问题,metadata不合适的机器上是不会跑起来的
目前发现Global unit的Status是没法观测的
fleetctl --etcd-key-prefix=fleet status wys-wpa@3.serviceUnable to determine status of global unit wys-wpa@3.service.
2.指定任意埠在某个服务,发布时自动增加,埠可控制区间对于某个服务来说,如[20001-20010]=apps.war
- Fleet问题
- HOJ 1487 Fleet Commander
- CepUserFleet fleet=
- Swarm、Fleet、Kubernetes、Mesos
- Swarm、Fleet、Kubernetes、Mesos
- Fleet Commander项目启动流程
- Further checks required for Qantas regional fleet
- 7GOJ 23 fleet [主席树]
- HDU6138 Fleet of the Eternal Throne
- HDU 6138 Fleet of the Eternal Throne
- hdu 6138 Fleet of the Eternal Throne
- HDU 6138 Fleet of the Eternal Throne
- 如何使用fleet与fleetctl管理CoreOS集群
- HDU 6138 Fleet of the Eternal Throne (2017多校8
- HDU 6138 Fleet of the Eternal Throne (2017多校8
- HDU 6138 Fleet of the Eternal Throne ( AC自动机)
- hdu 6138 Fleet of the Eternal Throne (ac自动机)
- HDU 6138 Fleet of the Eternal Throne [AC自动机]
- android studio配置sdk
- linux串口编程
- 大数取余,模拟除法
- JAVA Hello找不到或无法加载主类
- java同步/设置Linux系统时间
- Fleet问题
- ubuntu下如何用命令行运行deb安装包
- UML是啥?
- Adapter优化
- Binary Tree Inorder Traversal (leetcode)
- Drawable资源
- Ubuntu 12.04 安装 Subversion 1.7
- I/O
- Remove Element - LeetCode