基于bearychat的chatops
- 2019 年 10 月 4 日
- 筆記
参考文章: http://www.361way.com/bearychat-hubot/5663.html
需要用到nodejs 、bearychat注册账号。bearychat的操作,可以参考我上面贴的这个地址,写的比我详细。
# 创建一个低权限账号
useradd deploy
echo 'deploy' | passwd –stdin deploy
1、安装并启动redis-server (过程略过)
2、安装node (切换到deploy账号下操作)
yum install npm npm install -g n n stable node --version 如果上面的及步骤的node安装不上去,可以如下操作: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash nvm ls-remote export NVM_DIR="$HOME/.nvm" NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/dist nvm install v11.6.0 node --version
安装完node后,再继续往下执行:
npm install -g hubot coffee-script yo generator-hubot su - deploy mkdir hubot cd hubot sudo yo hubot sudo npm install hubot-bearychat --save sudo chown deploy.deploy /root/.config/ -R export HUBOT_BEARYCHAT_TOKENS=xxxxxxxxx export HUBOT_BEARYCHAT_MODE=rtm rm -f hubot-scripts.json # 这个文件一般用不到,可以删除
./bin/hubot -a bearychat 即可启动
# 安装 shellcmd模块
npm install hubot-script-shellcmd
# 添加到hubot配置中
vim /home/deploy/hubot/external-scripts.json 加一行 "hubot-script-shellcmd"
最后效果如下:
[ "hubot-diagnostics", "hubot-help", "hubot-heroku-keepalive", "hubot-google-images", "hubot-google-translate", "hubot-pugme", "hubot-maps", "hubot-redis-brain", "hubot-rules", "hubot-shipit", "hubot-script-shellcmd" ]
# 配置shellcmd的各种命令
cd /home/deploy/hubot/node_modules/hubot-script-shellcmd
cd bash/handlers/
全部的shell命令都在这个目录下存放
我们可以在 /home/deploy/hubot/node_modules/hubot-script-shellcmd 下面写一些小的shell脚本,里面可以调用ansible 传ip参数执行些日常运维操作(清理磁盘、查看数据库连接数统计、等等骚操作)。