介绍:redmine是一个灵活的项目管理系统,是一个基于ruby on rails的框架开发的开源项目,可以跨平台使用,而且支持多种数据库。
具体细则,请大家参考官方网站:http://www.redmine.org/
系统:CentOS 6.5
所需软件:redmine
下面的教程是在一个全新得系统上安装redmine程序
首先,我们需要安装以下的依赖关系
[[email protected] ~]#yum -y install zip unzip libyaml-devel zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel gcc ruby-devel gcc-c++ make postgresql-devel ImageMagick-devel sqlite-devel perl-LDAP mod_perl perl-Digest-SHA
然后,安装数据库的相关软件
[[email protected] ~]#yum install -y mysql mysql-server
启动数据库,并设为开机自动启动
[[email protected] ~]# chkconfig mysqld on [[email protected] ~]# service mysqld start
设置MySQL数据库的相关选项
[[email protected] ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we‘ll need the current password for the root user. If you‘ve just installed MySQL, and you haven‘t set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from ‘localhost‘. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] n ... skipping. By default, MySQL comes with a database named ‘test‘ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you‘ve completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
禁用selinux
[[email protected] ~]# setenforce 0
开放iptables相关的端口,redmine默认启动端口为3000
[[email protected] ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT [[email protected] ~]# iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
安装PHP和PHP相关插件
[[email protected] ~]# yum -y install php php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc php-pecl-apc php-soap
下面,进入正题,安装我们的ruby了,首先,要安装一个rvm的命令行工具,它提供一个便捷的多版本切换和管理
rvm安装
[[email protected] ~]# \curl -L https://get.rvm.io | bash
将rvm的命令加入到系统的环境变量中去
[[email protected] ~]# source /etc/profile.d/rvm.sh
安装rubygems
[[email protected] ~]# yum install -y rubygems
移除ruby的官方源,使用淘宝的rubygems源
[[email protected] ~]# gem sources -a https://ruby.taobao.org/ [[email protected] ~]# gem sources --remove http://rubygems.org/ [[email protected] ~]# gem sources -l #查看rubygems的源 *** CURRENT SOURCES *** https://ruby.taobao.org/
查看ruby的版本,然后,使用rvm安装ruby
[[email protected] ~]# rvm list known [[email protected] ~]# rvm install 1.9.3
查看安装后的ruby的版本
[[email protected] ~]# ruby -v ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
为redmine程序,创建一个新的数据库
[[email protected] ~]# mysql -uroot -hlocalhost -phuilian123 mysql> create database redmine_db character set utf8; Query OK, 1 row affected (0.23 sec) mysql> grant all privileges on redmine_db.* to "redmine_admin"@"%.%.%.%" identified by "redmine_pass"; Query OK, 0 rows affected (0.14 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
接下来就是重点了,下载,并且安装redmine程序
[[email protected] ~]# mkdir /redmine [[email protected] ~]# cd /redmine/ [[email protected] redmine]# wget http://www.redmine.org/releases/redmine-2.5.0.tar.gz
解压缩
[[email protected] redmine]# tar zxf redmine-2.5.0.tar.gz
在redmine的程序中,配置数据库相关的信息
[[email protected] redmine]# ln -sv redmine-2.5.0 redmine [[email protected] redmine]# cd redmine/config [[email protected] config]# cp database.yml.example database.yml 修改如下 production: adapter: mysql2 database: redmine_db host: 192.168.74.128 username: redmine_admin password: "redmine_pass" encoding: utf8
安装rails相关库的支持
[[email protected] redmine]# gem install bundler
此时,要修改redmine文件夹中的文件Gemfile
[[email protected] redmine]# vim Gemfile source ‘https://ruby.taobao.org/‘ #将源指向到淘宝的源 [[email protected] redmine]# bundle install //如果不修改Gemfile文件,执行是不能成功的
生成一个session文件,在迁移中,这是很重要的一项,要指定原来的值
[[email protected] redmine]# rake generate_secret_token
为redmine应用创建数据库(确认这步执行成功了),在迁移过程中,此步骤是不需要执行的
[[email protected] redmine]# RAILS_ENV=production rake db:migrate [[email protected] redmine]# RAILS_ENV=production rake redmine:load_default_data
创建一个文件夹,作为redmine的存放目录
[[email protected] ~]# mkdir /redmine/files [[email protected] ~]# cd /redmine/redmine-2.5.0/config [[email protected] config]# cp configuration.yml.example configuration.yml [[email protected] config]# vim configuration.yml attachments_storage_path: /redmine/files #指定文件路径
此时就可以启动redmine程序了
[[email protected] redmine]# pwd /redmine [[email protected] redmine]# ruby redmine/script/rails server webrick -e production
通过浏览器访问3001的端口
到此,redmine程序的搭建就完成了
下面,提供redmine的一个监控脚本,如果redmine进程down了,通过任务计划的检查,将其重启
#!/bin/bash #this script in order to check the redmine , if it down ,make it start #date : 2015/1/6 #notice : any questions send mail to [email protected] #rvm environment source /etc/profile.d/rvm.sh #change to redmine‘s directoy RedmineDir=/redmine cd $RedmineDir mkdir logs #this redmine is listen on 3001 ListenPort=3001 ReturnCode=`ss -tlnp | grep "\<$ListenPort\>" &> /dev/null ; echo $?` if [ $ReturnCode -eq 0 ];then echo -e "\e[32mtime: `date +%F-%T`\e[m" >> logs/access.log echo -e "\e[35mredmine is running.\e[m" >> logs/access.log else nohup ruby redmine/script/rails server webrick -e production -p 3001 & echo -e "\e[32mtime: `date +%F-%T`\e[m">> logs/error.log echo -e "\e[31mredmine is down to running.\e[m" >> logs/error.log fi #now check the log file size,delete the file which is larger then 100MB cd ${RemineDir}logs for file in access.log error.log do Size=`ls -l $file | awk -F" " ‘{print $5}‘` if (( $Size >= 102400 ));then > $file fi done
将上面的脚本写到任务计划中去
[[email protected] ~]# crontab -l */10 * * * * /bin/bash /redmine/redmine.sh &> /dev/null