Created
December 10, 2013 15:17
-
-
Save jay16/7892262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
系统环境:centos 5.5 | |
需要文件: | |
sqlite-amalgamation-3.6.16.tar.gz (sqlite安装包) | |
ruby-1.9.2-p180.tar.gz (ruby1.9.2安装包) | |
node-v0.4.8.tar.gz (nodejs安装包) | |
redis-2.4.16.tar.gz (redis安装包) | |
focus_mail.tar.gz (FocusMail源代码,解压后文件夹名为focus_mail_128,应修改为focus_mail) | |
mail206.tar.gz (FocusMail数据库内容) | |
redis.conf (redis配置文件,放置/etc下) | |
说明: | |
1.下列操作中所有安装包都放置在/home/tools下 | |
2.FocusMail部署在/home/work/下 | |
3.FocusMail文件夹的权限为webmail:webmail; | |
resque、passenger的启动需要使用webmail用户 | |
3.所需安装包下载链接 | |
普通下载:https://codeload.github.com/jay16/FocusMail_SOP/zip/master | |
git下载: https://github.com/jay16/FocusMail_SOP.git | |
1. 安装gcc | |
[root@localhost ~]# yum -y install gcc gcc-c++ gcc-g77 flex autoconf zlib curl readline-devel libxslt libxml2-devel libxslt-devel zlib-devel curl-devel bzip2 bzip2-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel | |
2.安装ruby1.92 | |
[root@localhost ~]# cd /home/tools/ | |
[root@localhost tools]# tar -xvzf ruby-1.9.2-p180.tar.gz | |
[root@localhost tools]# cd ruby-1.9.2-p180 | |
[root@localhost ruby-1.9.2-p180]# ./configure | |
[root@localhost ruby-1.9.2-p180]# make | |
[root@localhost ruby-1.9.2-p180]# sudo make install | |
[root@localhost ruby-1.9.2-p180]# ruby -v | |
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] | |
[root@localhost ruby-1.9.2-p180]# | |
----------------------------------------------------------------------- | |
-如果安装失败,把make后的文件夹拷贝至/usr/lib/下,然后 - | |
-创建ruby link - | |
-[root@localhost bin]# ln -s /usr/lib/ruby-1.9.2-p180/ruby ruby - | |
----------------------------------------------------------------------- | |
3.更新gem | |
[root@localhost ruby-1.9.2-p180]# gem update --system | |
[root@localhost ruby-1.9.2-p180]# gem update | |
[root@localhost ruby-1.9.2-p180]# gem -v | |
2.0.3 | |
4.安装rails | |
[root@localhost ruby-1.9.2-p180]# gem install rails -v=3.2.3 | |
[root@localhost ruby-1.9.2-p180]# rails -v | |
Rails 3.2.3 | |
5.安装数据库sqlite,mysql | |
5.1安装sqlite | |
[root@localhost ruby-1.9.2-p180]# yum -y install expat-devel gettext-devel sqlite-devel | |
[root@localhost ruby-1.9.2-p180]# cd /home/tools/ | |
[root@localhost tools]# tar xvzf sqlite-amalgamation-3.6.16.tar.gz | |
[root@localhost tools]# cd sqlite-3.6.16/ | |
[root@localhost sqlite-3.6.16]# ./configure --prefix=/usr | |
[root@localhost sqlite-3.6.16]# make | |
[root@localhost sqlite-3.6.16]# make install | |
[root@localhost sqlite-3.6.16]# sqlite3 -version | |
3.6.16 | |
安装sqlite相关套件 | |
[root@localhost sqlite-3.6.16]# gem install sqlite3-ruby | |
5.2安装mysql | |
[root@localhost sqlite-3.6.16]# yum -y install mysql-server | |
[root@localhost sqlite-3.6.16]# yum -y install mysql | |
[root@localhost sqlite-3.6.16]# yum -y install mysql-devel | |
启动mysql服务 | |
[root@localhost sqlite-3.6.16]# service mysqld start | |
登陆mysql,默认初始登陆密码为空 | |
[root@localhost sqlite-3.6.16]# mysql -u root -p | |
Enter password: (默认密码为空,直接回车) | |
修改mysql root登陆密码为Focus_Mail | |
创建mail_206数据库,并导入数据 | |
mysql> use mysql | |
Database changed | |
mysql> update user set password=password('Focus_01') where user='root'; | |
mysql> flush privileges; | |
mysql> | |
mysql> create database mail_206; | |
Query OK, 1 row affected (0.00 sec) | |
mysql> use mail_206; | |
Database changed | |
mysql> source /home/tools/mail206_bk.sql; | |
mysql> exit | |
Bye | |
6.测试 rails | |
[root@localhost ruby-1.9.2-p180]# cd /home/tools | |
[root@localhost tools]# rails new rails_app | |
[root@localhost tools]# cd rails_app/ | |
[root@localhost rails_app]# vi Gemfile | |
修改Gemfile,添加如下内容 | |
gem 'rb-readline' | |
gem 'execjs' | |
gem 'therubyracer' | |
[root@localhost rails_app]# bundle install | |
Make sure that `gem install therubyracer -v '0.11.4'` succeeds before bundling. | |
[root@localhost rails_app]# cd /home/tools | |
[root@localhost tools]# tar xzvf node-v0.4.8.tar.gz | |
[root@localhost tools]# cd node-v0.4.8 | |
[root@localhost node-v0.4.8]# ./configure | |
[root@localhost node-v0.4.8]# make | |
[root@localhost node-v0.4.8]# make install | |
[root@localhost node-v0.4.8]# gem install therubyracer | |
[root@localhost node-v0.4.8]# | |
[root@localhost node-v0.4.8]# cd /home/work/focus_mail | |
[root@localhost rails_app]# rm -fr Gemfile.lock | |
[root@localhost rails_app]# bundle install | |
[root@localhost rails_app]# rails s | |
出现以下提示表示启动成功 | |
=> Booting WEBrick | |
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000 | |
=> Call with -d to detach | |
=> Ctrl-C to shutdown server | |
[2013-04-29 07:29:36] INFO WEBrick 1.3.1 | |
[2013-04-29 07:29:36] INFO ruby 1.9.2 (2011-02-18) [i686-linux] | |
[2013-04-29 07:29:36] INFO WEBrick::HTTPServer#start: pid=4894 port=3000 | |
7.部署FocusMail | |
[root@localhost tools]# tar xzvf focus_mail.tar.gz | |
[root@localhost tools]# mv focus_mail_128 focus_mail | |
[root@localhost tools]# mkdir /home/work | |
[root@localhost tools]# cp -R focus_mail /home/work/ | |
[root@localhost tools]# cd /home/work/focus_mail/ | |
修改focus_mail文件夹权限 | |
[root@localhost focus_mail]# chown -R webmail:webmail /home/work/focus_mail | |
修改数据库配置文件 | |
[root@localhost focus_mail]# vi config/databases.yml | |
(1)修改文件config/databases.yml | |
将文件中ip 替换为localhost | |
修改Gemfile | |
[root@localhost focus_mail]# vi Gemfile | |
(2)修改文件Gemfile | |
gem 'lazy_high_charts', '~> 1.1.5' 修改为: gem 'lazy_high_charts' | |
添加 | |
gem 'rb-readline' | |
[root@localhost focus_mail]# rm -f Gemfile.lock | |
[root@localhost focus_mail]# bundle install | |
关闭防火墙 | |
[root@localhost focus_mail]# service iptables stop | |
启动FocusMail | |
[root@localhost focus_mail]# rails s | |
启动过程可能出现如下问题: | |
可能问题1 | |
gem nokogiri error: checking for libxml/parser.h. | |
[root@localhost focus_mail]# yum install libxslt libxml2-devel libxslt-devel | |
[root@localhost focus_mail]# gem install nokogiri | |
[root@localhost focus_mail]# rm -f Gemfile.lock | |
[root@localhost focus_mail]# bundle install | |
可能问题2 | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require': | |
/usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.4/lib/v8/init.so: | |
cannot restore segment prot after reloc: Permission denied | |
[root@localhost focus_mail]# vi /etc/sysconfig/selinux | |
修改为 :SELINUX=disabled | |
根据错误提示中的文件路径调整下面代码 | |
[root@localhost focus_mail]# chcon -t texrel_shlib_t /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.4/lib/v8/init.so | |
[root@localhost focus_mail]# | |
[root@localhost focus_mail]# rm -f Gemfile.lock | |
[root@localhost focus_mail]# bundle install | |
可能问题3 | |
[root@localhost focus_mail]# rails s | |
You're running a version of ruby with no Readline support | |
Please `gem install rb-readline` or recompile ruby --with-readline. | |
[root@localhost focus_mail]# yum install readline-devel | |
[root@localhost focus_mail]# gem install rb-readline | |
add the following line to your Gemfile: | |
gem 'rb-readline' | |
[root@localhost focus_mail]# rm -f Gemfile.lock | |
[root@localhost focus_mail]# bundle install | |
[root@localhost focus_mail]# rails s | |
=> Booting Thin | |
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000 | |
=> Call with -d to detach | |
=> Ctrl-C to shutdown server | |
SECURITY WARNING: No secret option provided to Rack::Session::Cookie. | |
This poses a security threat. It is strongly recommended that you | |
provide a secret to prevent exploits that may be possible from crafted | |
cookies. This will not be supported in future versions of Rack, and | |
future versions will even invalidate your existing user cookies. | |
>> Thin web server (v1.5.1 codename Straight Razor) | |
>> Maximum connections set to 1024 | |
>> Listening on 0.0.0.0:3000, CTRL+C to stop | |
按CTRL+C中断rails | |
8.安装nginx | |
[root@localhost focus_mail]# gem install passenger | |
[root@localhost focus_mail]# passenger-install-nginx-module | |
安装过程中需要有输入提示 | |
Enter your choice (1 or 2) or press Ctrl-C to abort: 1 | |
Please specify a prefix directory [/opt/nginx]: 回车 | |
测试passenger启动FocusMail | |
[root@localhost focus_mail]# passenger start | |
如果出现下面信息,按提示安装即可,安装完成后会继续启动FocusMail | |
Nginx core 1.2.6 isn't installed | |
Phusion Passenger Standalone will automatically install it into: | |
..... | |
..... | |
=============== Phusion Passenger Standalone web server started =============== | |
PID file: /home/work/focus_mail/tmp/pids/passenger.3000.pid | |
Log file: /home/work/focus_mail/log/passenger.3000.log | |
Environment: development | |
Accessible via: http://0.0.0.0:3000/ | |
You can stop Phusion Passenger Standalone by pressing Ctrl-C. | |
================================================================== | |
Ctrl-C 中断 | |
浏览器中输入平台ip,出现FocusMail登陆界面,表示FocusMail成功启动 | |
使用[email protected]/123456登陆 | |
查看log输出若有下面提示 | |
=============================================================================== | |
Rails Error: Unable to access log file. Please ensure that /home/work/focus_mail/log/development.log exists and is chmod 0666. | |
The log level has been raised to WARN and the output directed to STDERR until the problem is fixed | |
================================================================== | |
Ctrl-C 中断 | |
修改log权限 | |
[root@localhost focus_mail]# chmod 777 log/ | |
再次启动FocusMail查看输出 | |
[root@localhost focus_mail]# passenger start | |
修改FocusMail文件夹权限为webmail:webmail | |
若没有webmail:webmail群组或用户 | |
添加用户webmail | |
[root@localhost ~]# useradd webmail | |
添加用户群组webmail | |
[root@localhost ~]# groupadd webmail | |
groupadd:webmail 组已存在 | |
向webmail群组中添加webmail用户 | |
[root@localhost ~]# useradd -G webmail webmail | |
useradd:用户 webmail 已存在 | |
修改FocusMail文件夹所属群组为webmail:webmail | |
[root@localhost focus_mail]# chown -R webmail:webmail /home/work/focus_mail | |
passenger后台使用webmail运行FocusMail | |
[root@localhost focus_mail]# passenger start -p 80 -d --user webmail | |
=============== Phusion Passenger Standalone web server started =============== | |
PID file: /home/work/focus_mail/tmp/pids/passenger.80.pid | |
Log file: /home/work/focus_mail/log/passenger.80.log | |
Environment: development | |
Accessible via: http://0.0.0.0/ | |
Serving in the background as a daemon. | |
=============================================================================== | |
[root@localhost focus_mail]# | |
查看passenger是否启动 | |
[root@localhost focus_mail]# passenger status -p 80 | |
Phusion Passenger Standalone is running on PID 4555, according to PID file /home/work/focus_mail/tmp/pids/passenger.80.pid | |
[root@localhost focus_mail]# | |
如有需要重启passenger,需先暂停,然后再启动 | |
[root@localhost focus_mail]# passenger stop -p 80 | |
9.安装redis | |
[root@localhost focus_mail]# cd /home/tools | |
[root@localhost tools]# tar xzvf redis-2.4.16.tar.gz | |
[root@localhost tools]# cd redis-2.4.16 | |
[root@localhost redis-2.4.16]# make | |
[root@localhost redis-2.4.16]# make install | |
[root@localhost redis-2.4.16]# cp /home/tools/redis.conf /etc | |
启动redis | |
[root@localhost redis-2.4.16]# redis-server /etc/redis.conf | |
查看redis是否运行 | |
[root@localhost redis-2.4.16]# ps -ef | grep redis | |
root 14209 1 0 21:49 ? 00:00:00 redis-server /etc/redis.conf | |
root 14214 3375 0 21:49 pts/0 00:00:00 grep redis | |
[root@localhost redis-2.4.16]# cd /home/work | |
创建resque启动shell文件 | |
[root@localhost work]# vi focus_mail_resquework.sh | |
添加如下内容 | |
cd /home/work/focus_mail | |
nohup rake resque:workers COUNT=4 QUEUE=* VERBOSE=1 & | |
nohup rake resque:scheduler & | |
赋予权限 | |
[root@localhost work]# chmod +x focus_mail_start.sh | |
[root@localhost work]# chown webmail:webmail focus_mail_resquework.sh | |
切换至webmail用户启动 | |
[root@localhost work]# su webmail | |
[webmail@localhost work]$ | |
[webmail@localhost work]$ ./focus_mail_resquework.sh | |
nohup: appending output to “nohup.out” | |
nohup: appending output to “nohup.out” | |
查看后台是否运行 | |
[webmail@localhost work]$ ps -ef | grep resque | |
webmail 4412 1 26 05:45 pts/1 00:00:07 /usr/local/bin/ruby /usr/local/bin/rake resque:workers COUNT=4 QUEUE=* VERBOSE=1 | |
webmail 4413 1 32 05:45 pts/1 00:00:09 /usr/local/bin/ruby /usr/local/bin/rake resque:scheduler | |
webmail 4435 4412 18 05:45 pts/1 00:00:01 /usr/local/bin/ruby /usr/local/bin/rake resque:work | |
webmail 4441 4412 17 05:45 pts/1 00:00:01 /usr/local/bin/ruby /usr/local/bin/rake resque:work | |
webmail 4444 4412 15 05:45 pts/1 00:00:01 /usr/local/bin/ruby /usr/local/bin/rake resque:work | |
webmail 4446 4412 15 05:45 pts/1 00:00:01 /usr/local/bin/ruby /usr/local/bin/rake resque:work | |
webmail 4451 4372 0 05:46 pts/1 00:00:00 grep resque | |
[webmail@localhost work]$ | |
主要查看进程所属用户是否是webmail. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment