So Tired !_! 逆水行舟, 不进则退!

26Dec/12

Install Nginx/PHP-FPM on Fedora 17/16, CentOS/RHEL 6.3/5.8

Posted by Nick Xu

I have once written Install nginx, PHP 5.3 and FastCGI on CentOS 5.5, Fedora 13, Red Hat RHEL 5.5/6 guide, but this guide is “updated” version, howto install Nginx with PHP 5.4.10 and PHP-FPM on Fedora 17/16/15/14, CentOS 6.3/6.2/6.1/6/5.8 and Red Hat (RHEL) 6.3/6.2/6.1/6/5.8. PHP-FPM is easier to use and configure than FastCGI and some tests says that PHP-FPM is even much more efficient than FastCGI.

Nginx (engine x) is a robust, small and high performance http server, reverse proxy server and also mail proxy server.

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.

Install Nginx, PHP 5.4.10 and PHP-FPM on Fedora 17/16/15/14, CentOS 6.3/6.2/6.1/6/5.8, Red Hat (RHEL) 6.3/6.2/6.1/6/5.8

1. Change to root user.

sudo -i
## OR ##
su -

2. Install needed repositories

Fedora 17/16/15/14 Remi repository

## Remi Dependency on Fedora 17, 16
rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm 
rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm

## Fedora 17 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-17.rpm

## Fedora 16 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-16.rpm

## Fedora 15 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-15.rpm

## Fedora 14 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-14.rpm

CentOS 6.3/6.2/6.1/6/5.8 and Red Hat (RHEL) 6.3/6.2/6.1/6/5.8 Remi repository

## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm

## CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

## Remi Dependency on CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

## CentOS 5 and Red Hat (RHEL) 5 ## 
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

CentOS 6.3/6.2/6.1/6/5.8 and Red Hat (RHEL) 6.3/6.2/6.1/6/5.8 Nginx repository

Create file /etc/yum.repos.d/nginx.repo and add following content to repo file:
CentOS

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

Red Hat (RHEL)

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1

3. Install Nginx, PHP 5.4.10 and PHP-FPM

Fedora 17/16/15/14, CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8

yum --enablerepo=remi install nginx php php-fpm php-common

CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8

yum --enablerepo=remi,remi-test install nginx php php-fpm php-common

4. Install PHP 5.4.10 modules

  • APC (php-pecl-apc) – APC caches and optimizes PHP intermediate code
  • CLI (php-cli) – Command-line interface for PHP
  • PEAR (php-pear) – PHP Extension and Application Repository framework
  • PDO (php-pdo) – A database access abstraction module for PHP applications
  • MySQL (php-mysql) – A module for PHP applications that use MySQL databases
  • PostgreSQL (php-pgsql) – A PostgreSQL database module for PHP
  • MongoDB (php-pecl-mongo) – PHP MongoDB database driver
  • SQLite (php-sqlite) – Extension for the SQLite V2 Embeddable SQL Database Engine
  • Memcache (php-pecl-memcache) – Extension to work with the Memcached caching daemon
  • Memcached (php-pecl-memcached) – Extension to work with the Memcached caching daemon
  • GD (php-gd) – A module for PHP applications for using the gd graphics library
  • XML (php-xml) – A module for PHP applications which use XML
  • MBString (php-mbstring) – A module for PHP applications which need multi-byte string handling
  • MCrypt (php-mcrypt) – Standard PHP module provides mcrypt library support

Select what you need: APC, CLI, PEAR, PDO, MySQL, PostgreSQL, MongoDB, SQLite, Memcache, Memcached, GD, MBString, MCrypt, XML

More info about PHP APC from PHP APC Configuration and Usage Tips and Tricks

Fedora 17/16/15/14

yum --enablerepo=remi install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8

yum --enablerepo=remi,remi-test install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

5. Stop httpd (Apache) server, Start Nginx HTTP server and PHP-FPM (FastCGI Process Manager)

Stop httpd (Apache)

/etc/init.d/httpd stop
## OR ##
service httpd stop

Start Nginx

/etc/init.d/nginx start ## use restart after update
## OR ##
service nginx start ## use restart after update

Start PHP-FPM

/etc/init.d/php-fpm start ## use restart after update
## OR ##
service php-fpm start ## use restart after update

6. Autostart Nginx and PHP-FPM on boot, also prevent httpd (Apache) autostarting on boot

Prevent httpd (Apache) autostarting on boot

chkconfig httpd off

Autostart Nginx on boot

chkconfig --add nginx
chkconfig --levels 235 nginx on

Autostart PHP-FPM on boot

chkconfig --add php-fpm
chkconfig --levels 235 php-fpm on

7. Configure Nginx and PHP-FPM

Create directory layout for your site

I use here testsite.local site, but this could of course be your real site, like www.if-not-true-then-false.com.

## public_html directory and logs directory ##
mkdir -p /srv/www/testsite.local/public_html
mkdir /srv/www/testsite.local/logs
chown -R apache:apache /srv/www/testsite.local

Alternative setup to add logs under /var/log directory.

