VPS杂记

入手VPS好久了,用的是LNMP架构,在Evernote中压了一些笔记,一一贴出来示众~

安装lnmp
注:版本可能有更新,0.7为截至2011/06/03的最新版

wget http://soft.vpser.net/lnmp/lnmp0.7.tar.gz
tar zxvf lnmp0.7.tar.gz
cd lnmp0.7/
./ubuntu.sh

创建虚拟主机

/root/vhost.sh

root账户的使用
平时使用普通账户登录,需要使用root权限的时候用su命令,然后再输入root命令,使用完root权限之后可以用ctrl+D退出权限,继续使用普通账户权限,这样可以防止权限的混乱

安装OpenVPN

wget http://vpsnoc.com/scripts/debian-openvpn.sh
chmod +x debian-openvpn.sh
./debian-openvpn.sh

按照提示安装完成后下载keys.tgz,将其解压到OpenVPN安装目录下的config子目录,然后启动OpenVPN就可以使用了

wordpress的rewrite问题
默认的规则有点小问题,替换为以下的即可:

if  (!-e $request_filename)
{
    rewrite (.*) /index.php;
}

WordPress文件权限

chown -R www.www /blog

Shell 自动补全

1) /etc/passwd

It shows like this

huxuan:x:1002:1002::/home/huxuan:/bin/bash

in format of

Username:Password:User ID (UID):Group ID (GID):User ID Info:Home directory:Command/shell

Make sure the Command/shell is the “/bin/bash” and not the “/bin/sh” which may be the default value.

2) $HOME$/.bashrc or /etc/bash.bashrc
Make sure the code blew is not commented out.

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

3) Reference
http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/

使用密钥自动登录SSH(更新ssh-copy-id)

【更新】
lyxint提醒,发现了ssh-copy-id命令,第二步可以更简单的实现
ssh-copy-id -i ~/.ssh/id_rsa.pub username@hostname
其中username为用户名,hostname为服务器\VPS的IP\地址

1)在本机生成公钥密钥
ssh-keygen -t rsa
一路回车,选择默认路径即可,默认路径为~/.ssh/

2)将本地公钥上传至服务器
cat ~/.ssh/id_rsa.pub|ssh username@hostname ‘sh -c “cat – >>~/.ssh/authorized_keys”‘
其中username为用户名,hostname为服务器\VPS的IP\地址

3)ssh设置文件的几点说明(一般是默认即可)
路径:/etc/ssh/sshd_config
相关行:
PubkeyAuthentication yes #开启公钥验证
#AuthorizedKeysFile %h/.ssh/authorized_keys #公钥的位置,建议使用默认路径

Android平台下FreePascal的交叉编译器

0) Preface
0.1) The Operating System is Ubuntu 10.10
0.2) All the softwares are the latest stable version by April 12, 2011

1) Download the Source of Free Pascal Compiler
The ‘fpc-2.4.2.source.tar.gz’ on http://sourceforge.net/projects/freepascal/files/Source/2.4.2/

2) Install the fpc-source. Just extract it.
The root folder of fpc-source for me is ‘/home/victorhu/fpc-source’

3) Download the Arm-Eabi (Sourcery G++ Lite 2010.09-50 for ARM GNU/Linux)
The ‘IA32 GNU/Linux Installer’ on http://www.codesourcery.com/sgpp/lite/arm/portal/release1600

4) Install the Arm-Eabi (Sourcery G++ Lite 2010.09-50 for ARM GNU/Linux)
The installation need the system shell to be bash not dash which is default for Ubuntu. So
4.1)

sudo dpkg-reconfigure -plow dash

Choose NO to make the bash as the system shell.
4.2) Goto the root folder of Arm-Eabi for me is ‘/home/victorhu/toolchain/’
4.3)

chmod +x arm-2010.09-05-arm-none-linux-gnueabi.bin

4.4)

./arm-2010.09-05-arm-none-linux-gnueabi.bin

5) Get the Cross Compiler
5.1) Goto the root folder of fpc-source
5.2)

make crossall CPU_TARGET=arm OS_TARGET=linux OPT="-dFPC_ARMEL -O- -gl"  CROSSPORT="-O-" CROSSBINDIR=/home/victorhu/toolchain/arm-none-linux-gnueabi/bin

5.3) The ‘ppcrossarm’ under ‘/home/victorhu/fpc-source/compilers/’ is just what we want.
Note: CROSSBINDIR is depend on the folder of Arm-Eabi.

6) Write a Hello Word in Pascal
The path for me is /home/victorhu/hello.pas

Program hello;
begin
writeln('Hello World!');
end.

7) Compile the Hello World in Pascal via CrossCompile Environment.
7.1) Goto the folder contains ‘ppcrossarm’
7.2)

