Tag: Linux

  • 使用密钥自动登录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) [shell]sudo dpkg-reconfigure -plow dash[/shell] 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) [shell]chmod +x arm-2010.09-05-arm-none-linux-gnueabi.bin[/shell]
    4.4) [shell]./arm-2010.09-05-arm-none-linux-gnueabi.bin[/shell]

    5) Get the Cross Compiler
    5.1) Goto the root folder of fpc-source
    5.2) [shell]make crossall CPU_TARGET=arm OS_TARGET=linux OPT=”-dFPC_ARMEL -O- -gl” CROSSPORT=”-O-” CROSSBINDIR=/home/victorhu/toolchain/arm-none-linux-gnueabi/bin[/shell]
    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
    [pascal]
    Program hello;
    begin
    writeln(‘Hello World!’);
    end.
    [/pascal]

    7) Compile the Hello World in Pascal via CrossCompile Environment.
    7.1) Goto the folder contains ‘ppcrossarm’
    7.2) [shell]./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[/shell]
    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.
    [shell]./adb devices[/shell]
    If it shows somthing like ‘Emulator-5544 device’ (for me), then it’s right.
    8.4) Push the program into Android Emulator.
    [shell]./adb push ~/hello /data/hello[/shell]
    8.5) Run the program on the Android Emulator.
    [shell]./adb shell data/hello[/shell]
    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、准备工作
    [shell]sudo apt-get update[/shell]

    1、安装并开启Nginx
    [shell]sudo apt-get intsall nginx
    sudo /etc/init.d/nginx start
    #此时访问localhost如出现”Welcome to Nginx!”页面则表明安装成功[/shell]

    2、安装mysql(会提示设置数据库密码)
    [shell]sudo apt-get install mysql-server mysql-client[/shell]

    3、安装phpmyadmin并在虚拟主机根目录下建立软链接
    [shell]sudo apt-get install phpmyadmin
    sudo ln -s /usr/share/phpmyadmin/ /var/www/heaptech.com/ #/var/www/heaptech.com 即为虚拟主机位置[/shell]

    4、安装php
    [shell]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[/shell]

    5、安装spawn-fcgi(控制php5-cgi的)
    [shell]sudo apt-get install spawn-fcgi[/shell]

    6、在Nginx中配置spawn-fcgi
    [shell]#在/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[/shell]

    7、修改php-cgi的配置文件,把cgi.fix_pathinfo设置为1
    [shell]sudo sed -i ‘/cgi.fix_pathinfo=/ c cgi.fix_pathinfo=1;’ /etc/php5/cgi/php.ini[/shell]

    8、开启fastcgi并设置开机启动
    [shell]#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[/shell]
    [shell]#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[/shell]

    9、设置Nginx中虚拟主机配置(最重要的部分)
    [shell]#1)建立一个虚拟主机配置文件
    sudo vim /etc/nginx/sites-available/heaptech.com #文件名任意[/shell]
    [shell]#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;
    }
    }[/shell]
    [shell]#3)软链接至sites-enabled文件夹
    sudo ln -s /etc/nginx/sites-available/heaptech.com /etc/nginx/sites-enabled/[/shell]

    10、安装wordpress
    [shell]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 #需将命令中的中文替换为对应值[/shell]

    11、Last but not least
    [shell]sudo /etc/init.d/nginx restart
    #至此,所有安装工作全部完成
    #http://heaptech.com即为blog地址
    #http://heaptech.com/phpmyadmin/为phpmyadmin[/shell]