forked from judasn/Linux-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
263 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# daemontools 工具 | ||
|
||
## supervisord | ||
|
||
- 注意:Supervisor 能管理非 daemon 的进程,也就是说 Supervisor 不能管理守护进程。否则提示 Exited too quickly (process log may have details) 异常。 | ||
- 官网:<http://supervisord.org/installing.html> | ||
- 安装过程: | ||
- 解释:easy_install 是 setuptools 包里带的一个命令,使用 easy_install 实际上是在调用 setuptools 来完成安装模块的工作,所以安装 setuptools 即可。 | ||
- 安装: | ||
- `yum -y install python-setuptools` | ||
- `easy_install supervisor` | ||
- 生成配置文件: | ||
- `echo_supervisord_conf > /etc/supervisord.conf` | ||
- 创建专门的程序配置文件目录、日志目录: | ||
- `mkdir -p /var/log/supervisor` | ||
- `mkdir -p /etc/supervisor/conf.d/` | ||
- `echo -e "[include]\nfiles = /etc/supervisor/conf.d/*.conf">>/etc/supervisord.conf` | ||
- 安装完成的内容介绍:supervisor 安装完成后会生成三个执行程序: | ||
- supervisortd:supervisor 的守护进程服务(用于接收进程管理命令) | ||
- supervisorctl:客户端(用于和守护进程通信,发送管理进程的指令) | ||
- echo_supervisord_conf:生成初始配置文件程序。 | ||
- 程序位置:`/usr/bin/supervisord` | ||
- 配置文件位置:`/etc/supervisord.conf` | ||
|
||
### Logstash 进程进行守护 | ||
|
||
- 默认安装完 Supervisor 是已经启动的,所以在加入新配置之前,需要先停止程序:`ps -ef | grep supervisord`,kill 对应的 pid | ||
- 创建配置文件:`vim /etc/supervisor/conf.d/logstash.conf` | ||
|
||
``` nginx | ||
[program:gitnavi-logstash] | ||
command=/usr/program/elk/logstash-2.4.1/bin/logstash -f /usr/program/elk/logstash-2.4.1/config/logstash.conf | ||
stdout_logfile=/var/log/supervisor/supervisord-logstash.log | ||
stderr_logfile=/var/log/supervisor/supervisord-logstash-err.log | ||
user=root | ||
autostart=true | ||
autorestart=true | ||
startsecs=5 | ||
priority=1 | ||
stopasgroup=true | ||
killasgroup=true | ||
``` | ||
|
||
- 启动程序(默认会启动所有子任务):`/usr/bin/supervisord -c /etc/supervisord.conf` | ||
- 管理子任务的命令: | ||
- 启动所有子任务:`/usr/bin/supervisorctl start all` | ||
- 结束所有子任务:`/usr/bin/supervisorctl stop all` | ||
- 只载入最新的配置文件, 并不重启任何进程:`/usr/bin/supervisorctl reread` | ||
- 载入最新的配置文件,停止原来的所有进程并按新的配置启动管理所有进程:`/usr/bin/supervisorctl reload` | ||
- 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启:`/usr/bin/supervisorctl update` | ||
- 查看所有子任务状态,如果没有运行的子任务则是没有任何反馈信息:`/usr/bin/supervisorctl status` | ||
- 管理所有子任务也可以用交互方式,输入命令:`supervisorctl`,会进入 supervisord 的交互模式下,如果当前有启动的任务,还可以看到对应的任务情况。 | ||
- 在该交互下可以停止指定名称的子任务,比如 logstash 任务:`stop gitnavi-logstash` | ||
- 也可以停止所有子任务:`stop all` | ||
- 也可以启动所有子任务:`start all` | ||
- 更多命令可以输入:`help` | ||
|
||
### 设置 supervisord 开启自启动 | ||
|
||
#### CentOS 6 | ||
|
||
- 创建文件:`vim /etc/init.d/supervisord` | ||
|
||
``` nginx | ||
#!/bin/sh | ||
# | ||
# Supervisor is a client/server system that | ||
# allows its users to monitor and control a | ||
# number of processes on UNIX-like operating | ||
# systems. | ||
# | ||
# chkconfig: - 64 36 | ||
# description: Supervisor Server | ||
# processname: supervisord | ||
# Source init functions | ||
. /etc/init.d/functions | ||
RETVAL=0 | ||
prog="supervisord" | ||
pidfile="/tmp/supervisord.pid" | ||
lockfile="/var/lock/subsys/supervisord" | ||
start() | ||
{ | ||
echo -n $"Starting $prog: " | ||
daemon --pidfile $pidfile supervisord -c /etc/supervisord.conf | ||
RETVAL=$? | ||
echo | ||
[ $RETVAL -eq 0 ] && touch ${lockfile} | ||
} | ||
stop() | ||
{ | ||
echo -n $"Shutting down $prog: " | ||
killproc -p ${pidfile} /usr/bin/supervisord | ||
RETVAL=$? | ||
echo | ||
if [ $RETVAL -eq 0 ] ; then | ||
rm -f ${lockfile} ${pidfile} | ||
fi | ||
} | ||
case "$1" in | ||
start) | ||
start ;; | ||
stop) stop ;; | ||
status) | ||
status $prog ;; | ||
restart) | ||
stop | ||
start ;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status}" ;; | ||
esac | ||
``` | ||
|
||
|
||
- `chmod 755 /etc/init.d/supervisord` | ||
- `chkconfig supervisord on` | ||
- 以后启动可以用:`service supervisord start` | ||
- 以后停止可以用:`service supervisord stop` | ||
|
||
|
||
#### CentOS 7 | ||
|
||
- 创建文件:`vim /lib/systemd/system/supervisor.service` | ||
|
||
``` ini | ||
[Unit] | ||
Description=supervisor | ||
After=network.target | ||
|
||
[Service] | ||
Type=forking | ||
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf | ||
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown | ||
ExecReload=/usr/bin/supervisorctl $OPTIONS reload | ||
KillMode=process | ||
Restart=on-failure | ||
RestartSec=42s | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
``` | ||
|
||
- `chmod 766 /lib/systemd/system/supervisor.service` | ||
- `systemctl enable supervisor.service` | ||
- `systemctl daemon-reload` | ||
|
||
## 资料 | ||
|
||
- <http://blog.csdn.net/xyang81/article/details/51555473> | ||
- <https://www.fangc.xyz/detail/centos6pei-zhi-supervisorkai-j/> | ||
- <http://cpper.info/2016/04/14/supervisor-usage.html> | ||
- <https://luckymrwang.github.io/2016/12/23/Supervisor%E5%AE%89%E8%A3%85%E4%BD%BF%E7%94%A8/> | ||
- <http://www.aichengxu.com/linux/24569479.htm> | ||
- <http://www.tianfeiyu.com/?p=2450> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Tmux 安装和配置 | ||
|
||
## 介绍 | ||
|
||
- 说明:`tmux is a "terminal multiplexer", it enables a number of terminals (or windows) to be accessed and controlled from a single terminal. tmux is intended to be a simple, modern, BSD-licensed alternative to programs such as GNU screen.` | ||
- 大家的主要用途:`提供了一个窗体组随时存储和恢复的功能`,本质有点类似守护进程感。 | ||
- 官网:<https://tmux.github.io/> | ||
- 官网 Github:<https://github.com/tmux> | ||
- 当前(201703)最新版本:**2.3** | ||
|
||
## 安装 | ||
|
||
- CentOS:`yum install -y tmux` | ||
- Ubuntu:`apt-get install -y tmux` | ||
- Mac:`brew install tmux` | ||
- 也可以看官网 GitHub 进行编译安装。 | ||
|
||
## 基本概念 | ||
|
||
- session:一个服务器可以包含多个会话,可以理解成是一个特定的终端组合,通常将同一任务下的工作放到一个会话中。 | ||
- window:一个会话可以包含多个窗口,一个窗口就相当于普通终端的一个标签,通常在不同的窗口中完成不同的工作。 | ||
- pane:一个窗口可以被分割成多个小的窗格。 | ||
|
||
## 基础用法 | ||
|
||
- 启动:`tmux` | ||
- 信息查询: | ||
- `tmux list-keys` 列出所有可以的快捷键和其运行的 tmux 命令 | ||
- `tmux list-commands` 列出所有的 tmux 命令及其参数 | ||
- `tmux info` 流出所有的 session, window, pane, 运行的进程号,等。 | ||
- 窗口的控制: | ||
- session 会话:session是一个特定的终端组合。输入tmux就可以打开一个新的session | ||
- `tmux new -s session_name` 创建一个叫做 session_name 的 tmux session | ||
- `tmux attach -t session_name` 重新开启叫做 session_name 的 tmux session | ||
- `tmux switch -t session_name` 转换到叫做 session_name 的 tmux session | ||
- `tmux list-sessions` / tmux ls 列出现有的所有 session | ||
- `tmux detach` 离开当前开启的 session | ||
- `tmux kill-server` 关闭所有 session | ||
- window 窗口:session 中可以有不同的 window(但是同时只能看到一个 window) | ||
- `tmux new-window` 创建一个新的 window | ||
- `tmux list-windows` | ||
- `tmux select-window -t :0-9` 根据索引转到该 window | ||
- `tmux rename-window` 重命名当前 window | ||
- pane 面板:window 中可以有不同的 pane(可以把 window 分成不同的部分) | ||
- `tmux split-window` 将 window 垂直划分为两个 pane | ||
- `tmux split-window -h` 将 window 水平划分为两个 pane | ||
- `tmux swap-pane -U` 在指定的方向(方向有:U、D、L、R 四种)交换 pane | ||
- `tmux select-pane -U` 在指定的方向(方向有:U、D、L、R 四种)选择下一个 pane | ||
|
||
## 高级用法 | ||
|
||
- **注意:** 有一个前缀快捷键的概念,也称作:`<prefix>`,默认快捷键:`Ctrl + B`,下面的这些操作都是必须先按这个快捷键后再输入对应的命令: | ||
- 基本操作 | ||
- `?` 列出所有快捷键;按q返回 | ||
- `d` 脱离当前会话,可暂时返回Shell界面 | ||
- `s` 选择并切换会话;在同时开启了多个会话时使用 | ||
- `D` 选择要脱离的会话;在同时开启了多个会话时使用 | ||
- `:` 进入命令行模式;此时可输入支持的命令,例如 kill-server 关闭所有tmux会话 | ||
- `[` 复制模式,光标移动到复制内容位置,空格键开始,方向键选择复制,回车确认,q/Esc退出 | ||
- `]` 进入粘贴模式,粘贴之前复制的内容,按q/Esc退出 | ||
- `~` 列出提示信息缓存;其中包含了之前tmux返回的各种提示信息 | ||
- `t` 显示当前的时间 | ||
- `ctrl + z` 挂起当前会话 | ||
- 窗口操作 | ||
- `c` 创建新窗口 | ||
- `&` 关闭当前窗口 | ||
- `[0-9]` 数字键切换到指定窗口 | ||
- `p` 切换至上一窗口 | ||
- `n` 切换至下一窗口 | ||
- `l` 前后窗口间互相切换 | ||
- `w` 通过窗口列表切换窗口 | ||
- `,` 重命名当前窗口,便于识别 | ||
- `.` 修改当前窗口编号,相当于重新排序 | ||
- `f` 在所有窗口中查找关键词,便于窗口多了切换 | ||
- 面板操作 | ||
- `"` 将当前面板上下分屏(我自己改成了 |) | ||
- `%` 将当前面板左右分屏(我自己改成了 -) | ||
- `x` 关闭当前分屏 | ||
- `!` 将当前面板置于新窗口,即新建一个窗口,其中仅包含当前面板 | ||
- `Ctrl + 方向键` 以1个单元格为单位移动边缘以调整当前面板大小 | ||
- `Alt + 方向键` 以5个单元格为单位移动边缘以调整当前面板大小 | ||
- `q` 显示面板编号 | ||
- `o` 选择当前窗口中下一个面板 | ||
- `方向键` 移动光标选择对应面板 | ||
- `{` 向前置换当前面板 | ||
- `}` 向后置换当前面板 | ||
- `Alt+o` 逆时针旋转当前窗口的面板 | ||
- `Ctrl+o` 顺时针旋转当前窗口的面板 | ||
- `z` 最大化当前所在面板 | ||
- `page up` 向上滚动屏幕,q 退出 | ||
- `page down` 向下滚动屏幕,q 退出 | ||
|
||
|
||
|
||
|
||
## 资料 | ||
|
||
- <http://kuanghy.github.io/2016/09/29/tmux> | ||
- <http://harttle.com/2015/11/06/tmux-startup.html> | ||
- <http://cenalulu.github.io/linux/tmux/> | ||
- <http://wdxtub.com/2016/03/30/tmux-guide/> | ||
- <https://gist.github.com/ryerh/14b7c24dfd623ef8edc7> | ||
- <http://cenalulu.github.io/linux/tmux/> | ||
- <http://fishcried.com/2014-09-15/tmux/> | ||
- <> | ||
- <> |