使用ansible编译安装运维工具tmux

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

实验系统:CentOS 6.6_x86_64

实验前提:提前准备好编译环境,防火墙和selinux都关闭

软件介绍:tmux是一个优秀的终端复用软件,类似GNU Screen,但来自于OpenBSD,采用BSD授权。使用它最直观的好处就是,通过一个终端登录远程主机并运行tmux后,在其中可以开启多个控制台而无需再“浪费”多余的终端来连接这台远程主机;当然其功能远不止于此。

软件下载:http://pan.baidu.com/s/1c0i9kf2

一、常规安装

1.安装tmux所需要的依赖:

wgethttps://sourceforge.net/PRojects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gztarxf libevent-2.0.22-stable.tar.gz

cd libevent-2.0.22-stable

./configuremake&&makeinstall

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

2.安装tmux软件包:

wgethttp://iweb.dl.sourceforge.net/project/tmux/tmux/tmux-2.0/tmux-2.0.tar.gztarxf tmux-2.0.tar.gz

cd tmux-2.0./configure --prefix=/usr/local/tmuxmake&&makeinstall

3.导出二进制文件:

vim /etc/profile.d/tmux.sh---------------------------------------->PATH=$PATH:/usr/local/tmux/bin

export PATH<----------------------------------------./etc/profile.d/tmux.sh

4.导出man手册:

vim /etc/man.config--------------------------------------------->MANPATH/usr/local/tmux/share/man//增加一行

5.编辑配置文件:

vim ~/.tmux.conf------------------------------------------>set-g prefix C-a//设置前缀命令为crtl+aunbind C-b//解除ctrl+b的绑定setw-g mode-keysvi//copy-mode将快捷键设置为vi模式set-g default-terminal"screen-256color"//设置终端颜色为256色set-g status-utf8 on//开启状态栏的uft-8支持set-window-option -g mode-mouse on//开启滚屏

6.常用快捷键:

至此,tmux安装完毕了,下面咱们做个拓展实验,使用ansible安装tmux!

二、拓展实验

1.安装ansible并创建yaml文件:

yum-yinstallansiblemkdir-pv /root/ansible.roles/roles//创建工作目录cd/root/ansible.roles

vim tmux.yaml-------------------------------------------->

- name:installtmux

remote_user: root//运行用户hosts: tmux//运行这个剧本的主机,后面有定义roles:- tmux//规则名称,要与后面创建的文件夹名称相同

2.放入文件:

cd /root/ansible.roles/rolesmkdir-pv tmux/{files,handlers,tasks}//创建与规则同名的文件夹cp/root/tmux-2.0.tar.gz /root/libevent-2.0.22-stable.tar.gz tmux/files///将安装包放入cp/root/.tmux.conf tmux/files///将配置文件放入

3.编写主yaml文件:

vim /root/ansible.roles/roles/tmux/tasks/main.yaml------------------------------------------------------>

- name: copy libevent package

copy: src=libevent-2.0.22-stable.tar.gz dest=/root

- name: copy tmux package

copy: src=tmux-2.0.tar.gz dest=/root

- name: copy conf

copy: src=.tmux.conf dest=/root

- name: run script

script: tmux.sh

4.编写tmux.sh脚本:

vim /root/ansible.roles/roles/tmux/files/tmux.sh---------------------------------------------------------------->#!/bin/bash

#

# Install libevent

cd&&cdtarxf libevent-2.0.22-stable.tar.gz

cd libevent-2.0.22-stable

./configuremake&&makeinstallln-s /usr/local/lib/libevent-2.0.so.5/usr/lib64/libevent-2.0.so.5# Install tmux

cd&&cdtarxf tmux-2.0.tar.gz

cd tmux-2.0./configure --prefix=/usr/local/tmuxmake&&makeinstall# ExtraOperationtouch/etc/profile.d/tmux.shecho'PATH=$PATH:/usr/local/tmux/bin'> /etc/profile.d/tmux.shecho'export PATH'>> /etc/profile.d/tmux.shecho'MANPATH /usr/local/tmux/share/man'>> /etc/man.config

. /etc/profile.d/tmux.sh

<----------------------------------------------------------------

chmod +x /root/ansible.roles/roles/tmux/files/tmux.sh

5.加入要安装的主机:

vim /etc/ansible/hosts---------------------------------------------->[tmux]//对应tmux.yaml文件里的名称192.168.19.76ansible_ssh_pass=passWord//主机IP+登录密码

6.尝试使用:

cd /root/ansible.roles/ansible-playbook tmux.yaml

至此,实验全部完成。使用中发现/etc/profile.d/tmux.sh这个文件不能被正常source,所以可能需要手动执行一下 . /etc/profile.d/tmux.sh。由于时间紧迫,所以过程还不是很完善,脚本也并不严谨,没有一些条件判断等等,而且安装主机必须要有编译环境。大家如果有需要可以自行扩展修改,我已经把ansible文件夹上传至共享,大家可以随意下载使用。最后,感谢大家的收看,谢谢!如有问题,请联系QQ:82800452.

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航