實驗系統: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.