Blog

  • rpm命令

    用CentOS也有一段时间了,整理一下rpm命令的用法

    安装.rpm的文件,-i代表–install,-v代表–verbose,-h代表–hash 以#显示安装进度

    rpm -ivh package.rpm

    升级软件包

    rpm -U packupdate.rpm

    查看已经安装的软件

    列出已经安装的全部软件包,查具体包可接 | grep 来筛选,或使用通配符

    rpm -qa

    例如:

    # rpm -qa httpd* 
    httpd-tools-2.2.15-15.el6.centos.1.x86_64
    httpd-2.2.15-15.el6.centos.1.x86_64
    或
    # rpm -qa | grep http
    httpd-tools-2.2.15-15.el6.centos.1.x86_64
    httpd-2.2.15-15.el6.centos.1.x86_64

    找到某文件属于哪个软件包,使用

    rpm -qf filename

    例如:

    rpm -qf /etc/httpd/conf/httpd.conf

    执行结果: httpd-2.2.15-15.el6.centos.1.x86_64

    -qi 查看已经安装的软件包的功能,

    rpm -qi packagename

    -pqi 查看没有安装的.rpm包的详细信息

    [root@localhost ~]# rpm -pqi epel-release-6-8.noarch.rpm 
    Name        : epel-release                 Relocations: (not relocatable)
    Version     : 6                                 Vendor: Fedora Project
    Release     : 8                             Build Date: Mon 05 Nov 2012 11:54:41 AM CST
    Install Date: (not installed)               Build Host: buildvm-05.phx2.fedoraproject.org
    Group       : System Environment/Base       Source RPM: epel-release-6-8.src.rpm
    Size        : 22169                            License: GPLv2
    Signature   : RSA/8, Mon 05 Nov 2012 11:29:49 PM CST, Key ID 3b49df2a0608b895
    Packager    : Fedora Project
    URL         : http://dl.fedoraproject.org/pub/epel/
    Summary     : Extra Packages for Enterprise Linux repository configuration
    Description :
    This package contains the Extra Packages for Enterprise Linux (EPEL) repository
    GPG key as well as configuration for yum and up2date.

    如查看wget的功能说明

    rpm -qi wget

    删除已经安装的软件包

    rpm -e packagename

    查看已经安装好的软件包都包含哪些文件

    rpm -ql iptables

    查看某个 rpm 包包含有哪些文件

    rpm -qlp package.rpm

    对于 yum 源里没有安装在本机的 rpm 包查看要装哪些文件,可以这样查(前提要安装好yum-utils)

    repoquery -q -l --plugins memcached

    参考:http://www.cyberciti.biz/faq/howto-list-find-files-in-rpm-package/

  • ssh登录自动发邮件提醒

    大前提:

    因涉及到发邮件,debian下需安装exim4并可对外发邮件,centos则需安装mailx,sendmail。

    方案1,对所有用户生效,创建文件

    vim /etc/ssh/sshrc

    加入以下内容

    #!/bin/bash
    [email protected]
    mail -s "notification:user $USER login from ${SSH_CLIENT%% *}" $yourmail <<EOT
     the ip information : http://www.123cha.com/ip/?q=${SSH_CLIENT%% *}
     login date: `date +%Y/%m/%d" "%H:%M:%S`
     if this is not you , please contact xxx for help.
    EOT

    方案2,不影响他人,只针对自己的账户

    vim ~/.bashrc

    添加

    echo 'ALERT Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" [email protected]
  • PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted

    今天在用某程序生成html文章的时候,到46%的时候页面空白了。

    首先就是查nginx的日志

    2012/11/18 22:01:02 [error] 11485#0: *66546 FastCGI sent in stderr: “PHP message: PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in ….

    网上一查,才发现设定的值偏小了,到php.ini查找,466行处

    memory_limit = 128M

    改为256M后,重新生成html,没有问题了。

    昨天刚学了vim的一个技巧:将光标定位在128上,按住ctrl+a,数字变大,这次正好用上了。(数字减小,按ctrl+x)

    另一种方法是修改程序,不建议这样操作。

    具体说明在:http://www.php.net/manual/en/ini.core.php#ini.memory-limit

    要设置不限制,则值为-1

     

  • linux中pkill,kill,killall的用法

    killall也可以跟进程名

    killall – kill processes by name

    killall sends a signal to all processes running any of the specified commands. If no signal name is specified, SIGTERM is sent.

    kill 是要据进程号来杀死进程,加-9强制杀死

    结合ps 或 pgrep

    pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout. All the criteria have to match. For example,

    $ pgrep -u root sshd

    will only list the processes called sshd AND owned by root.

    但是这样只会显示进程号,怎么办? 永远不要忘了man一下

    man pgrep里给出了实例

    我试了一下,如

    ps `pgrep -u www-data` 或者 ps $(pgrep -u www-data) 可以查看到详细的属于www-data用户的进程

    root@debian:~# ps `pgrep -u www-data`
    PID TTY STAT TIME COMMAND
    3128 ? S 0:00 : worker process
    12245 ? S 0:04 php-fpm: pool www
    12246 ? S 0:04 php-fpm: pool www
    12247 ? S 0:05 php-fpm: pool www
    12248 ? S 0:06 php-fpm: pool www
    12249 ? S 0:05 php-fpm: pool www
    12250 ? S 0:05 php-fpm: pool www

  • vim光标移动

    将光标移到指定列,输入 数字+| ,例如 77|

    向右移动指定数量字符,输入 数字+l(小写L) ,例如 5l
    向左移动指定数量字符,输入 数字+h(小写H) ,例如 8h

    移动光标到上一个单词首字母,输入 b
    移动光标到下一个单词首字母,输入 w

    移动光标到行首,按0
    移动光标到行尾,按$

    移动光标到指定行行首,例如12行行首:12G 或 :12回车
    首行行首:gg
    最后一行行首:G

    向下移两行: 2+或2j
    向上移两行: 2-或2k

    移动到上一句:)
    移动到下一句:(

    移动到上一段:{
    移动到下一段:}

    在(),{},[],<>中移动光标,当光标在上述四种之内时,按%跳到开始,再按%跳到结尾。在编辑配置文件的时候非常有用。

    在屏幕中移动光标:
    移动到屏幕的最上端:H
    移动到距屏幕最上x行: xH
    移动到屏幕中央:M
    移动到屏幕底部:L
    移动到距屏幕底部x行:xL

    向下(前)滚动:ctrl + f
    向上(回)滚动:ctrl + b

    滚动到下一屏的中央: ctrl + d
    滚动到上一屏的中央: ctrl + u

    移动光标到屏幕中央(并把当前行带到屏中央,与M略有不同),小写字符:zz
    将当前行置于屏幕顶端 zt
    将当前行置于屏幕底端 zb

    行不动,整个文档向上移 ctrl + e
    整个文档向下移 ctrl + y

  • linux beep蜂鸣声

    公司搬家得到一台老IBM笔记本,各种折腾,今天折腾一下蜂鸣声。

    有时候按tab补全,vim输入错误等都会听到这样的报警声,很难听,如果想关掉它,

    临时关闭

    debian:

     $sudo rmmod pcspkr

    centos以root执行

     #rmmod pcspkr

    永久关闭

    debian:

     $sudo echo "blacklist pcspkr" >> /etc/modprobe.d/blacklist

    centos以root执行:

     #echo "alias pcspkr off" >> /etc/modprobe.conf

    不关闭就可以用beep来做一些有意思的警告了,甚至把警告变为music

    apt-get install beep

    加载驱动:

     modprobe pcspkr

    通过beep来操作(会听到嘀一声):

     beep -f 1000

    以下“音乐”摘自
    http://kirrus.co.uk/2010/09/linux-beep-music/

    beep -f 1000 -n -f 1500 -n -f 600 -n -f 500 -n -f 100 -r 2 -l 10 -n -f 50 -r 2 -l 200 -n -f 40 -r 2 -l 300 -n -f 60 -r 3 -n -f 50 -r 3

    星球大战的经典铃声:

    beep -l 350 -f 392 -D 100 -n -l 350 -f 392 -D 100 -n -l 350 -f 392 -D 100 -n -l 250 -f 311.1 -D 100 -n -l 25 -f 466.2 -D 100 -n -l 350 -f 392 -D 100 -n -l 250 -f 311.1 -D 100 -n -l 25 -f 466.2 -D 100 -n -l 700 -f 392 -D 100 -n -l 350 -f 587.32 -D 100 -n -l 350 -f 587.32 -D 100 -n -l 350 -f 587.32 -D 100 -n -l 250 -f 622.26 -D 100 -n -l 25 -f 466.2 -D 100 -n -l 350 -f 369.99 -D 100 -n -l 250 -f 311.1 -D 100 -n -l 25 -f 466.2 -D 100 -n -l 700 -f 392 -D 100 -n -l 350 -f 784 -D 100 -n -l 250 -f 392 -D 100 -n -l 25 -f 392 -D 100 -n -l 350 -f 784 -D 100 -n -l 250 -f 739.98 -D 100 -n -l 25 -f 698.46 -D 100 -n -l 25 -f 659.26 -D 100 -n -l 25 -f 622.26 -D 100 -n -l 50 -f 659.26 -D 400 -n -l 25 -f 415.3 -D 200 -n -l 350 -f 554.36 -D 100 -n -l 250 -f 523.25 -D 100 -n -l 25 -f 493.88 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 25 -f 440 -D 100 -n -l 50 -f 466.16 -D 400 -n -l 25 -f 311.13 -D 200 -n -l 350 -f 369.99 -D 100 -n -l 250 -f 311.13 -D 100 -n -l 25 -f 392 -D 100 -n -l 350 -f 466.16 -D 100 -n -l 250 -f 392 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 700 -f 587.32 -D 100 -n -l 350 -f 784 -D 100 -n -l 250 -f 392 -D 100 -n -l 25 -f 392 -D 100 -n -l 350 -f 784 -D 100 -n -l 250 -f 739.98 -D 100 -n -l 25 -f 698.46 -D 100 -n -l 25 -f 659.26 -D 100 -n -l 25 -f 622.26 -D 100 -n -l 50 -f 659.26 -D 400 -n -l 25 -f 415.3 -D 200 -n -l 350 -f 554.36 -D 100 -n -l 250 -f 523.25 -D 100 -n -l 25 -f 493.88 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 25 -f 440 -D 100 -n -l 50 -f 466.16 -D 400 -n -l 25 -f 311.13 -D 200 -n -l 350 -f 392 -D 100 -n -l 250 -f 311.13 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 300 -f 392.00 -D 150 -n -l 250 -f 311.13 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 700 -f 392

    –add by jpuyy@2013年03月20日

    解决linux播放音乐不出声的问题

    想用这台老本放音乐,但是每次都不出声,安装好了alsa,使用lsmod查看能看到声卡。困扰很久,后来查到一篇文章,http://xghe110.blog.51cto.com/337884/65713 查到原来alsamixer默认是不出声的。

    解决方法:

    1. root用户输入 #alsamixer,在界面中,左右方向键选择声道,上下方向选择大小。(关键)按m打开对应的声道。

    2. 输入# alsactl store 保存当前的配置。

    3. 在/etc/rc.local中加入 alsactl restore,下次重启后自动载入当前的alsa配置。

    这时,通过mpg321,mplayer,mocp来播放音乐。