Category: Linux

  • ubuntu vps使用zh_CN.utf8编码

    使用

    locale -a

    发现只有英文编码,使用命令

    bash /usr/share/locales/install-language-pack zh_CN

    install-language-pack脚本内容如下:

    #!/bin/sh -e
    
    if [ -z "$1" ]; then
        echo "Usage: $0 <language code> <class> [<version>]"
        exit 0
    fi
    
    # install locales for base packages (not for gnome/kde)
    # (use "--no-purge" in case PURGE=yes is used in config, which would remove
    #  all other locale files)
    if [ -z "$2" ]; then
        /usr/sbin/locale-gen --no-purge --lang "$1"
    fi
    
    # ensure that .desktop caches are up to date
    dpkg-trigger gmenucache || true

    通过如下命令,使默认编码为 zh_CN.utf8

    echo LANG="zh_CN.utf8" >> /etc/environment

    这样

    echo $LANG显示是
    zh_CN.utf8

    加其他语言编码雷同

    追加:
    使用dpkg-reconfigure来改变语言包更简单

    # dpkg-reconfigure locales

    CentOS7设置 locale

    localectl status # to display locale settings
    localectl set-locale LANG=en_GB.utf8 # to set the Language
    
  • shell 毕业倒计时

    参考鸟哥linux私房菜p389

    #!/bin/bash
    #for use:
    #author: jpuyy date  jpuyy.com [email protected]
    #modified by xx at date
    #version:
    #history:
    #relate on:
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
    export PATH
    
    echo "count down script"
    echo "how many time to graduate"
    read -p "please input your graduate time format like 20120620:" date2
    
    date_d=$(echo $date2 | grep '[0-9]\{8\}')
    if [ "$date_d" == "" ]; then
        echo "your input is wrong"
        exit 1
    fi
    
    declare -i date_dem=`date --date="$date2" +%s`
    declare -i date_now=`date +%s`
    declare -i date_total_s=$(($date_dem-$date_now))
    declare -i date_d=$(($date_total_s/60/60/24))
    
    if [ "$date_total_s" -lt "0" ]; then
        echo "you have graduated $((-1*$date_d)) days"
    else
        declare -i date_h=$(($(($date_total_s-$date_d*60*60*24))/60/60))
        echo "you left $date_d days and $date_h hours."
    fi

    执行

    其实不光有倒计时功能,也可以看已发生的事件到现在多长时间了

    收获:

    打代码时候vim颜色提醒了标点符号,节省了很多力气

    找码一定要打出来才知道掌握了多少,空想不可取,再少代码也不可复制。

    用到知识:date 和 时间换算常识

    root@www:/home/jpuyy/shellstudy# bash sh11.sh
    count down script
    how many time to graduate
    please input your graduate time format like 20120620:20120620
    you left 203 days and 11 hours.

    离毕业不远了啊

     

  • ubuntu下PAC Manager使用

    windows下面经常用Secure CRT来多标签连SSH

    linux下面用PAC Manager也是想当的顺手

    支持rsa加密的key来连接

    下载地址:http://sourceforge.net/projects/pacmanager/

    怎么生成key,看之前的ssh的key的生成

    在PAC Manager使用key的认证会提示说

    @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
    
    Permissions 0440 for '/home/jpuyy/Dropbox/key/xxxxx' are too open.
    It is recommended that your private key files are NOT accessible
    by others.
    This private key will be ignored.

    这样的话它是希望权限规定的越死越好,那么把文件弄成400,即只允许用户的读权限,其它一律不许

    chmod 400 xxx

    这样就可以了

    :)EOT

  • 安装php5扩展模块eaccelerator

    首先下载eaccelerator最新版

    wget http://sourceforge.net/projects/eaccelerator/files/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2

    网上的教程说要有/usr/local/php/bin/phpize,但是我的vps上的php是apt-get的没有怎么办?

    搜索得知要安装php5-dev才会有phpize,还要安装autoconf,automake

    apt-get install php5-dev autoconf automake

    安装到最后提示了

    update-alternatives: using /usr/bin/php-config5 to provide /usr/bin/php-config (php-config) in auto mode.
    update-alternatives: using /usr/bin/phpize5 to provide /usr/bin/phpize (phpize) in auto mode.

    既然给了上面的提示,就用带5的

    准备工作差不多了开始安装

    tar jxvf eaccelerator-0.9.6.1.tar.bz2
    cd eaccelerator-0.9.6.1
    /usr/bin/phpize5
    ./configure --enable-eaccelerator=shared --with-php-config=/usr/bin/php-config5
    make
    make install

    提示说 Installing shared extensions:     /usr/lib/php5/20090626+lfs/

    这样创建缓存目录

    mkdir /tmp/eaccelerator
    chmod 777 /tmp/eaccelerator

    这时编辑/etc/php5/fpm/php.ini在最后加入如下代码

    配置项更具体准确的含义来自:https://eaccelerator.net/wiki/Settings

    vim /etc/php5/fpm/php.ini
    [eaccelerator]
    zend_extension="/usr/lib/php5/20090626+lfs/eaccelerator.so"
    eaccelerator.shm_size="32"
    eaccelerator.cache_dir="/tmp/eaccelerator"
    eaccelerator.enable="1"
    eaccelerator.optimizer="1"
    eaccelerator.check_mtime="1"
    eaccelerator.debug="0"
    eaccelerator.filter=""
    eaccelerator.shm_max="0"
    eaccelerator.shm_ttl="300"
    eaccelerator.shm_prune_period="120"
    eaccelerator.shm_only="0"
    eaccelerator.compress="1"
    eaccelerator.compress_level="9"

    重启下php5-fpm

    /etc/init.d/php5-fpm restart

    如何检测呢,搞一个phpinfo();

    eAccelerator 这一节的描述

    这时进到/tmp/eaccelerator会发现有不少的目录

    收获:

    有空的话还是要不怕麻烦编译安装,这样对程序会更熟悉

    不要从不靠谱的网上直接复制配置文件,复制过来的双引号全是中文的

    续:

    按wiki里面说的我查看了下最大共享大小

    cat /proc/sys/kernel/shmmax

    得到33554432

    用expr除了两次:

    expr 33554432 \/ 1024
     32768
     expr 32768 \/ 1024
     32

    而这样按配置设置64,php5-fpm就不能重启成功

    比如想弄成64,则

    echo 67108864 > /proc/sys/kernel/shmmax

    效果如何?

    不会测试,网上人说的是ea的作用就是让缓存里php文件不需要再次编译,这一点我觉得有可能吧

  • 本博客支持ipv6访问!

    本博客支持ipv6访问!

    最近nginx要升级1.1.7,而且vps支持ipv6,并送了一个ipv6地址

    正好学校里有ipv6上网环境,大致步骤是加入ipv6模块,并在nginx的配置里加入ipv6监听,使用ipv6可以直接访问

    nginx的升级和加入ipv6模块

    wget http://nginx.org/download/nginx-1.1.7.tar.gz
     tar vxzf nginx-1.1.7.tar.gz
     cd nginx-1.1.7
     ./configure --with-ipv6
     make
     mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
     cp objs/nginx /usr/local/nginx/sbin/nginx
     make upgrade

    测试下配置文件:/usr/local/nginx/sbin/nginx -t

    查看下,已经添加了ipv6模块

    root@www:~# nginx -V
     nginx: nginx version: nginx/1.1.7
     nginx: built by gcc 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)
     nginx: configure arguments: --with-ipv6

    nginx的配置文件

    里面加入下面指令,如果是默认网站的话加default

    listen [::]:80 default;

    http://[2604:6600:1059::5810:3a0a]/

    重新加载配置文件

    kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

    不要用nginx -s reload 我用了不管用

    在域名提供商那里加入ipv6的AAAA记录

    godaddy AAAA record

    去 http://ipv6-test.com/  加一张认证图过来

    blog support ipv6 visit

     

    :)EOT

     

  • 安装php5-gd库

    在自已的vmplayer里面装了一个oecms,但是装好后验证码始终出不来,ie下显示一个红叉,火狐下显示空白。

    开始我想会不会是因为缓存和目录权限的问题

    后来看了看php代码发现里面直接就是image/PNG,我一想,应该是php库没装全,于是去网上搜了一下,这个库包含了libjpeg,libpng

    于是

    apt-get install php5-gd

    问题解决。

    PHP处理图像,使用了GD库,它使php支持 gif , jpeg , ttf ,wbmp

    :)EOT