## public_html directory and logs directory ##
mkdir -p /srv/www/testsite.local/public_html
mkdir -p /var/log/nginx/testsite.local
chown -R apache:apache /srv/www/testsite.local
chown -R nginx:nginx /var/log/nginx

Note: I use apache user and group here, because PHP-FPM runs as apache default (apache choosed to be able to access some dir as httpd). If you use some other user on your php-fpm conf then change this accordingly.

Create and configure virtual host directories under /etc/nginx

mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled

Add following lines to /etc/nginx/nginx.conf file, after “include /etc/nginx/conf.d/*.conf” line (inside http block).

## Load virtual host conf files. ##
include /etc/nginx/sites-enabled/*;

Create testsite.local virtual host file

Add following content to /etc/nginx/sites-available/testsite.local file. This is very basic virtual host config.

server {
    server_name testsite.local;
    access_log /srv/www/testsite.local/logs/access.log;
    error_log /srv/www/testsite.local/logs/error.log;
    root /srv/www/testsite.local/public_html;

    location / {
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/testsite.local/public_html$fastcgi_script_name;
    }
}

Link your virtual host to /etc/nginx/sites-enabled

cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/testsite.local
service nginx restart

Add your testsite.local “domain” to /etc/hosts file

/etc/hosts file Nginx on same machine
127.0.0.1 … row should look like example following:

127.0.0.1               localhost.localdomain localhost testsite.local

And if you use another machine where you are running your Nginx server, then add it’s public IP as following:

10.0.2.19               wordpress

Note: This is just very simple basic configuration, but if you want configure and optimize Nginx and PHP-FPM more then check following guide, Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks

8. Test your Nginx and PHP-FPM setup

Create /srv/www/testsite.local/public_html/index.php file with following content:

<?php 
    phpinfo();
?>

Access following address, with your browser. http://testsite.local/
Nginx PHP 5.4.4 PHP-FPM

Enable Remote Connection to Nginx Web Server (Open Port 80 on Iptables Firewall)

1. Edit /etc/sysconfig/iptables file:

nano -w /etc/sysconfig/iptables

2. Add following line before COMMIT:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

3. Restart Iptables Firewall:

service iptables restart
## OR ##
/etc/init.d/iptables restart

4. Test remote connection

Access following address, with your browser. http://your.domain/

Tagged as: , , No Comments
26Dec/12

redhat 6 配置 yum 源的两种方法

Posted by Nick Xu

由于 redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,重启安装,再配置其他源.

本文包括配置本地源及第三方源。第三方源包括:网易,epel,repoforge ,rpmfusion 以下为详细过程:

1.删除redhat原有的yum
rpm -aq|grep yum|xargs rpm -e --nodeps

2.下载yum安装文件

注意,如果下载时找不到文件,就登录到:http://mirrors.163.com/centos/6/os/x86_64/ 上查找相应的文件。然后再下载。

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.27-14.el6.centos.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-14.1.el6.x86_64.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm

3.进行安装yum

rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.2-14.1.el6.x86_64.rpm
rpm -ivh yum-3.2.27-14.el6.centos.noarch.rpm um-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm
注意最后两个包必需同时安装,否则会相互依赖
----------配置网易源
4.更新repo文件

mv /etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/rhel-debuginfo.repo.repo.bak

vi /etc/yum.repos.d/rhel-debuginfo.repo

内容为:

[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.163.com/centos/6.0/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.163.com/centos/6.0/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#packages used/produced in the build but not released
#[addons]
#name=CentOS-$releasever - Addons
#baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/
#gpgcheck=1
#gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.163.com/centos/6.0/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.163.com/centos/6.0/centosplus/$basearch/
gpgcheck=1
enabled=0

5、yum clean all

6、yum install vim #测试一下可不可以用

--配置epel源

Fedora EPEL 下载:http://mirrors.fedoraproject.org/publiclist/EPEL/

EPEL 下载地址:http://download.fedora.redhat.com/pub/epel/

以上网直可能不 可用,此时,登录到下面的地址:

https://fedoraproject.org/wiki/EPEL

查找:“How can I use these extra packages?”

在该条目内可以找到: The newest version of 'epel-release' for (版本)

下载epel包。再执行安装。

请针对不同的版本下载相应的包。

 

--配置repoforge源

rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
yum makecache

--配置rpmfusion源

RPMFusion官网:http://rpmfusion.org/

Fedora 13, 14 and 15:

su -c ’yum localinstall –nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.

noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm’

RHEL 6/CentOS 6 :

su -c ’rpm -Uvh http://download1.rpmfusion.org/free/el/updates/testing/6/i386/rpmfusion-free-release-6-0.1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/testing/6/i386/rpmfusion-nonfree-release-6-0.1.noarch.rpm’


【设置本地镜像作为yum源】

1、mkdir /mnt/cdrom

2   mount /dev/cdrom /mnt/cdrom  #挂着镜像,光盘

3  mkdir /home/redhat-iso

4  cp -Rf /mnt/cdrom/* /home/redhat-iso   #将光盘内的内容copy到某个路径下

5  vi /etc/yum.repos.d/rhel-debuginfo.repo  #编辑repo文件

添加一下内容:

[rhel_6_iso]
name=local iso
baseurl=file:///home/redhat-iso/
gpgcheck=1
gpgkey=file:///home/redhat-iso/RPM-GPG-KEY-CentOS-6  #该处的gpgkey文件应该改成iso镜像中的文件名

 

 

【关于yum的一点资料】

 

一、YUM是什么
YUM = Yellow dog Updater, Modified
主要功能是更方便的添加/删除/更新RPM包.
它能自动解决包的倚赖性问题.
它能便于管理大量系统的更新问题
二、 YUM特点
*可以同时配置多个资源库(Repository)
*简洁的配置文件(/etc/YUM.conf,/etc/YUM.repos.d 下的文件)
*自动解决增加或删除rpm包时遇到的倚赖性问题
*使用方便
*保持与RPM数据库的一致性

三、 YUM安装
Centos/RHEL
1. #rpm -ivh yum-2.4.3-4.el4.centos.noarch.rpm

四、YUM配置
YUM的配置文件
YUM的一切配置信息都储存在一个叫YUM.conf的配置文件中,通常位于/etc目 录下,这是整个YUM系统的重中之重,所以有必要详细介绍。下面是一个从网上找来的YUM.con文件,让我们以此为例,进行说明。

[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
retries=1[base]
name=Fedora Core $releasever - $basearch - Base
baseurl=http://download.atrpms.net/mirrors/fedoracore/$releasever/$basearch/os
http://rpmfind.net/linux/fedora/cor...er/$basearch/os
http://mirror.clarkson.edu/pub/dist...er/$basearch/os

[updates-released]
name=Fedora Core $releasever - $basearch - Released Updates
baseurl=http://download.atrpms.net/mirrors/fedoracore/updates/$releasever/$basearch
http://redhat.linux.ee/pub/fedora/l...sever/$basearch
http://fr2.rpmfind.net/linux/fedora...sever/$basearch

[Fedora.us]
name=Fedora.us - $basearch - Extras
baseurl=http://fedora.linux.duke.edu/fedorax86_64/fedora.us/$releasever/$basearch/RPMS.stable

[Dag Wieers]
name=Dag RPM Repository for Fedora Core
baseurl=http://apt.sw.be/fedora/$releasever/en/$basearch/dag

[Livna]
Name=Livna RPM, Fedora Core $releasever - $basearch
baseurl=http://rpm.livna.org/fedora/$releasever/$basearch/RPMS.stable

[freshrpms]
name=FreshRPMs
baseurl=http://ayo.freshrpms.net/fedora/linux/$releasever/$basearch/freshrpms/
http://ftp.us2.freshrpms.net/linux/...arch/freshrpms/

第一部分(这是YUM的全局性设置。默认一般不必改动。)

[main]

cachedir:YUM缓存的目录,YUM在此存储下载的rpm包和数据库,一般是/var/cache/YUM。
debuglevel:除错级别,0-10,默认是2。
logfile:YUM的日志文件,默认是/var/log/YUM.log。
pkgpolicy:包的策略。一共有两个选项,newest和last,这个作用是如果你设置了多个repository,而同一软件在不同的repository中同时存在,YUM应该安装哪一个,如果是newest,则YUM会安装最新的那个版本。如果是last,则YUM会将服务器id以字母表排序,并选择最后的那个服务器上的软件安装。一般都是选newest。
distroverpkg:指定一个软件包,YUM会根据这个包判断你的发行版本,默认是redhat-release,也可以是安装的任何针对自己发行版的rpm包。
exactarch,有两个选项1和0,代表是否只升级和你安装软件包cpu体系一致的包,如果设为1,则如你安装了一个i386的rpm,则YUM不会用1686的包来升级。
retries,网络连接发生错误后的重试次数,如果设为0,则会无限重试。
tolerent,也有1和0两个选项,表示YUM是否容忍命令行发生与软件包有关的错误,比如你要安装1,2,3三个包,而其中3此前已经安装了,如果你设为1,则YUM不会出现错误信息。默认是0。

除了上述之外,还有一些可以添加的选项,如

exclude=,排除某些软件在升级名单之外,可以用通配符,列表中各个项目要用空格隔开,这个对于安装了诸如美化包,中文补丁的朋友特别有用。
gpgchkeck= 有1和0两个选择,分别代表是否是否进行gpg校验,如果没有这一项,默认好像也是检查的。

第二部分:

配置repository服务器了,这是最令人激动的,有了好的repository,就如家门口开了大卖场,要什么东西稍微跑跑腿就行,对了这还是个免费的大卖场。
所有服务器设置都应该遵循如下格式:

1. [serverid]
2. name=Some name for this server
3. baseurl=url://path/to/repository/

其中serverid是用于区别各个不同的repository,必须有一个独一无二的名称。
name,是对repository的描述,支持像$releasever $basearch这样的变量;
baseurl是服务器设置中最重要的部分,只有设置正确,才能从上面获取软件。它的格式是:

1. baseurl=url://server1/path/to/repository/
2. url://server2/path/to/repository/
3. url://server3/path/to/repository/

其中url支持的协议有 http:// ftp:// file://三种。baseurl后可以跟多个url,你可以自己改为速度比较快的镜像站,但baseurl只能有一个,也就是说不能像如下格式:

1. baseurl=url://server1/path/to/repository/
2. baseurl=url://server2/path/to/repository/
3. baseurl=url://server3/path/to/repository/

其中url指向的目录必须是这个repository header目录的上一级,它也支持$releasever $basearch这样的变量。
url之后可以加上多个选项,如gpgcheck、exclude、failovermethod等,比如:

1. [updates-released]
2. name=Fedora Core $releasever - $basearch - Released Updates
3. baseurl=http://download.atrpms.net/mirrors/fedoracore/updates/$releasever/$basearch
4. http://redhat.linux.ee/pub/fedora/linux/core/updates/$releasever/$basearch
5. http://fr2.rpmfind.net/linux/fedora/core/updates/$releasever/$basearch
6. gpgcheck=1
7. exclude=gaim
8. failovermethod=priority

其中gpgcheck,exclude的含义和[main]部分相同,但只对此服务器起作用,failovermethode 有两个选项roundrobin和priority,意思分别是有多个url可供选择时,YUM选择的次序,roundrobin是随机选择,如果连接失 败则使用下一个,依次循环,priority则根据url的次序从第一个开始。如果不指明,默认是roundrobin。

几个变量

$releasever,发行版的版本,从[main]部分的distroverpkg获取,如果没有,则根据redhat-release包进行判断。
$arch,cpu体系,如i686,athlon等
$basearch,cpu的基本体系组,如i686和athlon同属i386,alpha和alphaev6同属alpha。

对YUM.conf设定完成,我们就可以好好体验YUM带来的方便了。

五、RHEL/CENTOS的YUM源

1、修改配置文件

2、导入GPG KEY

导入每个reposity的GPG key,前面说过,YUM可以使用gpg对包进行校验,确保下载包的完整性,所以我们先要到各个repository站点找到gpg key,一般都会放在首页的醒目位置,一些名字诸如 RPM-GPG-KEY.txt之类的纯文本文件,把它们下载,然后用rpm --import xxx.txt命令将它们导入,最好把发行版自带GPG-KEY也导入。rpm --import /usr/share/doc/redhat-release-*/RPM-GPG-KEY 官方软件升级用的上。

