2008-09-29

Solaris console环境下构建Apache+MySQL+PHP 平台

  其实,Solaris Express Developer Edition的安装过程中只要选完全安装这些东西就会自动装好的,不过,我们总得学会自力更生吧,所以我在安装系统的过程中没有安装这些,而选择了自己手动安装。
  基本上呢,solaris需要的东西都能通过http://www.sunfreeware.com/这个地方下载到,因为没有GUI,所以我们要会用ftp命令,路径可以在网站里查到,我们用ftp程序直接下载动solaris系统吧。看下网站上的说明就明白了:

[179] steve> ftp ftp.sunfreeware.com
Connected to ftp.sunfreeware.com.
220 ftp.sunfreeware.com FTP server ready.
Name (ftp.sunfreeware.com:steve): anonymous
331 Guest login ok, send your complete e-mail address as password.
Password:
230-
230-==============================================
230-This is the ftp.sunfreeware.com ftp server
230-
230-If you have not already done so, make sure
230-you have read the Downloading/Installation,
230-FAQ, and Disclaimer links on
230-http://sunfreeware.com.
230-
230-This is a restricted access system. All
230-transfers are logged. If you disagree
230-with this practice, log off now.
230-
230-Questions go to Steve Christensen at
230-steve@smc.vnet.net.
230-==============================================
230-
230-
230 Guest login ok, access restrictions apply.
ftp> bin
200 Type set to I.
ftp> cd pub/freeware
250 CWD command successful.
ft>p

这里为了方便,我期望使用ssh远程登录到solaris服务器上,因此先安装。如果你之前装了就别再装了,用svcs查看一下有没有ssh服务在运行:
svcs | grep ssh
如果没有的话再安装,从这个网站下载的软件包只要gzip -d 一下之后用pkgadd -d 一下就安装完了。
接下来配置openssh:
配置文件是/etc/ssh/sshd_config
我要做的只有几个事:
改端口:把port右边的22改成需要的端口号。
允许root用户登录,虽然这不安全,但在我现在使用的时刻正好需要。
好了,ssh配置完以后就可以在图形界面下的机器用ssh远程登录到服务器了,而且可以直接使用sftp传送文件,这样就不要每个文件都去输入名字传输了。
接下来就准备安装Apache了,从那个网站的下载介绍里面能看到它的包依赖信息:
apache-2.2.9-sol10-x86-local.gz Apache 2 - the popular web server - installs in /usr/local/apache2. Dependencies: expat, libiconv, openldap, sasl, zlib, openssl-0.9.8h, and either the libgcc-3.4.6 or gcc-3.4.6. Documentation can be found in /usr/local/apache2/doc/apache2. The configuration files in /usr/local/apache2/conf must be edited to fit your site's needs, including ssl support.

本来可以直接使用这个网站提供的包来安装这三个软件的的,不过我希望试试自己编译,所以直接从官网下了unix版的源码来编译安装:

先是mysql:

 从官方下载的包安装:
  • 建立目录:
    mkdir /usr/local/apache
  • 建立mysql的用户组和用户
    groupadd -g 110 mysql
    useradd -u 10001 -g mysql -m -d /export/home/mysql -s /bin/bash mysql
    passwd mysql

  • 安装好软件包就可以了,注意,如果之后安装php的时候用的是32位的,就要装32位的mysql,否则无法编译php。装好后如果能够正常启动服务并用空密码登录root就成功了,不能的话看下面
  不知为什么我的机器就是装不好官方下的那个包,总是提示pid文件找不到什么的,无奈之下,采取另外一种方法:
rm -fr /opt/mysql/mysql/data/*
因为我用官方包安装所以安装的路径是这个。
之后
cd /opt/mysql/mysql
./scripts/mysql_install_db --user=mysql

这里如果成功的话再
./bin/safe_mysqld --user=mysql
应该就能启动服务了。
不过相当无奈的是这个情况下root用户一直被拒绝登录。只能用别的方法了:
先停止服务:
/etc/init.d/mysql stop
用这个类似于超级维护模式的方法开启服务:
./bin/safe_mysqld --user=mysql --skip-grant-tables --skip-networking &
好了,输入mysql总算是进入mysql monitor了。不过问题来了。
select * from mysql.users
结果是0条数据。。。汗死。。。
所以我就试试直接新建一个用户的方法了:
mysql> INSERT INTO mysql.user (Host,User,Password)VALUES('%','test',PASSWORD('tset'));
mysql> FLUSH PRIVILEGES


弄完之后
/etc/init.d/mysql restart
最后成功的用那个帐户登录了。。。。
最后在启动脚本里面增加文件让mysql开关机时自动开启关闭:
ln /opt/mysql/mysql/support-files/mysql.server /etc/rc3.d/S99mysql
ln
/opt/mysql/mysql/support-files/mysql.server /etc/rc0.d/K00mysql
ln
/opt/mysql/mysql/support-files/mysql.server /etc/rc1.d/K00mysql
ln
/opt/mysql/mysql/support-files/mysql.server /etc/rc2.d/K00mysql
ln
/opt/mysql/mysql/support-files/mysql.server /etc/rcS.d/K00mysql

mysql到此就装好了。
 从源代码安装:
  • 准备动作同上,之后解压源代码,执行:
    ./configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls --prefix=/usr/local/mysql --with-mysqld-user=mysql --with-charset=gb2312 --with-extra-charsets=all
    with-as那一项是指定汇编编译器
  • 上一步执行成功之后就可以开始编译了,make的过程比较持久,我们好好等待吧。
  • 之后的步骤同上

 

接下来是Apache+php了:
  • 在编译之前必须安装一下软件包:
    SUNWarc
    SUNWbtool
    SUNWhea
    SUNWlibm
    SUNWsprot
    SUNWtoo

    这些包可以直接从光盘安装,方法:
    pkgadd -d /cdrom/sol_11_x86/Solaris_11/Product/ SUNWarc
    ...

  • 必须注意的一点是,Apache2.2以上的版本除了要安装编译环境之外还必须安装apr-1.2.2-sol10-x86-local.gz与aprutil-1.2.2-sol10-x86-local.gz这两个包,否则configure会出现configure failed for srclib/apr错误。目前从sunfreeware下的包还是不能编译apache,貌似是少了一个版本文件,所以我是从apr.apache.org那里下了新版自己编译的。
  • 编译apache:
    ./configure --prefix=/usr/local/apache -enable-so -enable-mods-shared=most
    这样就动态编译了apache了。编译完后安装,之后别动。
  • 编译php:
    ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs
    注意那个apxs2
  • cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
    cp php.ini-dist /usr/local/apache/conf/php.ini
  • 修改配置文件:
    检查LoadModule 中是否有
    LoadModule 5_module modules/libphp5.so
    这一行,没有加上。
    ServerName这一行指定好自己的服务器的域名或ip。
    默认的DocumentRoot可以修改。
    加一行AddType application/x-httpd-php .php .phtml
  • 之后/etc/init.d/httpd start来开启apache,就可以在别的机器上测试一下apache成功与否了。
基本上写一个index.php页面,内容如下:
<html>
<body>
<title>Hello World</title>
<?php phpinfo(); ?>
</body>
</html>


如果成功的话,就会出现php的信息了。
最后增加启动脚本并且连接文件:
ln -s /etc/init.d/httpd /etc/rc3.d/S90http
ln -s /etc/init.d/httpd /etc/rc3.d/K90http
ln -s /usr/local/apache/bin/apachectl /usr/bin/apache
/*******************************************
*原创文章,转载请注明出处
*******************************************/

Solaris10 console下配置网络

