Tofu
Tofu is the best food all around the world!


夢闌珊


狂躁的梦境陡然间结束,激昂的心跳瞬息间平缓,纷叠的记忆呼吸间逝去。
梦已逝,悲欢尽,夜迷朦,君何在?


Opera snapshots checker v3

以前寫的 checker 都是 php 的,早起無事,折騰下,用 shell 重寫個。

  1. #! /bin/bash
  2.  
  3. url=http://snapshot.opera.com/windows/latest
  4. dir=/ls.tl/check
  5.  
  6. win=`curl -s -I $url | grep Location | awk 'BEGIN{ORS=""} {print $2}' | tr -d '\r'`
  7. #eval `echo $win | awk -F '[-|_|/]' '{print "codename="$5, "ver="$6, "build="$7 }'`
  8. eval `echo $win | awk -F '[-|.]' '{ print "ver="$(NF-3)"."$(NF-2), "build="$(NF-1) }'`
  9.  
  10. if [ ! -f $dir/build ]
  11. then
  12.     echo 0 > $dir/build
  13. fi
  14.  
  15. if [ $build != `cat $dir/build | awk 'BEGIN{ORS=""} {print $0}'` ]
  16. then
  17.     echo -n $build > $dir/build
  18.  
  19.     mac=`echo $win | awk 'BEGIN{ORS=""} {sub(/windows/, "mac"); sub(/exe/, "dmg"); print $0}'`
  20.     unix=`echo $win | awk 'BEGIN{ORS=""} {sub(/windows/, "unix"); sub(/Opera.*$/, ""); print $0}'`
  21.  
  22.     echo -n '<h2>Opera '$ver' build '$build'</h2><ul><li><a href="'$win'">Windows</a></li><li><a href="'$mac'">Macintosh</a></li><li><a href="'$unix'">Linux/FreeBSD</a></li></ul>' > index.html
  23.  
  24.     echo -n -e $win"\n"$mac > $dir/dllist
  25.     wget -q -N -P $dir/builds/ -i $dir/dllist
  26.  
  27.     date +%s > $dir/timestamp
  28.     echo -n 1 > $dir/update
  29. else
  30.     date +%s > $dir/timestamp
  31.     echo -n 0 > $dir/update
  32. fi

嗯嗯,只有 php 的三分之一長


update – 2011.09.29
1076 更新时 codename 与 ver 之间插入了 “opera”,考虑到以后还会再有变化的可能性,改为从文件名中匹配版本号

  1. eval `echo $win | awk -F '[-|_|/]' '{print "codename="$5, "ver="$6, "build="$7 }'`

改为

  1. eval `echo $win | awk -F '[-|.]' '{ print "ver="$(NF-3)"."$(NF-2), "build="$(NF-1) }'`


地球不是繞着太陽轉的

地球不是繞著太陽轉的,地球是繞著太陽系重心轉的,太陽系重心並不總是在太陽内部 =.=!

参考:


debian+nginx+mysql+php 折騰手記

最近用 Amazon EC2 搭了不少環境,記之,以備日後查閱。

Debian 6.0.2 / Nginx 1.0.6 / MySQL 5.5.15 / PHP 5.3.8 編譯安裝。

零-初

  1. apt-get update
  2. apt-get upgrade
  3. apt-get install build-essential vim
  4. cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  5. echo '/dev/xvdf   /www    ext4    defaults,nosuid,noexec,nodev 1 2' >> /etc/fstab
  6. mount -a

一-Nginx

1,安裝依賴

  1. apt-get install libpcre3-dev libssl-dev

2,添加用戶

  1. adduser --system --no-create-home --disabled-login --disabled-password --group www

3,編譯安裝

  1. wget http://nginx.org/download/nginx-1.0.6.tar.gz
  2. tar zxvf nginx-1.0.6.tar.gz
  3. cd nginx-1.0.6
  4. ./configure --prefix=/opt/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
  5. make & make install