六、扩展你的rpm包

1、rpmforge

Centos/RHEL默认的yum软件仓库非常有限,仅仅限于发行版本那几张盘里面的常规包和一些软件包的更新,利用RpmForge,可以增加非常多的第三方rpm软件包。

获取

http://dag.wieers.com/rpm/packages/rpmforge-release/

找到与系统平台架构匹配的rpmforge包安装之即可。安装完后.默认会在系统的/etc/yum.repos.d/下新增两个文件,mirrors-rpmforge和rpmforge.repo

安装

1. # rpm -ivh rpmforge-release-0.3.6-1.el4.rf.i386.rpm
2. # rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

2、加速YUM更新速度

安装YUM的fast mirror插件,可以加快 CentOS/RHEL YUM的速度和提高稳定性,效果显著。

centos5

1. #yum -y install yum-fastestmirror

centos4

1. yum -y install yum-plugin-fastestmirror
七、 YUM使用

注:当第一次使用YUM或YUM资源库有更新时,YUM会自动下载所有所需的headers放置于/var/cache/YUM目录下,所需时间可能较长.

系统更新(更新所有可以升级的rpm包,包括kernel)

1. #YUM -y update

每天定期执行系统更新

1. #chkconfig YUM on
2. #service YUM start

*rpm包的更新

