分类 devops 相关 下的文章

记录一些之前做混沌工程(Chaos Engineering)时候的一些命令

错误注入的命令, 检查命令, 恢复命令.

burn one cpu:

cat /dev/zero > /dev/null & 
pgrep -a cat
killall -q cat

网络延迟:

tc qdisc add dev eth0 root netem delay 3000ms
tc qdisc show  dev eth0
tc qdisc del dev eth0 root

磁盘占满:

fallocate -l $(df -k /  | tail -1 | awk '{print $4}')k sre_fault.img
df -k /
rm sre_fault.img

内存用完:

dd if=/dev/zero of=/dev/shm/fill bs=1k count=9024k
free -m
rm /dev/shm/fill

慢慢的用完内存

cat <(yes | tr \\n x | head -c 999999999) | grep n
free -m
killall -q yes

falt.png

如何从 mysql 数据库恢复删除的 grafana dashboard

上周整理某个grafana文件夹下的 dashboard 的时候, 看到一个 dashboard 的名字叫 XXX-copy, 觉得这个太无趣, 可能是一个临时 copy 的 dashboard, 立马起了杀意, 直接删除. 这周到公司, 直接有人说我删除了他辛辛苦苦已经加工了半个月的 dashboard. 我无语. 想该怎么恢复.

google 了一下, UI 上无法恢复已经删除的 dashboard. 我们的 Grafana 没有用默认的 sqlite3, 而是使用 msyql, 并且是 DBA 专业30年维护. 于是找到 DBA 要了一个删除之前的那天的数据库 snapshot. 这个 snapshot 是一个 sql 文件. 压缩后300多M, 解压后2.5G.

于是拿到这个数据库 snapshot, 先解压, 然后通过 docker 安装一个 msyql, 导入数据, 然后再安装一个 grafana, 然后导出dashboard 数据, 再导入正在使用的grafana, 问题解决. 下面是具体步骤(前提本地有安装好的 docker)

  1. 安装 mysql

    $ docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
  2. 复制 数据文件到 mysql container (ec2c00bc4837 是 上面 mysql 的 container id [docker ps])

    $ docker cp ~/Downloads/grafana.sql ec2c00bc4837:/
  3. 进入 mysql container 导入数据

    $ docker exec -it ec2c00bc4837 /bin/bash
    # /usr/bin/mysql -u root -p > /grafana.sql
  4. 本地定制 grafana 的配置文件 custom.ini, 只要修改 defaults.ini 的 database 部分, 具体参考这里: https://grafana.com/docs/grafana/latest/administration/configuration/

    [database]
    type = mysql
    host = mysql
    name = mygrafanaDB
    user = root
    password = 123456
  5. docker 安装 grafana 使用定制配置文件

    $ docker run --link mysql -d --name grafana -p 3000:3000 -v                 ~/Downloads/custom.ini:/etc/grafana/grafana.ini  grafana/grafana

现在就可以等你的 grafana 了 http://localhost:3000/

另外如果你发现你需要某些特定的用户名/密码才能改这个页面, 研究下数据库里的这3个表:
dashboard
dashboard_acl
user

[DevOps for Developers] 读书笔记1

dev & ops 分别对change的态度, 决定了...
devOps 是随着agile实践一步步发展而来, agile 先是在开发team, 后延续到ops team. 它强调的是合作, 沟通.

dev: change code, and want to delivery quickly to production;
ops: no change for production, keep it stable;

devops 概念的萌芽发展历程

  1. Patrick Debois coined the term DevOps in 2009 while organizing the
    DevOpsDays conference in Belgium.
  2. Patrick Debois ran a session called “Agile Operations and
    Infrastructure: How Infra-gile Are You?”4 at the Agile 2008
    conference in Toronto and published a paper with a similar name.
  3. Marcel Wegermann published a e-mail list called “Agile System
    Administration.”
  4. John Allspaw gave a presentation called “10+ Deploys per Day: Dev
    and Ops Cooperation”7 at the Velocity 2009 conference in San Jose.
  5. Steven Blank published a book called Four Steps to the Epiphany.
  6. Eric Ries published The Lean Startup9 and others have written on the
    “lean startup” scene.
  7. The 451 Group published the first analyst report on DevOps (titled
    “The Rise of DevOps”10) in September 2010.

DevOps can be examined from the following overlapping perspectives:

  1. Metrics and measurement view: This aspect addresses quality and
    testing and stresses shared incentives.
  2. Process view: This aspect covers congruence and flow to gain fast
    feedback and set up a holistic process.
  3. Technical view: This aspect discusses fast feedback through
    automation, particularly automatic releasing, specification by
    example, and infrastructure as code.