redhat3 EL + lighttpd + ror +mysql 上搭配生产环境

所有安装文件都放在/usr/ror/下,我的redhat 3 只能代理上网,由于代理上网的密码包含"@"字符,不能wget安装文件,安装文件都是网页里面下载的,rails也是本地安装。
ruby -v 可以查看到redhat EL3自带了ruby1.6.8的版本,mysql -v可以看到redhat EL3自带了mysql-3.23.58的版本

1、安装 ruby-1.8.6-p114
cd /usr/ror
tar zxvf ruby-1.8.6-p114.tar.gz
cd ruby-1.8.6-p114
./configure --prefix=/usr/local/ruby/
make && make install
ruby -v (1.6.8)
export PATH=/usr/local/ruby/bin:$PATH
ruby -v (1/8/6)


2、安装zlib
cd /usr/ror
tar -xvzf zlib-1.2.3.tar.gz
cd zlib-1.2.3.tar.gz
./configure
make
sudo make install


3、安装ruby-zlib
cd /usr/ror
tar xzvf ruby-zlib-0.6.0.tar.gz
cd ruby-zlib-0.6.0
ruby extconf.rb
make && make install


4、安装rubygems-0.9.2
tar xzvf rubygems-0.9.2.gz
cd rubygems-0.9.2
ruby setup.rb
gem -v


5、安装mysql

cd /usr/ror
rpm -ihv MySQL-devel-community-5.1.24-0.rhel3.i386.rpm(与mysql-3.23.58冲突)
rpm -e Mysql...(删除所有依赖mysql-3.23.58的rpm,...部分需要一个个删除,      rpm -e A B  一起删除互相依赖的rpm A和B)
rpm -ihv MySQL-devel-community-5.1.24-0.rhel3.i386.rpm
rpm -ihv MySQL-server-community-5.1.24-0.rhel3.i386.rpm
rpm -ihv MySQL-client-community-5.1.24-0.rhel3.i386.rpm
rpm -ihv MySQL-shared-community-5.1.24-0.rhel3.i386.rpm
rpm -ihv MySQL-shared-compat-5.1.24-0.rhel3.i386.rpm

mysql-v 进入mysql-5.1.24(默认空密码)
mysqladmin -u root -p password yourpasswd(重设密码)
mysql -u root -p(带密码登陆)
show databases(查看已存在的数据库)
create database hspm(新建数据库hspm)
drop database hspm(删除数据库hspm)


6、安装mysql-ruby
cd /usr/ror
tar xzvf mysql-ruby-2.7.5.tar.gz
cd mysql-ruby-2.7.5
ruby extconf.rb --with-mysql-dir=/usr
make && make install


7、安装rails 1.2.5
cd /usr/ror
unset http_proxy (取消代理)
gem install rails -l -y
(如果上面的没起作用,则需要一个个安装rails的gems
gem install -l rake-0.7.2.gem
gem install -l activesupport-1.4.4.gem
gem install -l actionpack-1.13.5
gem install -l activerecord-1.15.5.gem
gem install -l actionmailer-1.3.5
gem install -l actionwebservice-1.2.5
gem install -l rails-1.2.5.gem
)


8、安装fcgi ,ruby-fcgi
cd /usr/ror
tar xzvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure --prefix=/usr/local/fcgi
make && make install


9、安装ruby-fcgi-0.8.7
cd /usr/ror
tar xzvf ruby-fcgi-0.8.7.tar.gz
cd ruby-fcgi-0.8.7
ruby install.rb config -- --with-fcgi-include=/usr/local/fcgi/include --with-fcgi-lib=/usr/local/fcgi/lib
ruby install.rb setup
ruby install.rb install



10、安装Lighttpd 1.4.19
(如果是linux最小安装,则还需装pcre 和pcre-devel
cd /usr/ror
tar xzvf pcre-6.3.tar.gz
./configure --prefix=/usr/local/pcre
make && make install

cd /usr/ror
rpm -ihv pcre-devel-3.9-3.i386.rpm
)
cd /usr/ror
tar xzvf lighttpd-1.4.19.tar.gz
cd lighttpd-1.4.19
./configure --prefix=/usr/local/lighttpd
(configure完毕以后,会给出一个激活的模块和没有激活模块的清单,可以检查一下,是否自己需要的模块都已经激活,在enable的模块中一定要有“mod_rewrite”这一项,否则重新检查pcre是否安装。然后编译安装:)
make && make install

cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
mkdir /etc/lighttpd
cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd
vi /etc/init.d/lighttpd (vi里面 a表示插入,esc键停止修改,esc后ZZ保存退出)
LIGHTTPD_BIN=/usr/sbin/lighttpd
改为
LIGHTTPD_BIN=/usr/local/lighttpd/sbin/lighttpd

/etc/init.d/lighttpd start (lighttpd的启动,没配置前还不能启动)
/etc/init.d/lighttpd stop  (lighttpd的关闭)
/etc/init.d/lighttpd restart (lighttpd的重起)
chkconfig lighttpd on (服务器启动的时候就启动lighttpd


11、配置lighttpd
mkdir /usr/www
vi /etc/lighttpd/lighttpd.conf (按a修改)
取消需要用到模块的注释,mod_rewrite,mod_access,mod_fastcgi,mod_simple_vhost,mod_cgi,mod_compress,mod_accesslog 。server.document-root="/usr/www"

server.username            = "root" (linux授权不熟,先用root)
server.groupname           = "root"
(静态文件压缩)
compress.cache-dir         = "/tmp/lighttpd/cache/compress"
compress.filetype          = ("text/plain", "text/html","text/javascript","text/css")

esc退出修改,ZZ保存退出
/etc/init.d/lighttpd start (lighttpd的启动,没配置前还不能启动)


12、hspm.zip是windows下开发的项目,配置项目并运行
mkdir /usr/rails_apps (用来存放rails项目)
cd /usr/ror
cp hspm.zip /usr/rails_apps
unzip hspm.zip
cd hspm
vi config/database.yml (配置数据库连接,a修改,esc停止,ZZ退出)
vi public/dispatch.fcgi (将顶端的 c:/ruby/bin/ruby.exe 改成 /usr/local/ruby/bin/ruby ,a修改,esc停止,ZZ退出)
cd public && ./dispatch.fcgi (看是否有权限)
chmod 755 dispatch.fcgi (给dispatch.fcgi授权,需在public目录下)
cd /usr/rails_apps/hspm
cd public && ./dispatch.fcgi (这时可以看到dispatch.fcgi里的内容)



/etc/init.d/lighttpd start (lighttpd的启动,没配置前还不能启动)
cd /usr/rails_apps/hspm
rake db/migrate (数据迁移)
ruby script/server (在开发模式运行项目,config下会有lighttpd.conf文件)
(ctrl + C 退出运行 )
vi config/lighttpd.conf
(修改lighttpd的配置文件,在生产模式下给10个fcgi进程来运行rails)

server.port                 = 4000
server.bind                 = "127.0.0.1"
server.event-handler        = "freebsd-kqueue"

server.modules              = ( "mod_rewrite", "mod_fastcgi", )
server.indexfiles           = ( "dispatch.fcgi" )
server.document-root        = "public/"
server.error-handler-404    = "/dispatch.fcgi"
server.errorlog             = "log/error.log"

url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )

#### fastcgi module
fastcgi.server =  (
   ".fcgi" => (
     "typo" => (
       "min-procs" => 10,
       "max-procs" => 10,
       "socket" => "/tmp/typo1.socket",
       "bin-path" => "public/dispatch.fcgi",
       "bin-environment" => ("RAILS_ENV" => "production"
       "idle-timeout" => 120
     )
   )
)



cd /usr/ror/hspm
ruby script/server (运行项目)
生产环境已搭配好,http://10.9.12.64:4000 (http://url:port)可以访问新项目了
注意:不熟悉redhat的同学,请不要随意修改其/etc 下的文件,搭配好生产环境后,最好不要进行任何/etc 下的修改,小心操作系统挂掉哈。

设置路由
route add -net 10.9.12.0  netmask 255.255.255.0 gw 10.9.12.254 dev eth1
route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.12.254 dev eth1
设置ruby环境变量 export PATH=/usr/local/ruby/bin:$PATH

你可能感兴趣的:(mysql,redhat,lighttpd,Ruby,Rails)