检查可更新的rpm包

1. #YUM check-update

更新所有的rpm包

1. #YUM update

更新指定的rpm包,如更新kernel和kernel source

1. #YUM update kernel kernel-source

大规模的版本升级,与YUM update不同的是,连旧的淘汰的包也升级

1. #YUM upgrade

*rpm包的安装和删除

安装rpm包,如xmms-mp3

1. #YUM install xmms-mp3

删除rpm包,包括与该包有倚赖性的包

1. #YUM remove licq

注:同时会提示删除licq-gnome,licq-qt,licq-text

*YUM暂存(/var/cache/YUM/)的相关参数

清除暂存中rpm包文件

1. #YUM clean packages

清除暂存中rpm头文件

1. #YUM clean headers

清除暂存中旧的rpm头文件

1. #YUM clean oldheaders

清除暂存中旧的rpm头文件和包文件

1. #YUM clean 或#YUM clean all

注:相当于YUM clean packages + YUM clean oldheaders

*rpm包列表

列出资源库中所有可以安装或更新的rpm包

1. #YUM list

列出资源库中特定的可以安装或更新以及已经安装的rpm包

1. #YUM list mozilla
2. #YUM list mozilla*

注:可以在rpm包名中使用匹配符,如列出所有以mozilla开头的rpm包

列出资源库中所有可以更新的rpm包

