年前对基于Linux的大型分布式的 Web 架构做了一些调研,我是在Ubuntu虚拟中做的试验,下面是记录的笔记:
<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:微软雅黑; panose-1:2 11 5 3 2 2 4 2 2 4; mso-font-charset:134; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-2147483001 705641554 22 0 262175 0;} @font-face {font-family:"/@微软雅黑"; panose-1:2 11 5 3 2 2 4 2 2 4; mso-font-charset:134; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-2147483001 705641554 22 0 262175 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; mso-themecolor:hyperlink; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {mso-style-priority:34; mso-style-unhide:no; mso-style-qformat:yes; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:389234680; mso-list-type:hybrid; mso-list-template-ids:-492550424 1783919710 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-tab-stop:none; mso-level-number-position:left; margin-left:18.0pt; text-indent:-18.0pt;} @list l0:level2 {mso-level-number-format:alpha-lower; mso-level-text:"%2/)"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:42.0pt; text-indent:-21.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->
Ubuntu Distributed System 实践笔记
1. 安装 Ubuntu 9 ,从官方下载最新的 iso ,在 VMWare 中安装
a) 系统升级 sudo apt-get update , sudo apt-get dis-upgrade
b) Ubuntu 下安装 rpm 包
sudo apt-get install alien #alien 默认没有安装,所以首先要安装它
sudo alien xxxx.rpm # 将 rpm 转换位 deb ,完成后会生成一个同名的 xxxx.deb
sudo dpkg -i xxxx.deb # 安装
或者先将 VMWareTools 光盘中的文件解压,然后执行 vmware-install.pl
出现文件共享未成功,按照 Ubuntu 中文论坛上的解决办法未能成功,重新安装新版本的 VMWareTools8.1.3 解决
但后来重装 VMWareTools8.1.3 后再次无法共享,干脆安装 samba
sudo apt-get install samba
sudo apt-get install smbfs
c) 创建 /home/jhzhang/Share
d) 编辑 /etc/samba/smb.conf 添加下面的内容:
修改 security = user 为 security = share
添加共享设置:
[Share]
path = /home/jhzhang/Share
browseable = yes
guest ok = yes
read only = no
writable = yes
现在从 PC 机可以浏览并编辑了。
使用 sudo smbclient //192.168.79.55/Publish -U iflytek/jhzhang% 密码 可以从 ubuntu 中访问 PC 机
或者使用下面的方法挂接:
sudo smbmount //192.168.79.55/dr /mnt/dr -o user=jhzhang,pass= 密码 ,dom=iflytek
2. 安装 apache , php , mysql
a) su1. 安装 SSH( 必须 ) sudo apt-get install ssh
b) 安装 MySQL( 虽然现在最新版为 5.1 ,但是还只能装 5.0 版本 )
sudo apt-get install mysql-server-5.0
修改 mysql root 密码(刚开始用空,后来发现 phpmyadmin 默认不允许空密码): mysqladmin -u root -p password 新密码
又发现无法通过 MySql-Front 从 PC 上连接,
grant all on *.* to root@'%' identified by 'iflytek' 修改 root 权限
sudo gedit /etc/mysql/my.cnf
bind-address = 127.0.0.1 改为 : bind-address = 0.0.0.0
重启 mysql 搞定
c) 安装 Apache
sudo apt-get install apache2
sudo gedit /etc/apache2/ports.conf
修改 apache 端口为 8080
重启 apache
d) 安装 PHP
sudo apt-get install php5 libapache2-mod-php5
sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql
sudo apt-get install php5-gd
配置 php.ini:
sudo gedit /etc/php5/apache2/php.ini
把文件在文件后面的:
#extension=mysql.so
#extension=gd.so
的#去掉。
e) 简单配置工作
sudo /etc/init.d/apache2 restart (重启 apache )
sudo gedit /etc/php5/apache2/php.ini (配置 php.ini )
sudo gedit /etc/apache2/apache2.conf (配置 apache2.conf )
/var/www/ (主目录位置)
f) 安装 phpmyadmin :
sudo apt-get install phpmyadmin
默认安装在 /usr/share/phpmyadmin
作个链接到 /var/www/ 目录下,命令为: sudo ln -s /usr/share/phpmyadmin/ /var/www/
再使用 http://localhost/phpmyadmin 即可以访问了。
3. 安装 nginx
a) Sudo apt-get install nginx
b) 修改 nginx 配置,参考 nginx 配置参数文档
sudo gedit /etc/nginx/nginx.conf ,添加下面的内容
upstream LocalMachine {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name 192.168.5.128;
location / {
proxy_pass http://LocalMachine;
}
location /NginxStatus {
stub_status on; #Nginx 状态监控配置
}
}
重启 nginx
4. 安装 MogileFS 分布式文件存储服务
a) 修改 sourcelist
sudo gedit /etc/apt/sources.list ,加入下面两行:
deb http://ppa.launchpad.net/awmcclain/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/awmcclain/ppa/ubuntu jaunty main
b) 更新并安装
sudo apt-get update
sudo apt-get install mogilefsd mogstored
c) 连接 mysql 创建数据库:
create database mogilefs;
CREATE USER 'mogilefs'@'localhost' IDENTIFIED BY 'iflytek';
GRANT SELECT,INSERT,UPDATE,DELETE ON mogilefs.* TO 'mogilefs'@'localhost';
Flush privileges;
mogdbsetup --dbhost=localhost --dbname=mogilefs --dbuser=mogilefs --dbpassword=iflytek;
d) 修改配置,创建用户,并启动服务:
sudo gedit /etc/mogilefs/mogilefsd.conf
sudo adduser mogile
su mogile
mogilefsd -c /etc/mogilefs/mogilefsd.conf –daemon
确认服务是否已经启动 :
ps aux | grep mogilefsd
e) 添加 host
mogadm --lib=/usr/local/share/perl/5.10.0 --trackers=127.0.0.1:7001 host add LocalStorageDev --ip=127.0.0.1 --port=7500 --status=alive
发现还需要安装 mogilefs-utils ,使用 sudo aptget install mogilefs-utils 没成功,改为手工安装:
从 CPAN 上下载 MogileFS-Client-1.10.tar.gz , IO-stringy-2.110.tar.gz , MogileFS-Utils-2.15.tar.gz
安装 执行的命令都一样
# tar zxvf xxxxx.tar.gz
# cd xxxxx
# perl Makefile.PL
# make
# make test
# make install
重新运行上面的 mogadm 命令, OK
检查 Host
mogadm --lib=/usr/local/share/perl/5.10.0 --trackers=127.0.0.1:7001 host list
有了:
LocalStorage [1]: alive
IP: 127.0.0.1:7500
f) 依次添加 device , domain , class :
mogadm --lib=/usr/local/share/perl/5.10.0 --trackers=127.0.0.1:7001 device add LocalStorage 1
mkdir -p /var/mogdata/dev1
mogadm --lib=/usr/local/share/perl/5.10.0 --trackers=127.0.0.1:7001 device list
mogadm --lib=/usr/local/share/perl/5.10.0 --trackers=127.0.0.1:7001 domain add typecho
mogadm --lib=/usr/local/share/perl/5.10.0 --trackers=127.0.0.1:7001 domain list
mogadm --lib=/usr/local/share/perl/5.10.0 --trackers=127.0.0.1:7001 class add typecho attachments
mogadm --lib=/usr/local/share/perl/5.10.0 --trackers=127.0.0.1:7001 class list
g) 安装 mogilefs PHP client
有可能需要安装 libxml2
apt-get install libxml2 libxml2-dev expat
下载 neon 最新版本
tar zxvf neon-0.29.3.tar.gz
cd neon-0.29.3
./configure
sudo make
sudo make install
tar xvf mogilefs-0.7.5b3.tar
cd mogilefs-0.7.5b3
phpize ,如出现找不到命令,需要安装 php5-dev
. /configure
make
make install
编辑 sudo gedit /etc/php5/apache2/php.ini ,加入:
extension=mogilefs.so
重启 apache
后来又装了另一个封装好的 php 类,这个不需要装扩展:
http://lists.danga.com/pipermail/mogilefs/2007-July/001085.html
5. 安装 memcached 服务
a) 安装 memcached
sudo apt-get install memcached
b) 启动 memcached 服务
memcached -d -m 50 -p 11211 -u root
参数说明 -m 指定使用多少兆的缓存空间; -p 指定要监听的端口; -u 指定以哪个用户来运行
ps aux | grep mеmcache
c) 安装 memcached php5 扩展
sudo apt-get install php5-memcache
d) 修改配置文件
编辑配置文件
$ sudo vim /etc/php5/conf.d/memcache.ini
; uncomment the next line to enable the module
extension=memcache.so
[memcache]
memcache.dbpath="/var/lib/memcache"
memcache.maxreclevel=0
memcache.maxfiles=0
memcache.archivememlim=0
memcache.maxfilesize=0
memcache.maxratio=0
6. 安装 PHP 应用软件系统
a) ImageVueV2 Flash 相册
b) 打开 /etc/apache2/httpd.conf 编辑,添加下面的内容:
DocumentRoot /var/www
Alias /imagevue/ "/home/jhzhang/Share/ImageVueV2"
<Directory "/home/jhzhang/Share/ImageVueV2">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Allow from all
</Directory>
c) 访问 http://192.168.5.128/imagevue/index.php 出现找不到该页
找到 /var/log/apache2/error.log ,发现是路径的问题,修改上面的虚拟路径配置在 ImageVue2 后加上 / 解决。
d)
再次访问,出现写 folderdata.xml 失败,
sudo chgrp nogroup –cR ./*
sudo chown nobody –cR ./*
sudo chmod 777 -Rf ./* 后解决。
e) 发现 imagenue 代码不算很简单,所以又找了个 Typecho 程序,部署过程都差不多
7. 修改程序增加分布式文件存储及缓存支持
a)