您的位置:首页 > 运维架构 > Docker

部署sematext监控docker容器

编程100天 2019-01-21 23:27 295 查看 http://blog.51cto.com/leoheng/

1.创建账号

https://sematext.com/

2.创建监控的项目名称

跟着引导进行操作,创建第一个属于你的第一个监控容器的项目

3.在docker环境运行

3.1 docker run方式

sudo docker run -d --name sematext-agent --restart=always -e SPM_TOKEN=f31a28dc-d452-4da7-b704-51ac94***  -v /:/rootfs:ro -v /var/run/docker.sock:/var/run/docker.sock sematext/sematext-agent-docker

3.2 docker-compose 方式

# docker-compose.yml
sematext-agent:
image: 'sematext/sematext-agent-docker:latest'
environment:
#- LOGSENE_TOKEN=YOUR_LOGSENE_TOKEN # create a Logsene app if you don't have one yet, then use its token here and uncomment the line
- SPM_TOKEN=f31a28dc-d452-4da7-b704-51ac94eb7fd4
- affinity:container!=*sematext-agent*
cap_add:
- SYS_ADMIN
restart: always
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
- '/:/rootfs:ro'

3.3 k8s方式:kubectl

创建文件名为  sematext-agent.yml

# Kubernetes < v1.9
# apiVersion: extensions/v1beta1
# Kubernetes >= v1.9
apiVersion: extensions/v1beta2
kind: DaemonSet
metadata:
name: sematext-agent
spec:
template:
metadata:
labels:
app: sematext-agent
spec:
nodeSelector: {}
hostNetwork: true
dnsPolicy: "ClusterFirst"
restartPolicy: "Always"
containers:
- name: sematext-agent
image: sematext/sematext-agent-docker:latest
imagePullPolicy: "Always"
env:
- name: SPM_TOKEN
value: "f31a28dc-d452-4da7-b704-51ac94eb7fd4"
#- name: LOGSENE_TOKEN
#  value: "LOGSENE_TOKEN" # create a Logsene app if you don't have one yet, then use its token here and uncomment these two lines
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-sock
- mountPath: /etc/localtime
name: localtime
- mountPath: /rootfs
name: rootfs
readOnly: true
securityContext:
privileged: true
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
- name: localtime
hostPath:
path: /etc/localtime
- name: rootfs
hostPath:
path: /

在k8s集群中创建sematext

kubectl create -f sematext-agent.yml

3.4 k8s:helm

直接执行创建命令

helm install --name release_name \
--set sematext.spmToken=f31a28dc-d452-4da7-b704-51ac94eb7fd4 \
--set sematext.logseneToken=YOUR_LOGS_TOKEN \
stable/sematext-docker-agent

删除命令

helm delete release_name

或者,可以指定YAML文件来安装

helm install --name release_name -f custom-vars.yaml stable/sematext-docker-agent

3.5 rancher方式

# sematext/docker-compose.yml
sematext-docker-agent:
image: 'sematext/sematext-agent-docker:latest'
environment:
- SPM_TOKEN=f31a28dc-d452-4da7-b704-51ac94eb7fd4
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /:/rootfs:ro
labels:
io.rancher.scheduler.global: 'true'
将配置存储在  sematext/docker-compose.yml 文件中

cd sematext
rancher-compose up -d

3.6 Mesos方式

curl -XPOST -H "Content-type: application/json" http://your_marathon_server:8080/v2/apps -d '
{
"container": {
"type": "DOCKER",
"docker": {
"image": "sematext/sematext-agent-docker",
"privileged": "true"
},
"volumes": [
{
"containerPath": "/var/run/docker.sock",
"hostPath": "/var/run/docker.sock",
"mode": "RW"
},
{
"containerPath": "/rootfs",
"hostPath": "/",
"mode": "RO"
}
],
"network": "BRIDGE"
},
"env": {
"_LOGSENE_TOKEN": "Remove leading _ in the key and replace this text with your Lo
4fc0
gsene token",
"SPM_TOKEN": "dd1d20ce-8e03-41a4-9d1e-30076e424e23",
},
"id": "sematext-agent-docker",
"instances": 1,
"cpus": 0.5,
"mem": 300,
"constraints": [
[
"hostname",
"UNIQUE"
]
]
}

3.7docker swarm

docker service create --mode global \
--restart-condition any \
--name sematext-agent-docker \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
--mount type=bind,src=/,dst=/rootfs,readonly=true \
-e SPM_TOKEN=dd1d20ce-8e03-41a4-9d1e-30076e424e23  sematext/sematext-agent-docker