“Linux” 标签页面:

  • Linux安装Python2.7并保留自带版本

    Linux很多组件需要Python,但自带的都是比较旧的版本,但不少程序也需要Python,但都是要求比较高的版本,但Python新旧版本不太兼容,所以……

    我们很有比较在系统上装个新版本,但默认还是要用旧版的Python。以下是安装过程。

    装较新版sqlite,否则新版的2.7会编译出错,而且一些Python应用程序也会莫名其妙地运行出错。

    wget http://www.sqlite.org/sqlite-autoconf-3071401.tar.gz
    tar zxf sqlite-autoconf-3071401.tar.gz
    ./configure
    make && make install
    ln -sf /usr/local/lib/libsqlite3.so /usr/lib/libsqlite3.so
    ln -sf /usr/local/lib/libsqlite3.so.0.8.6 /usr/lib/libsqlite3.so.0.8.6
    ln -sf /usr/local/lib/libsqlite3.so.0 libsqlite3.so.0.8.6

    然后安装Python,这里安装到/usr/local/python27的路径,防止覆盖掉旧版。

    wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
    tar zxf Python-2.7.3.tgz
    cd Python-2.7.3
    ./configure --prefix=/usr/local/python27
    make
    make install
    ln -sf /usr/local/python27/bin/python2.7 /usr/local/bin/python2.7

    然后安装setuptools,即easy_install。

    wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
    tar zxf setuptools-0.6c11.tar.gz
    cd setuptools-0.6c11
    python2.7 setup.py install
    ln -sf /usr/local/python27/bin/easy_install-2.7 /usr/local/bin/easy_install-2.7

    好了,现在如果要用自带的Python,则直接运行对应的py文件即可,如果要用安装的Python2.7,则使用“python2.7 xxx.py”即可。

    使用easy_install也是,自带的直接运行“easy_install xxx”,对应Python2.7的运行“easy_install2.7 xxx”。

    2012.11.08 / 6 条评论 / 6,318 次点击 / 分类: 所谓技术

  • 在Linux中安装plowshare

    使用git将项目clone到机器上并安装。如果没有git,可以参考《CentOS安装git》安装。

    使用以下命令进行安装plowshare

    git clone https://code.google.com/p/plowshare/

    cd plowshare

    然后,由于新版的plowshare默认是支持bash4以上,而大多数Linux都还是bash3,如果运行,会出现“plowshare/src/core.sh: line 2592: local: -u: invalid option”的错误提示,所以正在用bash3的用户要改成支持bash3的分支。

    git branch -a #看到有两个分支,一个master,一个bash3,HEAD则是头分支

    git checkout bash3 #切换到bash3分支,并自动track远程的同名分支

    最后安装(如果用了bash4的版本则将“plowshare3”改为“plowshare4”):

    make install PREFIX=/usr/local/plowshare

    ln -sf /usr/local/plowshare/share/plowshare3/download.sh /usr/local/bin/plowdown

    ln -sf /usr/local/plowshare/share/plowshare3/upload.sh   /usr/local/bin/plowup

    ln -sf /usr/local/plowshare/share/plowshare3/delete.sh   /usr/local/bin/plowdel

    ln -sf /usr/local/plowshare/share/plowshare3/list.sh     /usr/local/bin/plowlist

    安装完毕好,就可以直接使用:

    plowdown 网址

    即可将网络硬盘上面的内容下载到本地了。如果有验证码,则要根据提示找到验证码,并将验证码输入即可,或者加上“--captchamethod=imgur”参数,把验证码传到imgur网址,就可以直接通过浏览器访问验证码啦。

    更新也很简单,先进入plowshare的git版本目录,运行:

    git pull --all

    rm -rf /usr/local/plowshare/

    make install PREFIX=/usr/local/plowshare

    2012.10.28 / 暂无评论 / 696 次点击 / 分类: 所谓技术

  • CentOS安装git

    CentOS默认源是没有git的,所以希望通过yum install来安装的童鞋们,不要在错误的道路上越走越远……

    所以,要从源安装,对应的命令:

    yum -y install zlib-devel openssl-devel perl cpio expat-devel gettext-devel

    wget http://git-core.googlecode.com/files/git-1.7.7.5.tar.gz

    ./configure --prefix=/usr/local/git

    make

    make install

    然后对执行文件进行链接,当然,如果安装在/usr/local目录的话,就不用这步了。

    ln -s /usr/local/git/bin/git /usr/local/bin/git

    ln -s /usr/local/git/bin/gitk /usr/local/bin/gitk

    ln -s /usr/local/git/bin/git-shell /usr/local/bin/git-shell

    ln -s /usr/local/git/bin/git-upload-pack /usr/local/bin/git-upload-pack

    ln -s /usr/local/git/bin/git-cvsserver /usr/local/bin/git-cvsserver

    ln -s /usr/local/git/bin/git-receive-pack /usr/local/bin/git-receive-pack

    ln -s /usr/local/git/bin/git-upload-archive /usr/local/bin/git-upload-archive

    常见问题

    1、如果出现“git: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory”

    在确认已经安装iconv库的情况下,执行以下命令:

    echo "/usr/local/lib" > /etc/ld.so.conf.d/git.conf

    /sbin/ldconfig

    2、如果在“git clone https://***”时出现“error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing”

    在使用git前加上“GIT_SSL_NO_VERIFY=true”的环境变量,即:

    env GIT_SSL_NO_VERIFY=true git clone https://***

    2012.01.09 / 2 条评论 / 2,521 次点击 / 分类: 所谓技术

  • CentOS下安装使用start-stop-daemon

    CentOS是没有start-stop-daemon的,因为start-stop-daemon在debian的dpkg包里。要安装的话,需要自己折腾。

    相关命令如下:

    wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz

    tar zxf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz

    mv apps/sys-utils/start-stop-daemon-IR1_9_18-2/ ./

    rm -rf apps

    cd start-stop-daemon-IR1_9_18-2/

    cc start-stop-daemon.c -o start-stop-daemon

    cp start-stop-daemon /usr/local/bin/start-stop-daemon

    至此安装完成。可以看到:

    [root@localhost ~]# start-stop-daemon --help
    start-stop-daemon 1.9.18 for Debian - small and fast C version written by
    Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, public domain.

    Usage:
      start-stop-daemon -S|--start options ... -- arguments ...
      start-stop-daemon -K|--stop options ...
      start-stop-daemon -H|--help
      start-stop-daemon -V|--version

    Options (at least one of --exec|--pidfile|--user is required):
      -x|--exec <executable>        program to start/check if it is running
      -p|--pidfile <pid-file>       pid file to check
      -c|--chuid <name|uid[:group|gid]>
                    change to this user/group before starting process
      -u|--user <username>|<uid>    stop processes owned by this user
      -n|--name <process-name>      stop processes with this name
      -s|--signal <signal>          signal to send (default TERM)
      -a|--startas <pathname>       program to start (default is <executable>)
      -N|--nicelevel <incr>         add incr to the process's nice level
      -b|--background               force the process to detach
      -m|--make-pidfile             create the pidfile before starting
      -R|--retry <schedule>         check whether processes die, and retry
      -t|--test                     test mode, don't do anything
      -o|--oknodo                   exit status 0 (not 1) if nothing done
      -q|--quiet                    be more quiet
      -v|--verbose                  be more verbose
    Retry <schedule> is <item>|/<item>/... where <item> is one of
    -<signal-num>|[-]<signal-name>  send that signal
    <timeout>                       wait that many seconds
    forever                         repeat remainder forever
    or <schedule> may be just <timeout>, meaning <signal>/<timeout>/KILL/<timeout>

    Exit status:  0 = done      1 = nothing done (=> 0 if --oknodo)
                  3 = trouble   2 = with --retry, processes wouldn't die

    本文参考了此文档

    2011.12.20 / 3 条评论 / 4,727 次点击 / 分类: 梦溪笔记

  • 让SSH/SOCKS成为全局代理的软件们(Windows+Linux)

    Windows下的有:

    1. Proxifier 下载地址
    2. ProxyCap 下载地址

    前者比较好用,可控规则较多。我正在使用。

    Linux下的有:

    1. proxychains 下载地址
    2. redsocks 下载地址
    3. tsocks 下载地址

    proxychain功能较多,支持多个代理轮询等;redsocks据说支持android;tsocks配置简单。

     

    proxychains教程

    假设代理为127.0.0.1,端口为7070。我在Ubuntu下安装。

    安装很简单:

    sudo apt-get install proxychains

    配置:

    sudo vi /etc/proxychains.conf

    把最后的“[ProxyList]”部分配置为自己的代理即可:

    socks4  127.0.0.1 7070

    使用方法:

    proxychains <程序名>

    即可让程序使用代理。

     

    redsocks教程

    严格意义上来说,proxychains不算自动的全局代理,有没有像Proxifier这样,开了之后自动让所有启动的程序都走系统代理呢?答案就是redsocks。

    首先安装Ubuntu编译环境和必要的库:

    sudo apt-get install autoconf automake libtool libevent-dev g++

    下载源代码,然后编译安装:

    ./mkauto.sh

    cp redsocks /usr/local/bin/

    配置文件为:

    base {
    // debug: connection progress & client list on SIGUSR1
    log_debug = off;

    // info: start and end of client session
    log_info = off;

    /* possible `log' values are:
    * stderr
    * file:/path/to/file
    * syslog:FACILITY facility is any of "daemon", "local0"..."local7"
    */
    log = "file:/dev/null";
    // log = stderr;
    // log = "file:/path/to/file";
    // log = "syslog:local7";

    // detach from console
    daemon = on;

    /* Change uid, gid and root directory, these options require root
    * privilegies on startup.
    * Note, your chroot may requre /etc/localtime if you write log to syslog.
    * Log is opened before chroot & uid changing.
    */
    // user = nobody;
    // group = nobody;
    // chroot = "/var/chroot";

    /* possible `redirector' values are:
    * iptables - for Linux
    * ipf - for FreeBSD
    * pf - for OpenBSD
    * generic - some generic redirector that MAY work
    */
    redirector = iptables;
    }

    redsocks {
    /* `local_ip' defaults to 127.0.0.1 for security reasons,
    * use 0.0.0.0 if you want to listen on every interface.
    * `local_*' are used as port to redirect to.
    */
    local_ip = 127.0.0.1;
    local_port = 12345;

    // `ip' and `port' are IP and tcp-port of proxy-server
    ip = 127.0.0.1;
    port = 7070;

    // known types: socks4, socks5, http-connect, http-relay
    type = socks5;

    // login = "foobar";
    // password = "baz";
    }

    redudp {
    // `local_ip' should not be 0.0.0.0 as it's also used for outgoing
    // packets that are sent as replies - and it should be fixed
    // if we want NAT to work properly.
    local_ip = 127.0.0.1;
    local_port = 10053;

    // `ip' and `port' of socks5 proxy server.
    ip = 10.0.0.1;
    port = 1080;
    login = username;
    password = pazzw0rd;

    // kernel does not give us this information, so we have to duplicate it
    // in both iptables rules and configuration file. By the way, you can
    // set `local_ip' to 127.45.67.89 if you need more than 65535 ports to
    // forward ;-)
    // This limitation may be relaxed in future versions using contrack-tools.
    dest_ip = 8.8.8.8;
    dest_port = 53;

    udp_timeout = 30;
    udp_timeout_stream = 180;
    }

    dnstc {
    // fake and really dumb DNS server that returns "truncated answer" to
    // every query via UDP, RFC-compliant resolver should repeat same query
    // via TCP in this case.
    local_ip = 127.0.0.1;
    local_port = 5300;
    }

    // you can add more `redsocks' and `redudp' sections if you need.

    这里的配置没有配置udp的代理部分,只是配置了tcp即redsocks部分。监听端口是12345。日志关闭了,因为好像我下载的当前版本无论怎么样都产生一堆调试日志,不知道以后会不会修复这点。

    启动关闭脚本redsocks.sh为(via):

    #! /bin/bash

    SSHHOST=creke
    SSHPORT=22
    SSHUSR=creke
    SSHPWD=creke

    SSHDAEMON=/usr/local/bin/plink
    SSHPIDFILE=/var/run/sshtunnel.pid

    start_ssh()
    {
        echo "Start SSH Tunnel Daemon: "
        start-stop-daemon -b -q -m -p $SSHPIDFILE --exec $SSHDAEMON -S \
        -- -N -D 127.0.0.1:7070 -P $SSHPORT -pw $SSHPWD $SSHUSR@$SSHHOST
        echo "SSH Tunnel Daemon Started."
    }

    stop_ssh()
    {
        #ps aux|grep "ssh -NfD 1234"|awk '{print $2}'|xargs kill
        if [ -f $SSHPIDFILE ]; then
        PID=$(cat $SSHPIDFILE)
        kill $PID
        while [ -d /proc/$PID ];
        do
        sleep 1
        done
        fi
        rm -rf $SSHPIDFILE
        echo "SSH Tunnel Daemon Stoped."
    }

    case "$1" in
      start)
        start_ssh
        cd /usr/local/redsocks
        if [ -e redsocks.log ] ; then
          rm redsocks.log
        fi
        ./redsocks -p /usr/local/redsocks/redsocks.pid #set daemon = on in config file
        # start redirection
        # iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to 12345
        # iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDIRECT --to 12345
        # Create new chain
        iptables -t nat -N REDSOCKS

        # Ignore LANs and some other reserved addresses.
        iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
        iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
        iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
        iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
        iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
        iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
        iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
        iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN

        # Anything else should be redirected to port 12345
        iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 12345
        # Any tcp connection should be redirected.
        iptables -t nat -A OUTPUT -p tcp -j REDSOCKS
        ;;

      stop)
        stop_ssh
        cd /usr/local/redsocks
        if [ -e redsocks.pid ]; then
          kill `cat redsocks.pid`
          rm redsocks.pid
        else
          echo already killed, anyway, I will try killall
          killall -9 redsocks
        fi
        # stop redirection
        iptables -t nat -F OUTPUT
        iptables -t nat -F REDSOCKS
        iptables -t nat -X REDSOCKS
        ;;

      start_ssh)
        start_ssh
        ;;

      stop_ssh)
        stop_ssh
        ;;

      clean_dns)
        # iptables -A INPUT -p udp --sport 53 -m state --state ESTABLISHED -m you-know-who -j DROP -m comment --comment "drop you-know-who dns hijacks"
        echo this function not finished
        ;;

      *)
        echo "Usage: redsocks start|stop|start_ssh|stop_ssh|clean_dns" >&2
        exit 3
        ;;
    esac

    iptables的规则是让所有的TCP包都发送到redsocks监听的端口12345。本脚本还整合了ssh的daemon启动,使用start-stop-daemon来实现。

    启动和关闭:

    将启动关闭脚本中的开头的几个变量配置好

    启动命令:sudo ./redsocks.sh start

    关闭命令:sudo ./redsocks.sh stop

    2011.11.09 / 21 条评论 / 27,778 次点击 / 分类: 所谓技术

  • Linux下时区的相关设置更改

    一般国外的VPS的时区设置都是美国时区。如果要更改时区,可以分为以下几类进行查看和修改。

    查看系统时区:

    date -R

    更改系统时区:

    cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime

    更改MySQL时区:

    在my.ini的[mysqld]下面加上:

    default-time-zone=+8:00

    更改PHP时区:

    1.修改PHP.ini

    date.timezone = Asia/Hong_Kong

    2.修改.htaccess文件

    php_value date.timezone Asia/Hong_Kong

    或者
    SetEnv TZ Asia/Hong_Kong

    3.修改PHP代码

    date_default_timezone_set('Asia/Hong_Kong');

    或者
    ini_set('date.timezone','Asia/Hong_Kong');

    2011.06.15 / 暂无评论 / 670 次点击 / 分类: 所谓技术

  • Ubuntu Server 10.04安装GCC3

    下载GCC3的deb包

    这里选择一个镜像进入,看到有一堆deb包。

    Ubuntu软件包命名遵循下列约定: <1>_<2>-<3>_<4>.deb

    * <1>软件包名称(Package Name):

    * <2>版本(Version Number):

    * <3>修订号(Build Number):

    * <4>平台(Architecture):

    o i386

    o all: 平台无关. 即适用于所有平台.

    例如

    * nano_1.3.10-2_i386.deb

    o 软件包名称: nano

    o 版本: 1.3.10

    o 修订号: 2

    o 平台: i386

    我们下载其中的(64位系统的请用对应的amd64的deb包):

    • cpp-3.4_3.4.6-6ubuntu5_i386.deb
    • g++-3.4_3.4.6-6ubuntu5_i386.deb
    • gcc-3.4_3.4.6-6ubuntu5_i386.deb
    • gcc-3.4-base_3.4.6-6ubuntu5_i386.deb
    • libstdc++6-dev_3.4.6-6ubuntu5_i386.deb

    安装GCC3的deb包

    使用下列命令安装deb包:

    sudo dpkg -i *.deb

    修改为默认使用GCC3

    使用下面命令可以查看当前系统安装和使用的GCC:

    ls /usr/bin/gcc* -ll

    ls /usr/bin/g++* -ll

    ls /usr/bin/cpp* -ll

    使用下面命令修改为默认使用GCC3.4

    ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc

    ln -sf /usr/bin/g++-3.4 /usr/bin/g++

    ln -sf /usr/bin/cpp-3.4 /usr/bin/cpp

    好啦,终于折腾完了。

    2011.04.17 / 暂无评论 / 918 次点击 / 分类: 所谓技术

  • Windows下使用Xmanager连接SSH开启Linux远程桌面的方法

    在Windows下,可以使用“Xmanager Enterprise 3”连接SSH。这个套件包集成了:连接SSH用的“Xshell”;用于文件传送SFTP或FTP的“Xftp”;用于打印服务的“Xlpd”;还有当然就是显示X窗体的“Xmanager”。

    在Windows下使用它,可以很方便地开启窗口,比如:

    xcalc

    可以开启图形化界面的Linux计算器。

    而开启Linux远程桌面的方法,则分不同的图形环境,有不同的命令。

    在KDE环境下,开启远程桌面的命令是:

    startkde

    在gnome环境下,开启远程桌面的命令是:

    gnome-session

    好了,就是这样。

    2010.09.18 / 暂无评论 / 2,372 次点击 / 分类: 所谓技术