1. #YUM list updates

列出已经安装的所有的rpm包

1. #YUM list installed

列出已经安装的但是不包含在资源库中的rpm包

1. #YUM list extras

注:通过其它网站下载安装的rpm包

*rpm包信息显示(info参数同list)

列出资源库中所有可以安装或更新的rpm包的信息

1. #YUM info

列出资源库中特定的可以安装或更新以及已经安装的rpm包的信息

1. #YUM info mozilla
2. #YUM info mozilla*

注:可以在rpm包名中使用匹配符,如列出所有以mozilla开头的rpm包的信息

列出资源库中所有可以更新的rpm包的信息

1. #YUM info updates

列出已经安装的所有的rpm包的信息

1. #YUM info installed

列出已经安装的但是不包含在资源库中的rpm包的信息

1. #YUM info extras

注:通过其它网站下载安装的rpm包的信息

*搜索rpm包

搜索匹配特定字符的rpm包

1. #YUM search mozilla

注:在rpm包名,包描述等中搜索

搜索有包含特定文件名的rpm包

1. #YUM provides realplay

八、YUM常用问题解决

1、如果网速慢的话可以通过增加YUM的超时时间,这样就不会总是因为超时而退出。

1. #vi /etc/YUM.conf
2. #加上这么一句
3. timeout=120

2、YUM Existing lock错误的解决办法

如果系统启动的时候, YUM出现Existing lock /var/run/YUM.pid: another copy is running as pid 3380. Aborting.可以用下面的办法解决:

方法一

1. etc/init.d/YUM-updatesd stop

方法二

1. #rm -f /var/run/YUM.pid

主要原因就是YUM在自动更新,只要关掉它就可以了。

18Dec/12

nginx 反向代理做cache配置

Posted by Nick Xu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#user  nobody;
worker_processes  1;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    #sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    #keepalive_timeout  65;
    #gzip  on;
 
    server_names_hash_bucket_size 128;     #指定服务器名称哈希表的框大小
 
    client_header_buffer_size 32k;
    large_client_header_buffers 4 128k;     #以上两个是设定客户端请求的Header头缓冲区大小,对于cookie内容较大的请求,应增大改值。(400或414错误)
    client_max_body_size 8m;                #允许客户端请求的最大单文件字节数
    client_body_buffer_size 32k;            #缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户
 
    proxy_connect_timeout 600;              #nginx跟后端服务器连接超时时间(代理连接超时)
    proxy_read_timeout    600;              #连接成功后,后端服务器响应时间(代理接收超时)
    proxy_send_timeout    600;              #后端服务器数据回传时间(代理发送超时)
    proxy_buffer_size     32k;              #设置代理服务器(nginx)保存用户头信息的缓冲区大小
    proxy_buffers         4 32k;            #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
    proxy_busy_buffers_size  64k;           #高负荷下缓冲大小(proxy_buffers*2)
    proxy_temp_file_write_size  1024m;      #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘
    proxy_ignore_client_abort on;           #不允许代理端主动关闭连接
 
    sendfile           on;
    tcp_nopush         on;
    keepalive_timeout      65;
    tcp_nodelay     on;
    gzip         on;
    gzip_min_length      1k;
    gzip_buffers         4 16k;
    gzip_http_version     1.0;
    gzip_proxied         any;  #前端是squid的情况下要加此参数,否则squid上不缓存gzip文件
    gzip_comp_level     2;
    gzip_types        text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
 
    server_tokens off;
 
    #注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区
    proxy_temp_path   /cache/proxy_temp_path;
    #设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为30GB。
    proxy_cache_path  /cache/proxy_cache_path levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
 
    server {
        listen       8012;
        server_name  localhost.net;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   /var/www/nginx;
            index  index.html index.htm;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            proxy_pass  http://127.0.0.1:8011;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #include        fastcgi_params;
        }
 
    #扩展名以.gif、.jpg、.css等结尾的静态文件缓存。
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|mp3|mp4|flv|f4v|wmv|wma|mov)$
 
        {
            #如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
 
        proxy_cache cache_one;                   #进行缓存,使用Web缓存区cache_one
        proxy_cache_valid 200 304 12h;           #对不同的HTTP状态码设置不同的缓存时间
        proxy_cache_valid 301 302 1m;
        proxy_cache_valid any 1m;
        proxy_cache_key $host$uri$is_args$args;  #以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内
        proxy_set_header  Host $host;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Accept-Encoding "none";  #设定proxy_set_header Accept-Encoding '';
                                                  #      (或是后台服务器关闭gzip),这样这台机器才
                                                  #       不会缓存被压缩的文件,造成乱码
        #proxy_set_header Accept-Encoding ""; #这个也可
        proxy_ignore_headers "Cache-Control" "Expires"; #这段配置加上后,proxy_cache就能支持后台设定的expires。
        #proxy_pass http://127.0.0.1:8011; #反向代理
        root   /var/www/nginx;
        expires  1h;
 
        }
    #设置只允许指定的IP或IP段才可以清除URL缓存。
        location ~ /purge(/.*)  {
            allow            127.0.0.1;
            allow            192.168.0.0/255;
            allow             all;
            proxy_cache_purge cache_one $host$1$is_args$args;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    #测试不同域名绑定同一端口
    server {
        listen       8012;
        server_name  localhost.com;
        location / {
            root   /var/www/nginx2;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            proxy_pass  http://127.0.0.1:8011;
        }
    }
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;
 
    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_timeout  5m;
 
    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}