4,啓動腳本,保存至 /etc/init.d/nginx

  1. #!/bin/sh
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides:          nginx
  5. # Required-Start:    $local_fs $remote_fs $network $syslog
  6. # Required-Stop:     $local_fs $remote_fs $network $syslog
  7. # Default-Start:     2 3 4 5
  8. # Default-Stop:      0 1 6
  9. # Short-Description: starts the nginx web server
  10. # Description:       starts nginx using start-stop-daemon
  11. ### END INIT INFO
  12.  
  13. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  14. DAEMON=/opt/nginx/sbin/nginx
  15. NAME=nginx
  16. DESC=nginx
  17.  
  18. # Include nginx defaults if available
  19. if [ -f /etc/default/nginx ]; then
  20.     . /etc/default/nginx
  21. fi
  22.  
  23. test -x $DAEMON || exit 0
  24.  
  25. set -e
  26.  
  27. . /lib/lsb/init-functions
  28.  
  29. test_nginx_config() {
  30.     if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
  31.         return 0
  32.     else
  33.         $DAEMON -t $DAEMON_OPTS
  34.         return $?
  35.     fi
  36. }
  37.  
  38. case "$1" in
  39.     start)
  40.         echo -n "Starting $DESC: "
  41.         test_nginx_config
  42.         # Check if the ULIMIT is set in /etc/default/nginx
  43.         if [ -n "$ULIMIT" ]; then
  44.             # Set the ulimits
  45.             ulimit $ULIMIT
  46.         fi
  47.         start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
  48.             --exec $DAEMON -- $DAEMON_OPTS || true
  49.         echo "$NAME."
  50.         ;;
  51.  
  52.     stop)
  53.         echo -n "Stopping $DESC: "
  54.         start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
  55.             --exec $DAEMON || true
  56.         echo "$NAME."
  57.         ;;
  58.  
  59.     restart|force-reload)
  60.         echo -n "Restarting $DESC: "
  61.         start-stop-daemon --stop --quiet --pidfile \
  62.             /var/run/$NAME.pid --exec $DAEMON || true
  63.         sleep 1
  64.         test_nginx_config
  65.         start-stop-daemon --start --quiet --pidfile \
  66.             /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
  67.         echo "$NAME."
  68.         ;;
  69.  
  70.     reload)
  71.         echo -n "Reloading $DESC configuration: "
  72.         test_nginx_config
  73.         start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
  74.             --exec $DAEMON || true
  75.         echo "$NAME."
  76.         ;;
  77.  
  78.     configtest|testconfig)
  79.         echo -n "Testing $DESC configuration: "
  80.         if test_nginx_config; then
  81.             echo "$NAME."
  82.         else
  83.             exit $?
  84.         fi
  85.         ;;
  86.  
  87.     status)
  88.         status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
  89.         ;;
  90.     *)
  91.         echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
  92.         exit 1
  93.         ;;
  94. esac
  95.  
  96. exit 0

5,添加自啓動

  1. chmod +x /etc/init.d/nginx
  2. update-rc.d nginx defaults