./ppcrossarm -Tlinux -O- -XP -Fu/home/victorhu/fpc-source/rtl/units/arm-linux/ -FD/home/victorhu/toolchain/arm-none-linux-gnueabi/bin /home/victorhu/hello.pas

Note: -Fu is the unit path, -FD is the compiler utilities path.
7.3) The ‘hello’ under ‘/home/victorhu/temp’ is just the what we want (not hello.pas).

8) Test the Crosscompiled Hello World in Android Emulator
8.1) the tools under Android SDK or the ADT of Eclipse is where we can find it.
8.2) Goto the adb root folder under Android SDK .
It’s ‘platform-tools’ under the main root folder of Android SDK now while it’s ‘tools’ before.
8.3) Test whether is device is connected.

./adb devices

If it shows somthing like ‘Emulator-5544 device’ (for me), then it’s right.
8.4) Push the program into Android Emulator.

./adb push ~/hello /data/hello

8.5) Run the program on the Android Emulator.

./adb shell data/hello

If it shows ‘Hello World!’ (the result of the original program), then everything is done now!

9) Reference
9.1) http://alexmogurenko.com/blog/programming/android-building-free-pascal-compiler-for-android/
9.2) http://wiki.freepascal.org/Android_Interface
9.3) http://wiki.freepascal.org/Setup_Cross_Compile_For_ARM

P.S.本文参与“第二届 Google 暑期大学生博客分享大赛 – 2011 Android 成长篇”,感谢大家支持

Linux/Ubuntu 10.04 + Nginx + MySql + php(FastCGI) + Phpmyadmin + WordPress

新到手一台VPS,小试一下感觉不错,发帖留念。
注:
1、本文为完成之后根据回忆写成,如有问题欢迎指正
2、大部分文本操作直接在CLI下通过shell完成

0、准备工作

sudo apt-get update

1、安装并开启Nginx

sudo apt-get intsall nginx
sudo /etc/init.d/nginx start
#此时访问localhost如出现"Welcome to Nginx!"页面则表明安装成功

2、安装mysql(会提示设置数据库密码)

sudo apt-get install mysql-server mysql-client

3、安装phpmyadmin并在虚拟主机根目录下建立软链接

sudo apt-get install phpmyadmin
sudo ln -s /usr/share/phpmyadmin/ /var/www/heaptech.com/ #/var/www/heaptech.com 即为虚拟主机位置

4、安装php

sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl

5、安装spawn-fcgi(控制php5-cgi的)

sudo apt-get install spawn-fcgi

6、在Nginx中配置spawn-fcgi

#在/etc/nginx/fastcgi_params文件最后添加"fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
sudo sed -i '$ i fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' /etc/nginx/fastcgi_params

7、修改php-cgi的配置文件,把cgi.fix_pathinfo设置为1

sudo sed -i '/cgi.fix_pathinfo=/ c cgi.fix_pathinfo=1;' /etc/php5/cgi/php.ini

8、开启fastcgi并设置开机启动

#1)开启
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
#2)设置开机启动,即在/etc/rc.local中添加"/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid"
sudo sed -i '/^exit/ i /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid' /etc/rc.local

9、设置Nginx中虚拟主机配置(最重要的部分)

#1)建立一个虚拟主机配置文件
sudo vim /etc/nginx/sites-available/heaptech.com #文件名任意
#2)添加下方到内容
server {
     listen  80; #WordPress的访问端口(默认80)
     server_name heaptech.com www.heaptech.com; #主机名称,绑定的域名
     root /var/www/heaptech.com;  #虚拟主机根目录

     location / {
         index  index.php;
     }

     location ~ \.php$ {
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         include /etc/nginx/fastcgi_params;
     }
}
#3)软链接至sites-enabled文件夹
sudo ln -s /etc/nginx/sites-available/heaptech.com /etc/nginx/sites-enabled/

10、安装wordpress

cd /var/www/heaptech.com #虚拟主机根目录
sudo wget http://wordpress.org/latest.tar.gz
sudo tar -zxvf latest.tar.gz
sudo mv wordpress/* .
sudo chmod -R 755 wp-content/ #权限问题还有一点不是很明白,欢迎指教(怎样最安全?)
sudo cp wp-config-sample.php wp-config.php
sudo sed -i -e 's/database_name_here/数据库名称/' -e 's/username_here/数据库用户名/' -e 's/password_here/数据库密码/' -e 's/localhost/主机名称/' -e '$ i define(‘WP_POST_REVISIONS’, false);' wp-config.php #需将命令中的中文替换为对应值

11、Last but not least

sudo /etc/init.d/nginx restart
#至此,所有安装工作全部完成
#http://heaptech.com即为blog地址
#http://heaptech.com/phpmyadmin/为phpmyadmin