Filed under: Linux, Mac OS No Comments
14Dec/12

在XenServer 6.0中设置自动启动虚拟机

Posted by Nick Xu

在XenServer的较早前版本(6.0以前)中,启动XenServer时,可以选择自动启动在其中安装的虚拟机。这个功能在XenServer 6.0中被Citrix取消了,原因是会干扰到XenServer的HA(高可用性)和Failover(故障转移)功能的兼容性。但是,如果只运行一个XenServer,这个功能还是非常好的。

在XenServer 6.0中,自动启动虚拟机仍然是可以办到的。这需要在“Pool Level”上开启自启动功能,并且,在需要自启动的虚拟机上使用命令行进行设置。

一、获取Pool的UUID

在控制台的命令行输入如下命令并按回车:
xe pool-list

随后出现的结果类似于如下:
uuid ( RO)                : b99e3b3f-ea7a-9484-4827-87271b4b016b
name-label ( RW): TestPool
name-description ( RW):
master ( RO): 74fc086b-8c89-4918-b69e-369fcb19847d
default-SR ( RW): bebb142a-d986-acac-d4f4-636de937d28b

以上,“b99e3b3f-ea7a-9484-4827-87271b4b016b”就是Pool的UUID

二、设置Pool的自启动

复制此UUID,再输入如下命令并按回车:
xe pool-param-set uuid=b99e3b3f-ea7a-9484-4827-87271b4b016b other-config:auto_poweron=true
三、获取需要设置为自启动的虚拟机的UUID

以名称为“W2K08”的虚拟机为例,输入如下命令并按回车:
xe vm-list name-label="W2K08"

出现结果类似于如下:

uuid ( RO)           : 5ac81c4e-3d4c-bd70-355e-d1a1c2d7716d
name-label ( RW): W2K08
power-state ( RO): running

由上,可知名称为“W2K08”的虚拟机的UUID是:5ac81c4e-3d4c-bd70-355e-d1a1c2d7716d
【说明】
如果要得到简介的结果(即只希望输出UUD),可以使用如下命令:
xe vm-list name-label="W2K08" params=uuid --minimal

四、设置虚拟机的自启动

从上述“三”中的输出结果中复制虚拟机的UUID,再输入如下命令并按回车:
xe vm-param-set uuid=5ac81c4e-3d4c-bd70-355e-d1a1c2d7716d other-config:auto_poweron=true

经过如上的4步,就完成了在XenServer 6.0中虚拟机的自启动设置。

Filed under: Linux, 其它 No Comments
11Dec/12

mac下用openxenmanager管理xenserver

Posted by Nick Xu

IMPORTANT on last commits you don't need patch tightvnc, only install and copy to openxenmanager directory

This install was tested on Snow Leopard, and the tightvnc console worked.

Download the latest svn version:

svn co https://openxenmanager.svn.sourceforge.net/svnroot/openxenmanager openxenmanager

For the console you need to:

Install Macports. Then use port to install tightvnc:

port fetch tightvnc
port patch tightvnc
port build tightvnc

cp /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_x11_tightvnc/work/vnc_unixsrc/vncviewer/vncviewer openxenmanager/trunk

You may need to install pygtk via MacPorts?.

port -v install python25
port -v install python_select
python_select python25
port -v install py25-gtk

explained in:

http://www.php-architect.com/blog/2009/02/25/installing-python-pygtk-on-mac-osx/

Start the app:

cd openxenmanager/trunk
python window.py

If you have installed MacOSX native python interpreter (/usr/bin/python) together with the MacPorts? version, the command above will probably fail with a "No module named pygtk" error because it will attempt to load window.py using /usr/bin/python instead of theMacPorts? version. In that case you shall use the full path to your MacPorts? python installation, i.e.:

/opt/local/bin/python window.py
Filed under: Mac OS No Comments
9Dec/12

基于opencv的测量实验结果

Posted by Nick Xu

 

画出来的框只是为了方便查看和调试,实际结果是背后那一堆字符

物体左上角的位置在15.75mm左右宽度,右上角的位置在104.81mm左右的宽度

物体左上角的位置在7.12mm左右高度,左上角的位置在56.17mm左右高度

实际偏差还没有具体的比对,暂时没有误差数据出来...

Filed under: opencv, Python, 其它 No Comments
1Dec/12

Mac OS X OpenCV Port

Posted by Nick Xu

This page is devoted to information specific to the OS X build of OpenCV. Things are changing quickly due to recent work by Willow Garage, and the transition to the CMake build system.

There are a number of ways to install OpenCV on OS X. The most straightforward way is to download the latest version of OpenCV (currently 2.2.0), and use cmake as described in the general InstallGuide and below at number 2.