6,主配置文件,保存至 /opt/nginx/conf/nginx.conf

  1. user  www www;
  2. worker_processes  1;
  3. pid /var/run/nginx.pid;
  4.  
  5. events {
  6.     use     epoll;
  7.     worker_connections  1024;
  8. }
  9.  
  10. http {
  11.     include       mime.types;
  12.     default_type  application/octet-stream;
  13.  
  14.     client_body_buffer_size     1K;
  15.     client_header_buffer_size   2k;
  16.     client_max_body_size        20M;
  17.     large_client_header_buffers 4 8k;
  18.  
  19.     client_body_timeout   30;
  20.     client_header_timeout 30;
  21.     keepalive_timeout     35;
  22.     send_timeout          30;
  23.  
  24.     limit_zone slimits $binary_remote_addr 1m;
  25.     limit_conn slimits 5;
  26.  
  27.     sendfile        on;
  28.     tcp_nopush      on;
  29.     server_tokens   off;
  30.  
  31.     log_format  access  '$remote_addr - [$time_local] - $host "$request" - '
  32.                         '$status - $body_bytes_sent bytes - "$http_referer" - '
  33.                         '"$http_user_agent" - $http_x_forwarded_for';
  34.     access_log  /var/log/nginx/access.log  access;
  35.     error_log   /var/log/nginx/error.log;
  36.  
  37.     fastcgi_connect_timeout 300;
  38.     fastcgi_send_timeout 300;
  39.     fastcgi_read_timeout 300;
  40.     fastcgi_buffer_size 64k;
  41.     fastcgi_buffers 8 64k;
  42.     fastcgi_busy_buffers_size 128k;
  43.     fastcgi_temp_file_write_size 128k;
  44.  
  45.     gzip on;
  46.     gzip_disable "msie6";
  47.     gzip_vary on;
  48.     gzip_comp_level 3;
  49.     gzip_buffers 4 16k;
  50.     gzip_min_length  1k;
  51.     gzip_http_version 1.1;
  52.     gzip_types text/plain text/richtext text/css text/xsd text/xsl application/json application/x-javascript text/xml application/application/xml+rss text/javascript image/x-icon image/svg+xml;
  53.  
  54.     index index.html index.php;
  55.  
  56.     upstream php {
  57.         #server unix:/opt/php/var/run/php-fpm.sock;
  58.         server 127.0.0.1:9000;
  59.     }
  60.  
  61.     include conf.d/*.conf;
  62. }

7,站點配置文件,保存至 /opt/nginx/conf/conf.d/

  1. server {
  2.     server_name ls.tl www.ls.tl;
  3.     root        /www;
  4.  
  5.     if ($host !~ ^(ls.tl|www.ls.tl)$ ) {
  6.         return 444;
  7.     }
  8.  
  9.     if ($request_method !~ ^(GET|HEAD|POST)$ ) {
  10.         return 444;
  11.     }
  12.  
  13.     location = /favicon.ico {
  14.         log_not_found off;
  15.         access_log off;
  16.     }
  17.  
  18.     location = /robots.txt {
  19.         allow all;
  20.         log_not_found off;
  21.         access_log off;
  22.     }
  23.  
  24.     location ~ /\. {
  25.         deny all;
  26.         access_log off;
  27.         log_not_found off;
  28.     }
  29.  
  30.     location ~ \.php$ {
  31.         try_files $uri =404;
  32.         fastcgi_split_path_info ^(.+\.php)(/.+)$;
  33.         fastcgi_index index.php;
  34.         include fastcgi_params;
  35.         fastcgi_pass php;
  36.     }
  37. }

8,FastCGI 設置,保存至 /opt/nginx/conf/fastcgi_params

  1. fastcgi_param  QUERY_STRING       $query_string;
  2. fastcgi_param  REQUEST_METHOD     $request_method;
  3. fastcgi_param  CONTENT_TYPE       $content_type;
  4. fastcgi_param  CONTENT_LENGTH     $content_length;
  5.  
  6. fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
  7. fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
  8. fastcgi_param  REQUEST_URI        $request_uri;
  9. fastcgi_param  DOCUMENT_URI       $document_uri;
  10. fastcgi_param  DOCUMENT_ROOT      $document_root;
  11. fastcgi_param  SERVER_PROTOCOL    $server_protocol;
  12.  
  13. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  14. fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
  15.  
  16. fastcgi_param  REMOTE_ADDR        $remote_addr;
  17. fastcgi_param  REMOTE_PORT        $remote_port;
  18. fastcgi_param  SERVER_ADDR        $server_addr;
  19. fastcgi_param  SERVER_PORT        $server_port;
  20. fastcgi_param  SERVER_NAME        $server_name;
  21.  
  22. # PHP only, required if PHP was built with --enable-force-cgi-redirect
  23. fastcgi_param  REDIRECT_STATUS    200;

9,日誌及站點目錄

  1. mkdir /var/log/nginx
  2. chown -R www:www /www

10,啓動 Nginx

  1. /etc/init.d/nginx start

二-MySQL

1,安裝依賴

  1. apt-get install libncurses5-dev bison cmake

2,添加用戶

  1. adduser --system --disabled-login --home /opt/mysql --group mysql

3,編譯安裝

  1. wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.15.tar.gz/from/http://ftp.jaist.ac.jp/pub/mysql/ -O mysql-5.5.15.tar.gz
  2. tar zxvf mysql-5.5.15.tar.gz
  3. cd mysql-5.5.15
  4. cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DINSTALL_DATADIR=/opt/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1
  5. make & make install
  6. sh scripts/mysql_install_db  --basedir=/opt/mysql  --datadir=/opt/mysql/data  --user=mysql

4,配置文件及啓動腳本,並添加自啓動

  1. cp support-files/my-medium.cnf /etc/mysql/my.cnf
  2. cp support-files/mysql.server /etc/init.d/mysqld
  3. chmod +x /etc/init.d/mysqld
  4. update-rc.d mysqld defaults

5,啓動 MySQL 並設置 root 帳戶密碼

  1. /etc/init.d/mysqld start
  2. /opt/mysql/bin/mysqladmin -u root password 'yourpassword'

6,安裝 phpMyAdmin 3.4.4

  1. wget -O phpMyAdmin-3.4.4-all-languages.tar.xz http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.4/phpMyAdmin-3.4.4-all-languages.tar.xz?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1315241108&use_mirror=cdnetworks-kr-1
  2. tar Jxvf phpMyAdmin-3.4.4-all-languages.tar.xz
  3. mv phpMyAdmin-3.4.4-all-languages/ /www/phpmyadmin

三-PHP

1,安裝依賴

  1. apt-get install autoconf2.13 libxml2-dev libbz2-dev libcurl4-gnutls-dev libjpeg-dev libpng12-dev libxpm-dev libfreetype6-dev libmcrypt-dev libmysqlclient15-dev libxslt1-dev
  2. export PHP_AUTOCONF="/usr/bin/autoconf2.13"

2,編譯安裝

  1. wget http://jp2.php.net/distributions/php-5.3.8.tar.bz2
  2. tar jxvf php-5.3.8.tar.bz2
  3. cd php-5.3.8
  4. ./buildconf --force
  5. ./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-config-file-scan-dir=/opt/php/etc/conf.d --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-curl --with-pear --with-gd  --with-jpeg-dir --with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir --with-mcrypt --with-mhash --with-pdo-mysql --with-openssl --with-xmlrpc --with-xsl --with-bz2 --with-gettext --disable-debug --enable-exif --enable-wddx --enable-zip --enable-bcmath --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-shmop --enable-dba --enable-sysvsem --enable-sysvshm --enable-sysvmsg
  6. make & make install
  7. cp php.ini-production /opt/php/etc/php.ini
  8. cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf

3,配置文件,保存至 /opt/php/etc/php-fpm.conf

  1. pid = run/php-fpm.pid
  2. error_log = log/php-fpm.log
  3. log_level = notice
  4. listen = 127.0.0.1:9000
  5. listen.allowed_clients = 127.0.0.1
  6. listen.owner = www
  7. listen.group = www
  8. listen.mode = 0666
  9. user = www
  10. group = www
  11. pm = dynamic
  12. pm.max_children = 50
  13. pm.start_servers = 5
  14. pm.min_spare_servers = 5
  15. pm.max_spare_servers = 35
  16. pm.max_requests = 500
  17. env[HOSTNAME] = $HOSTNAME
  18. env[PATH] = /usr/local/bin:/usr/bin:/bin
  19. env[TMP] = /tmp
  20. env[TMPDIR] = /tmp
  21. env[TEMP] = /tmp

4,啓動腳本,保存至 /etc/init.d/php-fpm

  1. #!/bin/sh
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides:          php-fpm
  5. # Required-Start:    $remote_fs $network
  6. # Required-Stop:     $remote_fs $network
  7. # Default-Start:     2 3 4 5
  8. # Default-Stop:      0 1 6
  9. # Short-Description: starts php-fpm
  10. ### END INIT INFO
  11.  
  12. set -u
  13.  
  14. DAEMON="PHP FPM"
  15. FPM_CMD=/opt/php/sbin/php-fpm
  16. FPM_CONF=/opt/php/etc/php-fpm.conf
  17. FPM_PID=/opt/php/var/run/php-fpm.pid
  18. TIMEOUT=30
  19.  
  20. FPM_OPTIONS="--fpm-config $FPM_CONF"
  21. SSD_OPTIONS="--oknodo --quiet --pidfile $FPM_PID --exec $FPM_CMD"
  22.  
  23. . /lib/lsb/init-functions
  24.  
  25. #
  26. # Function to check the correctness of the config file
  27. #
  28. do_check()
  29. {
  30.     [ "$1" != "no" ] && $FPM_CMD $FPM_OPTIONS -t 2>&1 | grep -v "\[ERROR\]"
  31.     FPM_ERROR=$($FPM_CMD $FPM_OPTIONS -t 2>&1 | grep "\[ERROR\]")
  32.  
  33.     if [ -n "${FPM_ERROR}" ]; then
  34.         echo "Please fix your configuration file..."
  35.         $FPM_CMD $FPM_OPTIONS -t 2>&1 | grep "\[ERROR\]"
  36.         return 1
  37.     fi
  38.     return 0
  39. }
  40.  
  41. case "$1" in
  42.     start)
  43.     log_begin_msg "Starting $DAEMON..."
  44.     if do_check no ; then
  45.         /sbin/start-stop-daemon --start $SSD_OPTIONS -- $FPM_OPTIONS
  46.         log_end_msg $?
  47.     else
  48.         log_end_msg 1
  49.     fi
  50.     ;;
  51.     stop)
  52.     log_begin_msg "Stopping $DAEMON..."
  53.  
  54.     /sbin/start-stop-daemon --stop $SSD_OPTIONS
  55.     log_end_msg $?
  56.     ;;
  57.     graceful-stop)
  58.     log_begin_msg "Gracefully stopping $DAEMON..."
  59.  
  60.     /sbin/start-stop-daemon --stop --retry QUIT/$TIMEOUT/TERM $SSD_OPTIONS
  61.     log_end_msg $?
  62.     ;;
  63.     restart)
  64.     $0 stop
  65.     $0 start
  66.     ;;
  67.     reload|force-reload)
  68.     log_begin_msg "Reloading $DAEMON..."
  69.  
  70.     /sbin/start-stop-daemon --stop --signal USR2 $SSD_OPTIONS
  71.     log_end_msg $?
  72.     ;;
  73.     *)
  74.     echo "Usage: $0 {start|stop|graceful-stop|restart|reload|force-reload}"
  75.     exit 1
  76.     ;;
  77. esac

5,添加自啓動

  1. chmod +x /etc/init.d/php-fpm
  2. update-rc.d php-fpm defaults

6,安裝 Alternative PHP Cache

  1. /opt/php/bin/pecl install apc

7,APC 配置文件,保存至 /opt/php/etc/conf.d/apc.ini

  1. extension = apc.so
  2. apc.enabled = 1
  3. apc.shm_segments = 1
  4. apc.shm_size = 128M
  5. apc.optimization = 0
  6. apc.num_files_hint = 4096
  7. apc.ttl = 7200
  8. apc.user_ttl = 7200
  9. apc.gc_ttl = 0
  10. apc.cache_by_default = 1
  11. apc.filters = ""
  12. apc.mmap_file_mask = "/tmp/apc.XXXXXX"
  13. apc.slam_defense = 0
  14. apc.file_update_protection = 2
  15. apc.enable_cli = 0
  16. apc.max_file_size = 10M
  17. apc.stat = 1
  18. apc.write_lock = 1
  19. apc.report_autofilter = 0
  20. apc.include_once_override = 0
  21. ;apc.rfc1867 = 0
  22. ;apc.rfc1867_prefix = "upload_"
  23. ;apc.rfc1867_name = "APC_UPLOAD_PROGRESS"
  24. ;apc.rfc1867_freq = 0
  25. apc.localcache = 0
  26. apc.localcache.size = 512
  27. apc.coredump_unmap = 0
  28. apc.stat_ctime = 0

6,啓動 PHP

  1. /etc/init.d/php-fpm start

四-終

  1. reboot

乾淨安裝 Lion 10.7.1 之筆記

  1. 從 AppStore 下載 Lion 10.7.1。按住 Option 點選 purchased 即可重新選擇安裝。
  2. 下載完畢後取消安裝,從 “/Applications/Install Mac OS X Lion.app/Contents/SharedSupport” 中提取安裝鏡像 InstallESD.dmg
  3. 燒製鏡像到 DVD 或恢復鏡像到其他分區/U 盤
  4. 重啓,按 Option 選擇引導設備,按提示安裝即可

走到最後一步時出現若干問題:

  1. 安裝完重啓後出現禁止圖標。Google 一下,大神說這是黑蘋果的典型問題,坑爹呢 =.=!
  2. 再次重裝,安裝程序引導失敗,只是提示“請嘗試再次安裝”。再問 Google 大神,找到一靠譜的答案,參照官方文檔清空 NVRAM (登陸到系統後可使用 nvram 命令讀寫 NVRAM),搞定
  3. 以上兩個問題出現的根本原因是把 Lion 裝到了加密分區上,只能先裝到非加密分區,進入系統後再啓用 FileVault
  4. 系統分區亦不可使用大小寫敏感的,否則諸如 Photoshop 之類的 Adobe 系軟件是無法安裝的。話說正是有了上次使用大小寫敏感文件系統的經驗,才有了這次的系統重灌 =.=!

是以為記。