主要有几个文件需要配置:

  1. /etc/hosts 主机名解析 就是host表
  2. /etc/hostname.interface interface是网卡名,用于分配主机名,直接在里面输入主机名就好了。
  3. /etc/netmasks 设置子网掩码格式类似于:
    10.1.1.0 255.255.255.0
  4. /etc/inetd.conf 参见下面这段话
    UNIX并不是让每种服务的守护进程都在自己的端口上等待请求,而是将代表各个服务守护进程等待请求的任务交给一个叫inetd的服务进程。这样就可以大 大减少对系统资源的占用。只有当超级服务进程发现一个服务请求时,它才调用该服务的守护进程。/etc/inetd.conf配置文件允许inetd在启 动时决定自己将代表哪些服务等待服务请求。如果一种服务的守护进程没有包含在inetd.conf文件中,那么当inetd接收到该服务的请求时,会把该 请求丢弃。
    文件的字段:
    service_name 这是文件/etc/services中列出的服务的标志符。
    socket_type 用来标志使用的数据传输服务的类型。
    proto 标识传输协议的名字。是UPD和TCP
    flags 可以被设为"等待"和"非等待"。如果被设为"等待" 状态,inetd在恢复监听端口上的其他请求时,必须等待服 务协议释放将其连接到网络的连接。"非等待"可以使 inetd立即监听其他的请求。大多数TCP协议的采用"非等 待"方式,而UDP采用"等待"方式。
    user 表示调用服务的用户名。
    server_pathname 表示inetd在响应相关服务请求时必须调用的 服务程序的完整路径名。
    Args 该域包括服务的程序所使用的命令行参数。即以程序名开 始,然后跟随用户设置的参数
  5. /etc/defaultrouter 设定默认路由 直接输入网关的ip地址一般就可以了。
  6. /etc/gateways 这个是路由表文件,设置比较麻烦
  7. /etc/nsswitch.files 设定名字搜索顺序 记得在hosts: files背后加个dns
  8. /etc/resolv.conf 配置dns服务器的地址和域名格式:
    domain abc.efg.com
    nameserver 10.3.3.33

其他命令:
ifconfig
nslookup
netstat等等

2008-09-27

法拉第看教学

  说到教学,现在充斥于中国的课堂的气氛恐怕多数是一种互相之间都略失激情的悲哀吧。
  不过,几个世纪前,法拉第这位爱教书的老兄对教学有自己的见解,他认为教学是一门艺术。
  最近在某处看到他写的关于教学的看法:“老师上课就像带学生到一条花香满径的地方散步,因此老师在讲课时说话速度不宜太快,好像急着要做结论似的,但也不宜讲的太慢,好像吧学生的大脑反反复复的浸泡在同一种液体里,学生不昏睡才怪。语言是思想的外衣,要让自己的语言与思想和谐均匀的一起表达,用语言吧一个概念清楚而完整的表达出来,这是老师的责任,科学教育本来就是一件令人兴奋的事情,不能怪学生懒散不感兴趣,老师不是木头人因此上课的时候要用动作来加强语言,用语言来产生动作,如果教学没有动作,就像朗诵文稿的官吏,依我所知,自然界里没有一种动物发声的时候没有动作的,但是有些人以上讲台,两腿就被黏在地板上,两手就被黏在讲桌上,其实,身体也应该是一种教学的工具。”

2008-09-22

ubuntu的小键盘问题

  基本上,这个问题相当奇怪,不知道什么时候,重启一下之后突然小键盘没办法输入数字了。。。反倒变成鼠标控制键了,而且numlock是启动的状态。。。
  结果呢,其实只要用shift+alt+numLock组合键一按就可以恢复了。其实在xwindow的常用快捷键里有介绍的:


1. Ctrl-Alt-“+” 或者 Ctrl-Alt-“-”- 改变屏幕分辨率(提高/降低)。前提是在X-Window server配置文件中写入了多种可用分辨率。
2. Ctrl-Alt-Backspace - 杀死X-server,返回登录界面。所有正在运行的应用程序将被终止。
3. Ctrl-Alt-Escape - xkill - 点击一个应用程序强制关闭。
4. Ctrl-Shift-Num Lock 把键盘上的小键盘(数字键盘)变成鼠标,启动后你可以用小键盘进行鼠标操作。数字键盘上的/和 * 分别代表鼠标左键和鼠标右键,数字键盘上的 5是双击。
5. Ctrl-Alt-Fn (F1, F2, F3,…) - 切换到第 n 个文本控制台。一般Alt+F7切换回X-window。
6. Alt-F2 - 开启一个运行命令的小窗口。如果输入的是可执行命令则直接运行;如果输入的是文件名系统将调用适当的应用程序打开它;输入网址将用默认的浏览器打开它。
基本上,这个也是一项功能吧。

2008-09-21

mkv视频的处理

  随着高清的普及,以mkv封装发布的视频越来越多。这种格式的视频需要处理的话直接用普通的傻瓜式程序是不可能的,而使用mencoder又会改变封装,这个过程会产生奇怪的问题。比如不同步,时间轴不准等等。这个时候就需要使用强大的MKVToolnix。
  官方对它的定义是:MKVToolnix -- Cross-platform tools for Matroska
  当然就是跨平台,又开源的东西了。我这次用的是linux平台来解说。也可自己参照官网的文档:http://www.bunkus.org/videotools/mkvtoolnix/source.html
  MKVToolnix包括mkvmerge mkvinfo mkvextract
  mkvmerge的gui版使用mmg命令启动。下面主要介绍一下我自己常用的功能:

切割mkv视频:
  mkvmerge在切割方面提供了三种方法,见split参数解释:
  

Splits the output file after a given size or a given time. Please note that tracks can only be split right before a key frame. Due to buffering mkvmerge will split right before the next key frame after the split point has been reached. Therefore the split point may be a bit off from what the user has specified.
At the moment mkvmerge supports three different modes.
1. Splitting by size.
The parameter d may end with k, m or g to indicate that the size is in KB, MB or GB respectively. Otherwise a size in Bytes is assumed. After the current output file has reached this size limit a new one will be started. The size: prefix may be omitted for compatibility reasons.
2. Splitting after a duration.
The paramter must have the form HH:MM:SS.nnnnnnnnn for specifying the duration in up to nano-second precision or a number n followed by the letter ’s’ for the duration in seconds. "HH" is the number of hours, "MM" the number of minutes, "SS" the number of seconds and "nnnnnnnnn" the number of nanoseconds. Both the number of hours and the number of nanoseconds can be omitted. There can be up to nine digits after the decimal point. After the duration of the contents in the current output has reached this limit a new output file will be started. The duration: prefix may be omitted for compatibility reasons.
3. Splitting after specific timecodes.
The parameters A, B etc must all have the same format as the ones used for the duration (see above). The list of timecodes is separated by commas. After the current file has reached the current split point’s timecode a new file is created. Then the next split point given in this list is used. The timecodes: prefix must not be omitted.
For this splitting mode the output filename is treated differently than for the normal operation. It may contain a printf like expression ’%d’ including an optional field width, e.g. ’%02d’. If it does then the current file number will be formatted appropriately and inserted at that point in the filename. If there is no such pattern then a pattern of ’-%03d’ is assumed right before the file’s extension: ’-o output.mkv’ would result in ’output-001.mkv’ and so on. If there’s no extension then ’-%03d’ will be appended to the name.  
  废话很长,其实就是三种,一个按大小分割,一个按每次分割出的文件有多长时间分割,还有一个按照时间点分割也就是从头开始,当时间到你填入的时间点时它会自动分割一个文件。
比如我填50s,160s那么视频会被分成三个片段,一个从头到50s第二个从50s到160s,第三个从160s到结束。


提取mkv视频中的流:
  直接用mkvextract命令就好了。

封装成mkv:
  同样使用mkvmerge就好了。