实验系统:CentOS 6.6_x86_64linux
实验前提:提早准备好编译环境,防火墙和selinux都关闭web
软件介绍:tmux是一个优秀的终端复用软件,相似GNU Screen,但来自于OpenBSD,采用BSD受权。使用它最直观的好处就是,经过一个终端登陆远程主机并运行tmux后,在其中能够开启多个控制台而无需再“浪费”多余的终端来链接这台远程主机;固然其功能远不止于此。vim
软件下载:http://pan.baidu.com/s/1c0i9kf2bash
1、常规安装ssh
1.安装tmux所须要的依赖:spa
wget https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz tar xf libevent-2.0.22-stable.tar.gz cd libevent-2.0.22-stable ./configure make && make install
ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
2.安装tmux软件包:.net
wget http://iweb.dl.sourceforge.net/project/tmux/tmux/tmux-2.0/tmux-2.0.tar.gz tar xf tmux-2.0.tar.gz cd tmux-2.0 ./configure --prefix=/usr/local/tmux make && make install
3.导出二进制文件:code
vim /etc/profile.d/tmux.sh ----------------------------------------> PATH=$PATH:/usr/local/tmux/bin export PATH <---------------------------------------- . /etc/profile.d/tmux.sh
4.导出man手册:blog
vim /etc/man.config ---------------------------------------------> MANPATH /usr/local/tmux/share/man //增长一行
5.编辑配置文件:ip
vim ~/.tmux.conf ------------------------------------------> set -g prefix C-a //设置前缀命令为crtl+a unbind C-b //解除ctrl+b的绑定 setw -g mode-keys vi //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!
2、拓展实验
1.安装ansible并建立yaml文件:
yum -y install ansible mkdir -pv /root/ansible.roles/roles //建立工做目录 cd /root/ansible.roles vim tmux.yaml --------------------------------------------> - name: install tmux remote_user: root //运行用户 hosts: tmux //运行这个剧本的主机,后面有定义 roles: - tmux //规则名称,要与后面建立的文件夹名称相同
2.放入文件:
cd /root/ansible.roles/roles mkdir -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 && cd tar xf libevent-2.0.22-stable.tar.gz cd libevent-2.0.22-stable ./configure make && make install ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5 # Install tmux cd && cd tar xf tmux-2.0.tar.gz cd tmux-2.0 ./configure --prefix=/usr/local/tmux make && make install # Extra Operation touch /etc/profile.d/tmux.sh echo 'PATH=$PATH:/usr/local/tmux/bin' > /etc/profile.d/tmux.sh echo 'export PATH' >> /etc/profile.d/tmux.sh echo '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.76 ansible_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.