• CentOS 5.2下Memcache的安装与配置

    安装服务器端:
    1,安装libevent库,它将Linux的epoll、freebsd操作系统的kqueue等事件处理功能封装成统一的接口,memcached使用这个库,可以发挥其高性能。
    [root@youxia205 opt]# yum install libevent libevent-devel
    2,下载memcache源码包:
    [root@youxia205 opt]# wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
    3,解压、编译、安装:
    [root@youxia205 opt]# tar -zxvf memcached-1.4.5.tar.gz
    [root@youxia205 opt]# cd memcached-1.4.5
    [root@youxia205 memcached-1.4.5]# ./configure
    [root@youxia205 memcached-1.4.5]# make && make install
    4,安装完成之后可以看下memcache的参数:
    [root@youxia205 local]# memcached -help
    memcached 1.4.5
    -p <num>      TCP port number to listen on (default: 11211)
    -U <num>      UDP port number to listen on (default: 11211, 0 is off)
    -s <file>     UNIX socket path to listen on (disables network support)
    -a <mask>     access mask for UNIX socket, in octal (default: 0700)
    -l <ip_addr>  interface to listen on (default: INADDR_ANY, all addresses)
    -d            run as a daemon
    -r            maximize core file limit
    -u <username> assume identity of <username> (only when run as root)
    -m <num>      max memory to use for items in megabytes (default: 64 MB)
    -M            return error on memory exhausted (rather than removing items)
    -c <num>      max simultaneous connections (default: 1024)
    -k            lock down all paged memory.  Note that there is a
    limit on how much memory you may lock.  Trying to
    allocate more than that would fail, so be sure you
    set the limit correctly for the user you started
    the daemon with (not for -u <username> user;
    under sh this is done with ‘ulimit -S -l NUM_KB’).
    -v            verbose (print errors/warnings while in event loop)
    -vv           very verbose (also print client commands/reponses)
    -vvv          extremely verbose (also print internal state transitions)
    -h            print this help and exit
    -i            print memcached and libevent license
    -P <file>     save PID in <file>, only used with -d option
    -f <factor>   chunk size growth factor (default: 1.25)
    -n <bytes>    minimum space allocated for key+value+flags (default: 48)
    -L            Try to use large memory pages (if available). Increasing
    the memory page size could reduce the number of TLB misses
    and improve the performance. In order to get large pages
    from the OS, memcached will allocate the total item-cache
    in one large chunk.
    -D <char>     Use <char> as the delimiter between key prefixes and IDs.
    This is used for per-prefix stats reporting. The default is
    “:” (colon). If this option is specified, stats collection
    is turned on automatically; if not, then it may be turned on
    by sending the “stats detail on” command to the server.
    -t <num>      number of threads to use (default: 4)
    -R            Maximum number of requests per event, limits the number of
    requests process for a given connection to prevent
    starvation (default: 20)
    -C            Disable use of CAS
    -b            Set the backlog queue limit (default: 1024)
    -B            Binding protocol – one of ascii, binary, or auto (default)
    -I            Override the size of each slab page. Adjusts max item size
    (default: 1mb, min: 1k, max: 128m)
  • 用css控制图片最大尺寸

    <style type=”text/css”>
    <!–
    img,a img{
    border:0;
    margin:0;
    padding:0;
    max-width:650px;
    width: expression(this.width > 650 && this.width > this.height ? 650px : ‘auto’;);
    max-height:1650px;
    height: expresion(this.height > 1650 ? 1650px : ‘auto’;);
    } –>
    </style>
  • 常见mysql远程连接错误解决方法

    1,远端无法telnet到mysql服务器的3306无反应

    解决方法:

    进入/etc/mysql/my.cnf,找到bind-address   = 127.0.0.1,将其注释掉,然后自毁执行/etc/init.d/mysql restart重启.

    2,ip地址不被允许访问该mysql服务器

    解决方法:

    grant all PRIVILEGES on *.* to root@’您的本地ip地址’ identified by ‘数据库密码’;

    *.*代表 数据库.数据表

    all PRIVILEGES 所有权限   也可以是create,select,insert,update,delete

  • svn的安装与远程备份

    svn的安装与远程备份

  • linux下 A服务器到B服务器(远程)备份

    linux下 A服务器到B服务器(远程)备份
    一个示例脚本
    A:首先手动备份一个目录压缩成一个tar.gz
    写一个执行脚本
    #! /bin/sh
    rm /var/www/备份源文件_bak.tar.gz
    tar -cvzf /var/www/备份源文件_bak.tar.gz /var/www/源文件夹
    rq=`date +%Y%m%d` 生成当前日期
    scp /var/www/备份源文件_bak.tar.gz root@XXX.XXX.XXX.XXX:/var/wiki_copy/备份新名称i$rq.tar.gz
    scp命令 从A服务器拷贝文件到B服务器(XXX.XXX.XXX.XXX)
  • svn数据备份,还原检出到其他目录

    hooks目录下的post-commit 是上传钩子脚本
    即你从本地上传文件到svn服务器的时候触发该脚本
    注意post-commit 文件权限为root可执行
    vi  /var/svn/project-name/hooks/post-commit
    #!/bin/sh
    export LANG=zh_CN.UTF-8
    REPOS=”$1″
    REV=”$2″
    svn checkout –username 用户名 –password 密码 svn://127.0.0.1/test /var/www/test
    ##从svn版本库中检出源文件到新的目录  /var/www/test
  • apache端口转发

    在某些时候,可能需要将发到apache某个端口的请求转发到另外一个端口. mod_proxy模块可以方便的完成这个需求.
    ubuntu中配置apache2比较方便.  下面以lucid中apache2为例介绍如何使用 mod_proxy
    1. 首先配置mod_proxy模块
    将/etc/apache2/mods-available中的
    proxy_http.load
    proxy.load
    proxy.conf
    proxy_connect.load
    ln -s 到 /etc/apache2/mods-enabled
    注意需要适当的修改 proxy.conf
    2. 在 /etc/apache2/sites-enabled中建立一个文件(或一个连接 ln -s 到一个文件)
    <VirtualHost *:80>
    ProxyPreserveHost On
    ServerName www.example.com
    ProxyPass / http://www.example.com:8000/
    ProxyPassReverse / http://www.example.com:8000/
    ServerAdmin webmaster@localhost
    </VirtualHost>
    这样, 所有http://www.example.com 请求实际上都是到了其 8000端口. 80端口实际上成了 8000端口的一个代理
    当然 mod_proxy能够完成的任务不止这些. 例如, 它可以将请求转发到别的服务器上(配置合适的话).
    使用该模块应该注意 proxy.conf的配置.
  • debian操作系统安装记录

    1.安装sudo  编辑/etc/sudoers
    2.安装配置apt源
    vim /etc/apt/source.list
    然后进行更新源
    apt-get -s upgrade
    apt-get update
    3.安装ssh(openssh-server)
    4.安装rcconf(服务管理器)管理需要启动的服务
  • scp命令:两台服务器文件传输,进阶-设置两台服务器不需要密码直接复制

    scp 命令是 SSH 中最方便有用的命令了,试想,在两台服务器之间直接传送文件,仅仅用 scp 一个命令就完全解决了。 你可以在一台服务器上 以 root 身份运行 #scp servername:/home/ftp/pub/file1 . 这样就把另一台服务器上的文件 /home/ftp/pub/file1 直接传到本机器的当前目录下,当然你也可以用 #scp /tmp/file2 servername:/boot 把本机上的文件 /tmp/file2 送到另一台机器的 /boot 目录下。而且整个传送过程仍然是用 SSH 加密的。
    scp 就是 secure copy, 是用来进行远程文件拷贝的 . 数据传输使用 ssh1, 并且和 ssh1 使用相同的认证方式 , 提供相同的安全保证 . 与 rcp 不同的是 ,scp 会要求你输入密码如果需要的话 .
    案例:
    copy 本地的档案到远程的机器上
    scp /etc/lilo.conf my@www.upsdn.net:/home/my

    scp 命令是 SSH 中最方便有用的命令了,试想,在两台服务器之间直接传送文件,仅仅用 scp 一个命令就完全解决了。 你可以在一台服务器上 以 root 身份运行 #scp servername:/home/ftp/pub/file1 . 这样就把另一台服务器上的文件 /home/ftp/pub/file1 直接传到本机器的当前目录下,当然你也可以用 #scp /tmp/file2 servername:/boot 把本机上的文件 /tmp/file2 送到另一台机器的 /boot 目录下。而且整个传送过程仍然是用 SSH 加密的。
    scp 就是 secure copy, 是用来进行远程文件拷贝的 . 数据传输使用 ssh1, 并且和 ssh1 使用相同的认证方式 , 提供相同的安全保证 . 与 rcp 不同的是 ,scp 会要求你输入密码如果需要的话 .
    案例:
    copy 本地的档案到远程的机器上

    scp /etc/lilo.conf my@www.upsdn.net:/home/my/123.conf

    copy远程机器上的档案到本地来

    scp my@www.upsdn.net:/etc/lilo.conf /etc

    进阶—————-

    最近在编写定时自动执行的shell脚步中遇到一个问题。在该脚步中,需要使用scp命令将本地的文件复制到另一台机器中备份。但通常执行scp命令后都需要输入用户密码,这样在定时自动执行的shell脚步中就不适用了。

    本人的第一直觉就是建立无密码用户,在scp命令中使用该用户就不需要输入用户密码了。

    以下是在机器Client的root和机器Server的root之间建立安全信任关系的步骤:

    1. 在机器Client上root用户执行ssh-keygen命令,生成建立安全信任关系的证书。

    [root@Client root]# ssh-keygen -b 1024 -t rsa

    Generating public/private rsa key pair.

    Enter file in which to save the key (/root/.ssh/id_rsa):

    Enter passphrase (empty for no passphrase):            <– 直接输入回车

    Enter same passphrase again:                           <– 直接输入回车

    Your identification has been saved in /root/.ssh/id_rsa.

    Your public key has been saved in /root/.ssh/id_rsa.pub.

    The key fingerprint is:

    49:9c:8a:8f:bc:19:5e:8c:c0:10:d3:15:60:a3:32:1c root@Client

    [root@Client root]#

    注意:在程序提示输入passphrase时直接输入回车,表示无证书密码。

    上述命令将生成私钥证书id_rsa和公钥证书id_rsa.pub,存放在用户家目录的.ssh子目录中。

    2. 将公钥证书id_rsa.pub复制到机器Server的root家目录的.ssh子目录中,同时将文件名更换为authorized_keys。

    [root@Client root]# scp -p .ssh/id_rsa.pub root@192.168.3.206:/root/.ssh/authorized_keys

    root@192.168.3.206’s password:          <– 输入机器Server的root用户密码

    id_rsa.pub           100% |**************************|   218       00:00

    [root@Client root]#

    在执行上述命令时,两台机器的root用户之间还未建立安全信任关系,所以还需要输入机器Server的root用户密码。

    经过以上2步,就在机器Client的root和机器Server的root之间建立安全信任关系。

  • crontab应用

    wiki备份
    #! /bin/sh
    rm /var/www/dokuwiki_bak.tar.gz
    tar -cvzf /var/www/dokuwiki_bak.tar.gz /var/www/dokuwiki
    rq=`date +%Y%m%d`
    scp /var/www/dokuwiki_bak.tar.gz root@211.157.136.46:/var/wiki_copy/dokuwiki$rq.tar.gz
    延深:系统环境 debian5.0
    方法1:
    在linux平台上如果需要实现任务调度功能可以编写cron脚本来实现。
    以某一频率执行任务
    linux缺省会启动crond进程,crond进程不需要用户启动、关闭。
    crond进程负责读取调度任务并执行,用户只需要将相应的调度脚本写入cron的调度配置文件中。
    cron的调度文件有以下几个:均在/etc/目录下
    crontab
    cron.d
    cron.daily
    cron.hourly
    cron.monthly
    cron.weekly
    如果用的任务不是以hourly monthly weekly方式执行,则可以将相应的crontab写入到crontab 或cron.d目录中。
    示例内容为
    分钟 小时 天 月 星期 用户 命令
    */2 * * * * root  /opt/bin/test-cron.sh #每两分钟就执行……..
    0 6,12,18   *   *   *    root      ……………      #每天6点、12点、18点执行……..
    启动cron进程的方法:/etc/init.d/crond start
    方法二:
    把cron加入到启动脚本中:
    # rc-update add vixie-cron default
    crontab -l #查看你的任务
    crontab -e#编辑你的任务(debian系统crontab默认编辑器不是vi,需要修改环境变量EDITOR,(命令:export EDITOR=vim)
    crontab -r#删除用户的crontab的内容
    收获:可以把经常要做的一些事放到其中,简化工作量,如每周一检查服务器的运行状态,查看报告,杀掉一些进程等等……