{"id":460,"date":"2021-09-14T04:48:00","date_gmt":"2021-09-14T04:48:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=460"},"modified":"2021-09-14T04:48:00","modified_gmt":"2021-09-14T04:48:00","slug":"460","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/09\/14\/460\/","title":{"rendered":"\u4f7f\u7528 tmux\u811a\u672c \u548c Xshell\u5feb\u901f\u547d\u4ee4 \u5b9a\u5236\u73af\u5883\uff0c\u5b9a\u5236\u4e00\u952eDocker\u9762\u677f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/09\/3678174084.webp\" alt=\"tmux.webp\" title=\"tmux.webp\"><\/p>\n<h3><a href=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/09\/1128832684.zip\">Xshell_7_\u5feb\u901f\u547d\u4ee4\u680f\u5bfc\u5165\u5305.zip<\/a><\/h3>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 tmux \u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u6a21\u578b\uff08client-server model\uff09\u6765\u521b\u5efa\u4e00\u4e2a\u5b9a\u5236\u7684\u811a\u672c\u6765\u81ea\u52a8\u5730\u6784\u5efa\u5f00\u53d1\u73af\u5883\u3001\u5206\u5272\u7a97\u53e3\u5e76\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<h3><code>tmux-docker.sh<\/code><\/h3>\n<pre><code>#!\/bin\/bash\ntmux new-session -d -s ssh    # \u540e\u53f0\u65b0\u5efa\u4e00\u4e2asession\ntmux split-window -h          # \u5207\u5272\u7a97\u53e3(\u5de6\u53f3)\ntmux split-window -v          # \u5207\u5272\u7a97\u53e3(\u4e0a\u4e0b)\n\ntmux select-pane -t 0         # \u9009\u62e90\u53f7\u7a97\u53e3  # \u53d1\u9001\u547d\u4ee4\ntmux send-keys \"iptables -nvL DOCKER; docker ps -a\" C-m\n\ntmux select-pane -t 1\ntmux send-keys \"htop\" C-m\n\ntmux select-pane -t 2\ntmux send-keys \"docker exec -it  nginx-php bash\" C-m\ntmux send-keys \"cd \/var\/www\/html\" C-m\ntmux send-keys \"php i.php\" C-m\n\ntmux select-pane -t 0\ntmux send-keys \"echo;echo;echo -e ':: \u767b\u5f55tmux\u7a97\u53e3: tmux a -t ssh    \u540e\u53f0\u4fdd\u6301:tmux: Ctrl+b-d    \u5173\u95ed: Ctrl+d'\" C-m\n\ntmux a -t ssh                # \u767b\u5f55tmux\u7a97\u53e3\n# tmux kill-session -t ssh   # \u505c\u6b62\u540e\u53f0session<\/code><\/pre>\n<ul>\n<li>\u5982\u56fe <code>Xshell<\/code> \u5feb\u901f\u547d\u4ee4\u680f\u6dfb\u52a0\u4e00\u4e2a\u5feb\u901f\u547d\u4ee4\uff0c\u7c98\u8d34\u4ee5\u4e0a\u5185\u5bb9 \u4f7f\u7528  # \u7ed3\u5c3e<\/li>\n<li>\u7136\u540e\u70b9\u4e00\u4e0b\u9f20\u6807\uff0c\u5c31\u80fd\u81ea\u52a8\u5f00\u542f tmux \u7a97\u53e3\u548c\u4f60\u60f3\u8981\u7684\u547d\u4ee4<\/li>\n<li><code>tmux<\/code> \u548c <code>htop<\/code> \u9700\u8981\u63d0\u524d\u5b89\u88c5  <code>apt install tmux htop<\/code><\/li>\n<\/ul>\n<h2>\u6211\u4eec\u5728\u4e00\u4e2a\u5821\u5792\u673a\u4e0a\uff0c\u8fd0\u884ctmux\uff0c\u7136\u540e\u5206\u522b\u5411\u5176\u4ed6\u53d7\u63a7\u5236\u673a\u5668\uff0c\u53d1\u9001\u5408\u9002\u7684\u547d\u4ee4<\/h2>\n<pre><code>tmux select-pane -t 1  # \u7a97\u53e3\u7f16\u53f7\u6309\u5b9e\u9645\u53d8\u5316\ntmux send-keys \"ssh root@192.168.1.111\" C-m\ntmux send-keys \"cd \/root; ls -1a\" C-m<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/07\/2526248639.png\" alt=\"\" title=\"\"><\/p>\n<h2>\u4e3a\u4e86\u5feb\u901f\u547d\u4ee4\u901a\u7528\uff0c\u6211\u4eec\u5148\u4f7f\u7528 <code>tmux a -t ssh<\/code> \u767b\u9646\u4e4b\u524d\u5df2\u6709 tmux \u670d\u52a1\uff0c\u68c0\u67e5 <code>$?<\/code> \u8fd4\u56de\u503c\u5224\u65ad\u662f\u5426\u5b58\u5728\u540d\u79f0 <code>ssh<\/code>\u7684\u65e7session<\/h2>\n<pre><code>#!\/bin\/bash\ntmux a -t ssh\nif [ $? == 1 ]; then\n    tmux new-session -d -s ssh    # \u540e\u53f0\u65b0\u5efa\u4e00\u4e2asession\n    tmux split-window -h          # \u5207\u5272\u7a97\u53e3(\u5de6\u53f3)\n    tmux split-window -v          # \u5207\u5272\u7a97\u53e3(\u4e0a\u4e0b)\n\n    tmux select-pane -t 0         # \u9009\u62e90\u53f7\u7a97\u53e3  # \u53d1\u9001\u547d\u4ee4\n    tmux send-keys \"iptables -nvL DOCKER; docker ps -a\" C-m\n    tmux select-pane -t 1\n    tmux send-keys \"htop\" C-m\n    tmux select-pane -t 2\n    tmux send-keys \"docker exec -it  nginx-php bash\" C-m\n    tmux send-keys \"cd \/var\/www\/html\" C-m\n    tmux send-keys \"php i.php\" C-m\n\n    tmux select-pane -t 0\n    # tmux send-keys \"echo;echo;echo -e ':: \u767b\u5f55tmux\u7a97\u53e3: tmux a -t ssh    \u540e\u53f0\u4fdd\u6301:tmux: Ctrl+b-d    \u5173\u95ed: Ctrl+d'\" C-m\n    tmux a -t ssh                # \u767b\u5f55tmux\u7a97\u53e3\n    # tmux kill-session -t ssh   # \u505c\u6b62\u540e\u53f0session\nfi # <\/code><\/pre>\n<ul>\n<li>Xshell\u548ctmux \u6587\u7ae0\u6807\u7b7e<br \/><a href=\"https:\/\/www.lyvba.com\/index.php\/tag\/Xshell\/\">https:\/\/www.lyvba.com\/index.php\/tag\/Xshell\/<\/a><br \/><a href=\"https:\/\/www.lyvba.com\/index.php\/tag\/tmux\/\">https:\/\/www.lyvba.com\/index.php\/tag\/tmux\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Xshell_7_\u5feb\u901f\u547d\u4ee4\u680f\u5bfc\u5165\u5305.zip \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 tmux \u7684\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u6a21\u578b\uff08clien [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[22,49],"class_list":["post-460","post","type-post","status-publish","format-standard","hentry","category-soft","tag-tmux","tag-xshell"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=460"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/460\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}