初始环境:
系统版本:centos 6.6
已安装LAMP
步骤:
1、ruby安装
mkdir -p /newdisk/software
wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz
tar xzf ruby-2.1.5.tar.gz
cd ruby-2.1.5
./configure --prefix=/usr/local/ruby
make && make install
2、将ruby添加到环境变量:
vi /etc/profile
export PATH=/usr/local/ruby/bin:$PATH
让变量生效:
. /etc/profile
3、安装gem:
wget http://production.cf.rubygems.org/rubygems/rubygems-2.4.5.tgz
tar xzf rubygems-2.4.5.tgz
cd rubygems-2.4.5
ruby setup.rb
提示:gem是一种文件组织的包,一般的ruby的很多插件都有由这种各种的包提供。
#gem -v
2.4.5
#which gem
/usr/local/ruby/bin/gem
由于国内网络原因,导致rubygems.org存放 Amazon S3上面的资源文件间歇性连接失败。所以你会遇到gem install
rack或bundle install的时候半天没有响应,具体可以用gem install rails
-V来查看执行过程。下面替换成淘宝的GEM镜像站:
#gem sources -l
- CURRENT SOURCES ***
https://rubygems.org/
#gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
#gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
#gem sources -l
- CURRENT SOURCES ***
https://ruby.taobao.org/
4、安装ralis,Redmine选择安装2.6版本,因此rails安装3.2版本
#gem install rails -v=3.2
- rails -v
Rails 3.2.0
5、安装Redmine2.6
yum -y install zip unzip libyaml-devel zlib-devel
curl-devel openssl-devel httpd-devel apr-devel apr-util-devel
mysql-devel gcc ruby-devel gcc-c++ make postgresql-devel
ImageMagick-devel sqlite-devel perl-LDAP mod_perl perl-Digest-SHA
wget http://www.redmine.org/releases/redmine-2.6.0.tar.gz
tar xzf redmine-2.6.0.tar.gz -C /newdisk
mv redmine-2.6.0 redmine
cd /newdisk/redmine
gem
install mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
#由于我的机器本来就装了mysql,所以配置文件路径得给我的mysql地址,如果您的机器没有装mysql,你可以不用加配置文件这个条件。
6、创建redmine数据库
/usr/local/mysql/bin/mysql -u root -p您的密码 #进入数据库
CREATE DATABASE redmine CHARACTER SET utf8; #创建数据库
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'my_password'; #创建用户
'localhost'; #给用户权限
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@
7、修改redmine数据库配置文件
cd /newdisk/redmine/config
cp database.yml.example database.yml
vi database.yml
修改为:
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: "密码" #填写redmine用户对应的密码
encoding: utf8
8、完成redmine依赖的所有ruby包:
cd ..
gem install bundler
bundle install #如果中途遇见错误,那么就按照提示安装相应的包
如果遇到这样的错误:
An error occurred while installing mysql2 (0.3.19), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.19'` succeeds before bundling.
解决办法:
yum install mysql-devel
9、为Rails生成cookies秘钥:
rake generate_secret_token
10、创建数据库结构
RAILS_ENV=production rake db:migrate
遇到这样的错误:Mysql2::Error: Can't connect to local MySQL server through socket /var/lib/mysql/mysql.sock
原因是:由于我的机器中已经安装了mysql,而且默认的sock文件是/tmp/mysql.sock而不是/var/lib/mysql/mysql.sock
解决办法:ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
11、生成缺省数据:
RAILS_ENV=production REDMINE_LANG=zh rake redmine:load_default_data
12、调整文件系统权限:
cd /newdisk/redmine
mkdir -p tmp tmp/pdf public/plugin_assets #备注:tmp和tmp/pdf (若不存在则创建该路径,用于生成 PDF 文件);public/plugin_assets (若不存在则创建该路径,plugins资源)
chown -R www.www /newdisk/redmine
13、启动服务,测试
su www -c "ruby script/rails server webrick -e production -d"
iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
浏览器中输入地址:http://IP:3000
缺省管理员用户:
login: admin
password: admin
14、关联redmine和svn:
进入Redmine目录下Config,有文件“configuration.yml.example”,复制该文件重命名“configuration.yml”,修改其中的SVN配置
scm_subversion_command: svn # (default: svn),
登录redmine后台,管理-》项目-》选择某个项目-》选择版本库选项卡。在SCM中选择Subversion,填入URL,填入登录名和密码(填写svn的用户名和密码)。然后在前台查看这个项目,会有版本库菜单,点击即可显示此项目对应的版本库信息。
15、配置邮件通知:
cd /newdisk/redmine/config
cp configuration.yml.example configuration.yml
vi configuration.yml
default:
email_delivery:
delivery_method: :async_smtp
smtp_settings:
tls: false
address: "smtp.163.com"
enable_starttls_auto: true
port: 25
authentication: :login
domain: 'smtp.163.com'
user_name: 'surmount_zhoujp@163.com' #邮箱登录名
password: '' #密码
production:
email_delivery:
delivery_method: :async_smtp
smtp_settings:
tls: false
address: "smtp.163.com"
enable_starttls_auto: true
port: 25
authentication: :login
domain: 'smtp.163.com'
user_name: 'surmount_zhoujp@163.com' #邮箱登录名
password: '' #密码
页面配置:
邮件发件人地址,要和配置文件中的一直。
16、配置redmine和Apache整合
16.1、安装Passenger(用于整合Apache)
gem install passenger
passenger-install-apache2-module
16.2、为Apache安装fastcgi模块
wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
tar zxf mod_fastcgi-2.4.6.tar.gz
cd mod_fastcgi-2.4.6
wget http://blog.linuxeye.com/wp-content/uploads/2014/12/byte-compile-against-apache24.diff
patch
-p1 < byte-compile-against-apache24.diff
#apache2.4下安装mod_fastcgi 2.4.6,需要打补丁,如果没有patch命令,需要安装patch,命令如下:yum
install patch -y
cp Makefile.AP2 Makefile
vi Makefile #将Makefile中的路径改成你的apache的安装路径
make && make install #安装成功后,会自动把mod_fastcgi.so复制到/usr/local/apache/modules目录
16.3、配置apache
vi /etc/httpd/httpd.conf #在结尾添加以下行
LoadModule passenger_module /usr/local/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.15/buildout/apache2/mod_passenger.so
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.15
PassengerDefaultRuby /usr/local/ruby/bin/ruby
</IfModule>
找到以下行,去掉前面的“#”号:
Include /etc/httpd/extra/httpd-vhosts.conf
vi /etc/httpd/extra/httpd-vhosts.conf #增加如下行
<VirtualHost *:80>
ServerName 192.168.2.44
DocumentRoot /newdisk/hongyantu/redmine/public
ErrorLog "/newdisk/hongyantu/redmine/logs/error_redmine.log"
CustomLog "/newdisk/hongyantu/redmine/logs/access_redmine.log" common
<Directory /newdisk/hongyantu/redmine/public>
Options FollowSymlinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
16.4、配置完成后,重启apache并验证:
/usr/local/apache2/bin/apachectl restart #重启apache
验证:浏览器中直接输入http://IP即可,例如http://192.168.2.44,看到如下结果就成功了