Blog

  • 自动更新花生壳的ip

    参考:

    http://open.oray.com/wiki/doku.php?id=文档:花生壳:http协议说明

    只能使用GET方式提交信息,这里使用curl,需提前安装好curl。
    加一个判断,如果当前dns中的ip和检测的ip不一致时,就自动提交;一致则退出。

    #!/bin/bash
    orayuser=your oray name
    oraypass=your oray passoword
    oraydomain=your domain
    realip=`curl http://ddns.oray.com/checkip | cut -d' ' -f 6 | cut -d'<' -f 1`
    theurl="http://$orayuser:[email protected]/ph/update?hostname=$oraydomain&myip=$realip"
    currentip=`nslookup $oraydomain | tail -2 | head -1 | cut -d' ' -f 2`
    if [ "$realip" = "$currentip" ]; then
     exit 0
    else
     curl "$theurl"
    fi

    在crontab中加入以下内容,每十五分钟检测一次

    */15 * * * * /bin/bash /root/pushiporay.sh

    –添加于2013年3月3日开始–

    后来申请了noip.com的二级域名,才发现花生壳和人家的api是如此的像。同理可更新noip里的记录

    #!/bin/bash
    noipuser=your noip username
    noippass=your noip password
    noipdomain=your noip domain
    realip=`curl http://ddns.oray.com/checkip | cut -d' ' -f 6 | cut -d'<' -f 1`
    noipurl="http://$noipuser:[email protected]/nic/update?hostname=$noipdomain&myip=$realip"
    noipcurrentip=`nslookup $noipdomain | tail -2 | head -1 | cut -d' ' -f 2`
    if [ "$realip" = "$noipcurrentip" ]; then
     echo "no need to update"
     exit 0
    else
     curl "$noipurl"
    fi

     

  • discuzx2.5放在目录中的nginx rewrite规则

    如果论坛放在/club目录时,nginx中对应server{}的discuz rewrite可使用如下规则实现伪静态。

     

    location /club/ {
        index index.php;
        try_files $uri $uri/ @discuz;
    }
    
    location @discuz {
        rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
        rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
        rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
        rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
        rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
        rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
        rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
        rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
        rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
        if (!-e $request_filename) {
        return 404;
        }
    }
  • bash创建mysql数据库脚本

    需要批量创建数据库及数据库对应用户,写了一个对于mysql的执行脚本。

    #!/bin/bash
     #用法:将数据库名/用户名用:分隔开,每个一行,写入一个文件,执行脚本+文件名,可创建数据库,并为其分配同名用户
     IFS=:
     while read dbname dbpassword
     do
     sql_user='root'
     sql_pass='root'
     mysql -u $sql_user -p$sql_pass -s <<EOT
     create database if not exists $dbname default charset utf8 collate utf8_general_ci;
     QUIT
     EOT
     mysql -u $sql_user -p$sql_pass -s << EOF
     insert into mysql.user (Host,User,Password) values ("localhost","$dbname",PASSWORD("$dbpassword"));
     flush privileges;
     grant all on $dbname.* to $dbname@localhost;
     flush privileges;
     QUIT
     EOF
    done < $1
  • nginx使用phpmyadmin及配置

    要求:在nginx环境下,打开服务器的http://ip/phpmyadmin或http://域名/phpmyadmin都能够使用phpmyadmin,则只需在对应网站的server{}中添加如下配置即可。

    #------ nginx.conf phpmyadmin ------#
            location /phpmyadmin {
                    alias /usr/share/phpMyAdmin;
                    index index.php;
            }
            location ~ ^/phpmyadmin/.+\.php$ {
                    if ($fastcgi_script_name ~ /phpadmin/(.+\.php)$) {
                            set $valid_fastcgi_script_name $1;
                    }
                    include        fastcgi_params;
                    fastcgi_index  index.php;
                    fastcgi_pass   127.0.0.1:9000;
                    fastcgi_param  SCRIPT_FILENAME /usr/share/phpMyAdmin/$valid_fastcgi_script_name;
            }
    
    #------ nginx.conf phpmyadmin end ------#
  • CentOS6.2安装epel包

    官方介绍:

    https://fedoraproject.org/wiki/EPEL/zh-cn

    在装了epel之后,要安装nginx,php,mysql,直接yum install就可以了。

    EPEL 包含一个叫做’epel-release’的包,这个包包含了 EPEL 源的 gpg 密钥和软件源信息。

    现在安装epel-release

    rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

    重装

    rpm -iv --replacepkgs http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

    上面的地址经常变,可以打开下面网址找到epel包

    http://dl.fedoraproject.org/pub/epel/6/x86_64/

    导入RPM-GPG-KEY-EPEL的key

    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

    epel安装完之后在/etc/yum.repos.d/下生成了两个文件,epel.repo,epel-testing.repo

    修改epel.repo文件(epel-testing包含最新的测试软件包,其版本很新但是安装有风险)

    在[epel-debuginfo]前添加

    priority=11

    这样yum时会先去官方源查找,官方源没有再去epel安装

    PS:还有一款不错的源,叫atomic,包含有php-fpm,安装这个源则更为方便,此脚本会自动安装对应系统的版本,更省心。

    wget -q -O - http://www.atomicorp.com/installers/atomic | sh

    同样rpmforge也很不错,在这里查看对应版本的安装方法

    http://wiki.centos.org/zh/AdditionalResources/Repositories/RPMForge

    epel centos6 源

    [epel]
    name=Extra Packages for Enterprise Linux 6 - $basearch
    baseurl=http://mirrors.tuna.tsinghua.edu.cn/epel/6/$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
    baseurl=http://mirrors.tuna.tsinghua.edu.cn/epel/6/$basearch/debug
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=1
    
    [epel-source]
    name=Extra Packages for Enterprise Linux 6 - $basearch - Source
    baseurl=http://mirrors.tuna.tsinghua.edu.cn/epel/6/SRPMS
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=1
    
  • 购买了创新小魔镜和罗技k240

    在58同城上浏览电脑配件,发现有个人发了一堆东西,里面有我想要的创新mp3和无线键鼠

    记得大学那会儿买了创新小石头,便宜又好用,电量坚挺,到现在淘宝上二手的都比当时买的价格贵了,毕业了有时候跑步,还是有个mp3方便。

    去和卖主见面,才发现他就是做电子产品生意的,包装还没有拆封,生产日期是2008年07月,现在都2012年9月了,拆开试了一下,一点问题没有,¥90成交。

    还有mk240黑色的也是未拆封的,用了一下,挺迷你,平时办公可能不太适合,娱乐就很适合了;鼠标是不发光的,带开关,键盘没有开关,用起来很省地方,但是没有指示灯。没有数字键用起来也很不错。¥75成交
    罗技的mk240,在windows下安装好set point,可以查看电量, 某些按键如Caps Lock的屏幕提示。