Each of the numbers below are separate ways to install OpenCV for Mac OS X.

 

0. Getting a precompiled version ( sorry, but this is only for OpenCV 1.2 and only valid only for i386, Not 2.x - anyone know how to build a Private Framework for 2.x ? ):

see: http://www.ient.rwth-aachen.de/cms/software/opencv/

 

wget http://www.ient.rwth-aachen.de/~asbach/OpenCV-Private-Framework-1.2.dmg
open OpenCV-Private-Framework-1.2.dmg
cd /Volumes/OpenCV\ Private\ Framework/
cp -R OpenCV.framework/ /Library/Frameworks/OpenCV.framework

 

1. Build via MacPorts

For Snow Leopard users, you can build OpenCV 2.1.0 and above via MacPorts as a 64-bit library with support of QTKit video I/O and Cocoa GUI.

Assuming MacPorts installed, first use:

 

sudo port selfupdate

to update the MacPorts base and the port tree. Then, simply:

 

sudo port install opencv

to build OpenCV 2.1.0 in 64-bit.

If you encounter errors, try installing its dependents with +universal whenever possible.

 

sudo port -v install opencv +python26

to use with Python 2.6 bindings or

 

sudo port -v install opencv +python27

to use with Python 2.7 bindings

By default OpenCV is installed to /opt/local/ according to MacPorts conventions. The opencv_xxxx utilities are located in /opt/local/bin/, the dynamic libraries in /opt/local/lib/ and the header files in/opt/local/include/opencv/.

To use the libraries, include the required files with standard includes. For example:

 

#include <cv.h>
#include <highgui.h>

If you use Xcode, the instructions are similar to the ones in method 3. It only differs that /usr/local becomes /opt/local.

 

1.1 Build via HomeBrew

For users that have and like homebrew:

 

sudo brew update
sudo brew install opencv

If you need the 32bit version, change the last command to sudo brew install opencv --build32

OLD METHOD:

Assuming HomeBrew ( aka 'brew') is installed first:

 

sudo brew update
sudo brew install lame       ( for libmp3lame that opencv needs)
sudo brew install libpng     ( which theora needs -  part of the ffmpeg package )
sudo brew link    libpng     ( needed if theora/ffmpeg can't find it)
sudo brew install ffmpeg     ( for libavcodec and related stuff that opencv needs)
sudo brew install python     ( the system python is not good enough)
sudo brew install doxygen    ( if you compile opencv yourself, you'll want this)
sudo chmod 000 /System/Library/Frameworks/Python.framework/
sudo chmod 000 /Library/Frameworks/Python.framework/
   ( disable system python/s temporarily just for the next step)

either:
sudo brew install opencv     ( finally! - this will probably bork? )

or:
svn co https://code.ros.org/svn/opencv/trunk/opencv cd opencv ( or get sources by hand)
cd opencv
ccmake .   ( disable everything you can that's not important, maybe you'll figure out how get it to build? don't forget to press 't' for advanced mode.  Edit the settings as you desire, then 'c' and 'g' )
cmake .
make -j8
make install ( optional )

sudo chmod 755 /System/Library/Frameworks/Python.framework/
sudo chmod 755 /Library/Frameworks/Python.framework/
   ( put it back how it was )

By default OpenCV is installed to /opt/homebrew/ 

* see also: 

   http://www.tsd.net.au/blog/opencv-python-bindings-macports

   http://wiki.nuigroup.com/Installing_OpenCV_on_Mac_OS_X

   https://github.com/mxcl/homebrew/issues/issue/1792

See MacPort install for any other details, just replace /opt/local with /opt/homebrew

 

2. Build from source using the CMake build system (new)

The GNU autotools methods (configure, make, make install) are being obsoleted. OpenCV has now switched to the CMake build system.

 

Getting the source code

Make sure you have subversion installed (built-in since Snow Leopard). If MacPorts is your primary package manager, use:

 

sudo port install subversion

if not using MacPorts or it gives an error, try:

 

sudo fink install svn-ssl

Make sure you have cmake installed. This can also be installed with MacPorts:

 

sudo port install cmake

Check out the source code into a clean directory and cd into the source directory after the download is complete:

 

# previous URL
# svn co https://code.ros.org/svn/opencv/trunk/opencv ; cd opencv
# current (April 2012) URL
svn co http://code.opencv.org/svn/opencv/trunk/opencv ; cd opencv
  • Note: There's a "atomic bomb commit" at r3060 which largely changed the OpenCV directory structure. If you wish to work with the older structure, you can specify an earlier checkout revision:

 

# previous URL
# svn co https://code.ros.org/svn/opencv/trunk/opencv -r 3059 ; cd opencv
# current (April 2012) URL
svn co http://code.opencv.org/svn/opencv/trunk/opencv -r 3059 ; cd opencv

 

Use CMake to build

To use CMake to generate Unix Makefiles, type:

 

# make a separate directory for building
mkdir build
cd build
cmake -G "Unix Makefiles" ..

You can specify many configuration options in the above command. For examples:

  • -D BUILD_TESTS=OFF -> if you don't want to build tests.
  • -D BUILD_NEW_PYTHON_SUPPORT=OFF -> if you don't want the Python interface support.
  • -D WITH_CARBON=ON -> (mainly for Leopard and below) if you want to use Carbon for UI instead of Cocoa (since r2909).
  • -D WITH_QUICKTIME=ON -> (mainly for Leopard and below) if you want to use QuickTime for Video I/O insted of QTKit (since r2924). If you're using Snow Leopard and do need Carbon and QuickTime, you must also specify -D CMAKE_OSX_ARCHITECTURES=i386-D CMAKE_C_FLAGS=-m32 and -D CMAKE_CXX_FLAGS=-m32.
  • An example configuration of OpenCV 2.2.0 on Mac OSX 10.6 without TPP or Eigen or Carbon is shown at http://imagebin.ca/view/A2uboY.html.

Finally, follow the usual "make, make install" method:

 

make -j8
sudo make install

append a new line "export PYTHONPATH=/usr/local/lib/python2.7/site-packages/" to ~/.profile:


If you need the CMake GUI for other options, replace cmake with ccmake. If the arrow keys fail, you can use the following commands instead:

 

ctrl + N : next option
ctrl + P : previous options
ctrl + D : down one page
ctrl + U : up one page

To compile with Intel Threading Building blocks, use ccmake (the Cmake GUI) to specify the lib and include paths to your installation of TBB.

After setting the build options, hit 'c' to configure. Hit 'g' to generate the config file and exit ccmake. Then execute the "make, make install" commands above.

 

if got  “Segmentation fault” during “import cv”:

In ccmake(ccmake -G "Unix Makefiles" .), toggle to the advanced mode pressing t.

change PYTHON_LIBRARY value to
/opt/local/lib/libpython2.7.dylib

and PYTHON_INCLUDE_DIR to
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7

Note that the specific path depends, of course, what version of Python you are using (2.6 or 2.7 etc.). Also, if you are using the system Python, instead of MacPorts (which is in /opt), then you probably want PYTHON_LIBRARY to be /usr/lib/libpython2.7.dylib

 

 

3. Building as an Xcode Framework using the make_frameworks.sh script (obsoleted)

Note: the CMake build system should ultimately make this obsolete, one may remove this section when the CMake building is mature on the Mac. By the way, the make_framework.sh script has been removed since revision 2528.The last revision where make_framework.sh successfully builds, as I tested, is r2492.

OpenCV can now be built as a Mac OS X Framework useable with XCode. Just invoke the './make_frameworks.sh' script and you will obtain a Universal Framework named "OpenCV.framework" meant as a Private Framework.

Additionally, a pre-built version (universal binary Private Framework, again together with a demo application) is available. See the PrivateFramework wiki page or directly download it from http://www.ient.rwth-aachen.de/~asbach/OpenCV-Private-Framework-1.1.dmg .

A more recent version of the framework can be found here http://www.ient.rwth-aachen.de/cms/software/opencv/ or downloaded directly from http://www.ient.rwth-aachen.de/~asbach/OpenCV-Private-Framework-1.2.dmg

OpenCV 2.0 Universal Framework (tested on ppc and i386 Leopard and Snow Leopard): Here is an universal Framework for Mac ppc/i386 built from the OpenCV 2.0 released in September09. By the way, I also fixed some bugs and add some improvements:

 

-> a bug on Mac (carbon) that prevented cvCloseWindow/cvCloseAllWindow from working. -> a bug when 2 cameras capture images simultaneously (black bands) (see picture bellow) -> The trackbar now displays its current value (see picture bellow) and is resized according to its name.

Those fix/improvements are added to this framework.

http://nick.txtcc.com/wp-content/uploads/remote_image/2012/12/095445lne.png http://nick.txtcc.com/wp-content/uploads/remote_image/2012/12/095446Nn3.png

 

4. Building the old UNIX way

This was removed since it no longer works.

 

Other Resources

Links:

Attachments:

  • [get | view] (2006-05-30 14:17:41, 6.2 KB) [[attachment:export.cpp]]

 

Collected Information

 

Compiling Universal Binaries

The --enable-universal-build switch has been removed again since it doesn't allow building on intel machines ... You can still try out what it did by configuring with:

 

./configure CFLAGS="-arch i386 -arch ppc" CXXFLAGS="-arch i386 -arch ppc" --disable-dependency-tracking

As an alternative, we now have a small build script that configures and builds twice (once for ppc, once for intel) and then merges the binaries with lipo. We can and will extend this to more architectures whenever Mac OS X 10.5 Leopard is released, since it finally comes with 64bit compilers for intel. In addition to those then natural 4 platforms (intel/ppc * 32/64), it might be nice to provide specially optimized variants for G5, G4, G3 (-mcpu=...) to maximize speed on older hardware. This however requires additional testing (and performance testing).

See also: Compiling for Multiple Architectures in http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/

A (very old) list of supported quicktime codecs can be found at QuickTimeCodecs

Filed under: Mac OS, opencv No Comments
   
site
site