byobu "屏风" 简介 ,以及在CentOS下安装及日常使用

【byobu "屏风" 简介 ,以及在CentOS下安装及日常使用】-UBUNTU LINUX论坛-ZOL中关村在线

    byobu "屏风" 简介 ,以及在CentOS下安装及日常使用




    byobu "屏风" 简介  以及在CentOS下的安装使用

    byobu是个ubuntu team的一个项目,以前名字是screen-profile.是对screen进行了包装,以方便使用。

    讲byobu前,先来说下screen,

    我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务,结果却由于网络的不稳定导致任务中途失败。如何让命令提交后不受本地关闭终端窗口/网络断开连接的干扰呢?[详见:Linux 技巧:让进程在后台可靠运行的几种方法]
    screen可以解决上面的问题,不过他的功能不仅仅于此。

        * 使用时Attach,离开或者断开连接后Detach。(screen常用功能)
        * 可以做为窗口管理程序(类似于KDE,GNOME, 当然不要奢求X11那样的)
        * 可以共享桌面,screen 的multiuser模式(共享终端比较确切)。
        * 监视程序窗口状态。monitoring功能。
        * 可以挂站(好像是台湾那边的说法,一直上着BBS或者IRC吧)

    有几个screen的术语:
    session: 一次会话,可以Detach,Attach。父进程是1.可包含多个window。
    window:一个窗口,里面可以运行你的程序,默认启动screen就带个window。
    caption/hardstatus line:“标题栏”/"状态栏"。可以显示些系统信息。

    默认的screen配置比较简单,长久使用,自己修改下screen的配置文件让你比较顺手。这里有个简单的例子。(来着:如何做个轻量,美丽,功能强劲的终端 )
    点击在新窗口查看全图 CTRL+<a href=http://detail.zol.com.cn/mice_index/subcate32_list_1.html style=text-decoration:underline target=_blank>鼠标</a>滚轮放大或缩小

    OK,下面主角byobu出场。byobu来着日文,意思就是 “屏风”,档风和遮障是屏风的主要功能,它可以起到分割和空间导向的作用。


    byobu在ubuntu下安装很简单,

    [Copy to clipboard] [ - ]

    CODE:
        Grab and install the latest .deb from the PPA:
          https://launchpad.net/~byobu/+archive/ppa
          sudo apt-get install byobu byobu-extras


    但是如果想在CentOS中使用,还需要升级下Python(到>2.5,目前CentOS自带的为2.4)。
    由于CentOS系统很多应用依赖python,所以在yum源没出python升级前,手动安装到另外的地方而不要去覆盖自带的python。
    传统安装方法:

    [Copy to clipboard] [ - ]

    CODE:
        wget http://www.python.org/ftp/python/2.5.4/Python-2.5.4.tar.bz2
        tar -xvf Python-2.5.4.tar.bz2
        Python-2.5.4
        ./configure
        make
        make install

    [root@t61p ~]# which python
    /usr/local/bin/python
    [root@t61p ~]# python -V
    Python 2.5.4


    PS:如果你的其他应用(ex:yum)抱怨python方面的问题,把新版本先挪掉 (mv /usr/local/bin/python /usr/local/bin/python.backup)

    接下去下载byobu源代码
    网站上有个export版本,适合没有root权限或者编译不成的人的,主要功能也在,只是他的F9 Menu是不能调出来的。
    同时把最新的export和源代码包下来。(export包后面有用)

    解压源代码发现有个spec文件(byobu_2.42.orig/rpm/byobu.spec). 所以这个tarball可以使用rpmbuild来编译(rpmbuild由yum install rpm-build)。

    [Copy to clipboard] [ - ]

    CODE:
    [root@t61p byobu]# rpmbuild -tb byobu_2.42.orig.tar.gz
    ...[output ignored]....
    + cp -ar profiles/black /var/tmp/byobu-2.42-1-root-root/usr/share/byobu/profiles
    cp: cannot stat `profiles/black': No such file or directory
    error: Bad exit status from /var/tmp/rpm-tmp.40268 (%install)


    RPM build errors:
        Bad exit status from /var/tmp/rpm-tmp.40268 (%install)


    用过一段时间的export版本,这些profile文件是用来设置颜色风格的,源代码包作者好像粗心没放进去。不过我从其他地方找了一份(比如ubuntu,或者官方git)。
    然后在build就可以了。

    [Copy to clipboard] [ - ]

    CODE:
    [root@t61p byobu]# tar -xvf byobu_2.42.orig.tar.gz
    [root@t61p byobu]# mv byobu_2.42.orig.tar.gz byobu_2.42.orig.tar.gz.old
    [root@t61p byobu]# cp /usr/share/byobu/profiles/* byobu_2.42.orig/profiles/    #我原来就在的。
    [root@t61p byobu]# tar -czvf byobu_2.42.orig.tar.gz byobu_2.42.orig
    [root@t61p byobu]# rpmbuild -tb byobu_2.42.orig.tar.gz
    ...[output ignored]....
    Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
    Requires: /bin/sh /usr/bin/env gettext newt python >= 2.5 screen
    Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/byobu-2.42-1-root-root
    Wrote: /usr/src/redhat/RPMS/noarch/byobu-2.42-1.noarch.rpm
    Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.11709
    + umask 022
    + cd /usr/src/redhat/BUILD
    + cd byobu_2.42.orig
    + rm -rf /var/tmp/byobu-2.42-1-root-root
    + exit 0


    rpm包已经生成,由于python我们不是覆盖安装,所以有些lib什么的版本会不够,rpm安装是会报错,所以我们只能 --nodeps 强制安装。

    [Copy to clipboard] [ - ]

    CODE:
    [root@t61p byobu]# rpm --nodeps -Uvh /usr/src/redhat/RPMS/noarch/byobu-2.42-1.noarch.rpm


    再开始使用前,随便把一个问题先这里提下,byobu使用python的snack模块,从而导致F9 的Menu不能打开。我开始查了半天,后来才发现snack在newt包里。把python的模块包拷贝到新装的python目录就能工作了。

    [Copy to clipboard] [ - ]

    CODE:
    [root@t61p ~]# rpm -ql newt.i386
    /usr/bin/whiptail
    /usr/lib/libnewt.so.0.52
    /usr/lib/libnewt.so.0.52.1
    /usr/lib/python2.4/site-packages/_snackmodule.so
    /usr/lib/python2.4/site-packages/snack.py
    /usr/lib/python2.4/site-packages/snack.pyc
    /usr/lib/python2.4/site-packages/snack.pyo
    /usr/share/doc/newt-0.52.2
    /usr/share/doc/newt-0.52.2/COPYING

    [root@t61p byobu]# cp /usr/lib/python2.4/site-packages/_snackmodule.so  /usr/local/lib/python2.5/
    [root@t61p byobu]# cp /usr/lib/python2.4/site-packages/snack.py               /usr/local/lib/python2.5/
    [root@t61p byobu]# cp /usr/lib/python2.4/site-packages/snack.pyc             /usr/local/lib/python2.5/
    [root@t61p byobu]# cp /usr/lib/python2.4/site-packages/snack.pyo             /usr/local/lib/python2.5/


    然后你就可以开始探索byobu了, 因为buyobu是个screen的封装,使用byobu的语法和screen类似,而且两者兼容,byobu开的session使用screen就能attach。
    byobu -S test


    按下F9,就有个界面来配置byobu了。


    byobu的热键绑定在F2~F12上。
    有几个比较常用的
    F2:新建Window
    F3:上一个Window
    F4:上一个Window
    F5:reload config
    F6:Detache
    F8:改Window名字
    F12:screen加密码,类似锁屏。

    byobu有个安装的概念,就是在你ID登陆后自动启动个screen session。这个功能比较好用但也得谨慎,如果byobu进程挂起的话你的ID登陆也就有问题了。

    下面是我平时的一些使用,一般的console程序工作的还不错,(有些会因为F*键冲突,或者鼠标不能使用),一般都是多窗口状态。
    screen+irssi上IRC
    点击在新窗口查看全图 CTRL+鼠标滚轮放大或缩小

    参考URL:
    byobu官方主页。
    https://launchpad.net/byobu
    Linux 技巧:让进程在后台可靠运行的几种方法
    http://www.ibm.com/developerworks/cn/linux/l-cn-nohup/index.html
    linux 技巧:使用 screen 管理你的远程会话
    http://www.ibm.com/developerworks/cn/linux/l-cn-screen
    对话 UNIX: 使用 Screen 创建并管理多个 shell
    http://www.ibm.com/developerworks/cn/aix/library/au-gnu_screen
    byobu 美化你的 screen
    http://li2z.cn/2009/11/06/byobu/
    如何做个轻量,美丽,功能强劲的终端(结尾部分提到screen的配置)
    http://tuxtraining.com/2009/07/28/how-to-have-a-lightweight-beautiful-functional-terminal
    byobu其实就是方便了screen的使用,screen是比较强大的,稍后带来一些实际中的应用。 :lol:

    介绍下screen的multiuser模式。
    先准备个简单的screen配置,用来显示当前window列表。

    [Copy to clipboard] [ - ]

    CODE:
    [user1@CentOS1 ~]$ cat screenrctest
    caption always "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"

    [user1@CentOS1 ~]$ screen -c screenrctest -S multitest
    [user1@CentOS1 ~]$ screen -ls
    There are screens on:
            23037.bt        (Detached)
            2705.work       (Detached)
            25047.multitest (Attached)
    3 Sockets in /var/run/screen/S-user1.


    Ctrl+a,c //创建几个window
    Ctrl+a,:  并输入multiuser on//进入screen的命令模式(类似vim的:这里可以输入命令),


    [Copy to clipboard] [ - ]

    CODE:
    [user1@CentOS1 ~]$ screen -ls
    There are screens on:
            23037.bt        (Detached)
            2705.work       (Detached)
            25047.multitest (Multi, attached)
    3 Sockets in /var/run/screen/S-user1.


    这个时候其他用户还不能Attach过来,还没设置权限。有文档说root什么时候都可以,我试了下好像不行。

    比如我有另外一个用户user2要来连接我的session,我需要设置好权限。
    使用acl***系列的screen命令,这里简单点我使用acladd和aclchg。
    ------------------------------------------------------------------------------------------------------------------
    #
    acladd usernames [crypted-pw] - Adds users with full permission to all windows. usernames can be a single user or a comma-delimited list. This is the only way to set a password on a user.
    #
    aclchg usernames permbits list - Adds users with more flexible permissions or changes the permissions on an existing user. list is a comma-delimited list of windows and commands.
    screen has a relatively flexible representation of permissions. The permissions that can be set are read, write, and execute. Read does nothing. Write applies to windows and allows the user to type into the windows. Execute applies to commands and allows the user to run the specified commands. '#' can be used to apply to all windows and '?' to all commands.
    ------------------------------------------------------------------------------------------------------------------
    权限也使用rwx来区分。
    r:没效果?
    w:可以在你的session中输入(只读和可写间区分)。
    x:可以执行screen命令。
    作用范围
    #:所有window
    ?:所有命令

    acladd user2
    aclchg user2 +rwx "#?" //可读可写,适合远程协助
    aclchg user2  -w "#?" //只读,适合演示

    这个时候user2就可以连入我的session
    [user2@CentOS1 ~]$ screen -r user1/
    Must run suid root for multiuser support.
    ====================================================================
    * You may also need to set-uid on the screen executable. Do this on your screen executable as root: chmod u+s /usr/bin/screen. This is in man screen towards the end.
    [root@CentOS1 ~]# ls -l /usr/bin/screen
    -rwxr-sr-x 1 root screen 348856 Dec  3 18:52 /usr/bin/screen
    [root@CentOS1 ~]# chmod u+s /usr/bin/screen
    [root@CentOS1 ~]# ls -l /usr/bin/screen
    -rwsr-sr-x 1 root screen 348856 Dec  3 18:52 /usr/bin/screen
    ====================================================================

    当客户段的putty窗口大小和我的不一致时会有下面的现象,看起来不舒服。

    [user1@CentOS1 ~]$ echo $COLUMNS
    80
    [user1@CentOS1 ~]$ echo $LINES
    23
    然后让客户段Putty->window设置成一致的窗口就可以了。

    screen自己常用的就这些,留个位置给后面补充。:lol:


    这里解释个常见的screen错误和解决方法:

    错误信息:

    [Copy to clipboard] [ - ]

    CODE:
    [user2@CentOS1 ~]$ screen -ls
    There is a screen on:
            3510.user2screen       (Attached)
    1 Socket in /var/run/screen/S-user2.
    [user2@CentOS1 ~]$ screen -x
    Cannot open your terminal '/dev/pts/5' - please check.


    这个错误发生的典型情况是:
    user2 开了个screen,注意没有开multiuser 模式,user1为了去共享桌面需要先 su或者sudo到user2,此时去Attach的时候就会有上面的错误。

    错误原因:
    因为screen需要去读写用户的tty导致的。以上面的场景为例:
    user2使用SSH登陆,分配了TTY /dev/pts/7.
    user1使用SSH登陆,分配了TTY /dev/pts/5. su或者sudo到user2后,user1的tty是不会变的。
    tty默认权限如下:

    [Copy to clipboard] [ - ]

    CODE:
    [user1@CentOS1 ~]$ ls -l /dev/pts/5
    crw--w---- 1 user1 tty 136, 5 Dec 25 13:44 /dev/pts/5


    由于su过去的user2用户运行时读写的tty是su前user1的tty,所以是没有读写权限的。

    解决方法:
    方法1:
    直接登陆user2,但是往往很多时候我们没有user2(比如说客户,学妹)的密码。

    方法2:
    改tty权限,这个只是临时方案,而且不太安全。

    [Copy to clipboard] [ - ]

    CODE:
    [user1@CentOS1 ~]$ ls -l /dev/pts/5
    crw--w---- 1 user1 tty 136, 5 Dec 25 13:44 /dev/pts/5
    [user1@CentOS1 ~]$ chmod o+rw /dev/pts/5
    [user1@CentOS1 ~]$ ls -l /dev/pts/5
    crw--w-rw- 1 user1 tty 136, 5 Dec 25 13:44 /dev/pts/5


    改了权限后,user1==>user2,user2 (这里称为窗口WINB)可以screen -x attach进user2先前的sreen (WINA) session,但是刚才那个/dev/pts/5别人就可以读到了(可以直接cat  /dev/pts/5,同时WINB的输入没有回显了。)。

    方法3:(以前可以,但今天测试没成功,先放出来再研究下)
    user1先su到root,然后root用户开个screen,在screen window中su到user2,然后在attach到user2先前开的screen。(注意:这种情况下是nested screen,热键传到里面一层要多按一次Ctrl+a.)

    方法3原文[http://searchenterpriselinux.techtarget.com/tip/0,289483,sid39_gci1102088,00.html]:
    Another option is to become root and invoke screen, and then become the system account needed to run the job within the screen session. This will work because the superuser is able to open any user's tty, and (ostensibly) your support staff has sufficient rights to become the root user.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用以下命令在Linux上安装Hollywood: 1. 首先,更新软件包信息: ``` sudo apt update ``` 2. 安装Hollywood软件包: ``` sudo apt install hollywood ``` 如果你使用的是Ubuntu或者其他基于Ubuntu的Linux发行版(比如Linux Mint、elementary OS、Zorin OS、Linux Lite等),上述命令应该能够正常工作。 如果上述命令在你的系统上不起作用,你可以尝试使用PPA(Personal Package Archive)来安装Hollywood。请按照以下步骤操作: 1. 添加Hollywood PPA: ``` sudo apt-add-repository ppa:hollywood/ppa ``` 2. 更新软件包信息: ``` sudo apt update ``` 3. 安装Hollywood: ``` sudo apt install byobu hollywood ``` 另外,如果你想获取Hollywood的源代码,可以从它的GitHub存储库中获取: ``` https://github.com/dustinkirkland/hollywood ``` 安装完成后,你可以使用以下命令运行Hollywood(无需使用sudo): ``` hollywood ``` 请注意,因为Hollywood首先运行Byobu,所以你需要使用Ctrl+C两次来停止Hollywood,并使用"exit"命令退出黑客终端脚本。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [30 秒速成好莱坞黑客 -- 在 Linux 终端中伪造好莱坞黑客屏幕](https://blog.csdn.net/m0_46278037/article/details/122500664)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [oeasy 教您玩转linux 之 010209 装酷利器 hollywood](https://blog.csdn.net/overmind/article/details/108506192)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值