CentOS6.5上部署redmine程序

介紹:redmine是一個靈活的項目管理系統,是一個基於ruby on rails的框架開發的開源項目,可以跨平臺使用,而且支持多種數據庫。

具體細則,請大家參考官方網站:http://www.redmine.org/


系統:CentOS 6.5

所需軟件:redmine


下面的教程是在一個全新得系統上安裝redmine程序

首先,我們需要安裝以下的依賴關係

[root@ihuilian ~]#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


然後,安裝數據庫的相關軟件

[root@ihuilian ~]#yum install -y mysql mysql-server


啓動數據庫,並設爲開機自動啓動

[root@ihuilian ~]# chkconfig mysqld on
[root@ihuilian ~]# service mysqld start


設置MySQL數據庫的相關選項

[root@ihuilian ~]# 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

[root@ihuilian ~]# setenforce 0


開放iptables相關的端口,redmine默認啓動端口爲3000

[root@ihuilian ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT
[root@ihuilian ~]# iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT


安裝PHP和PHP相關插件

[root@ihuilian ~]# 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安裝

[root@ihuilian ~]# \curl -L https://get.rvm.io | bash


將rvm的命令加入到系統的環境變量中去

[root@ihuilian ~]# source /etc/profile.d/rvm.sh


安裝rubygems

[root@ihuilian ~]# yum install -y rubygems


移除ruby的官方源,使用淘寶的rubygems源

[root@ihuilian ~]# gem sources -a https://ruby.taobao.org/
[root@ihuilian ~]# gem sources --remove http://rubygems.org/
[root@ihuilian ~]# gem sources -l    #查看rubygems的源
*** CURRENT SOURCES *** 
https://ruby.taobao.org/


查看ruby的版本,然後,使用rvm安裝ruby

[root@ihuilian ~]# rvm list known
[root@ihuilian ~]# rvm install 1.9.3


查看安裝後的ruby的版本

[root@ihuilian ~]# ruby -v 
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]


爲redmine程序,創建一個新的數據庫

[root@ihuilian ~]# 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程序

[root@ihuilian ~]# mkdir /redmine 
[root@ihuilian ~]# cd /redmine/ 
[root@ihuilian redmine]# wget http://www.redmine.org/releases/redmine-2.5.0.tar.gz

解壓縮

[root@ihuilian redmine]# tar zxf redmine-2.5.0.tar.gz


在redmine的程序中,配置數據庫相關的信息

[root@ihuilian redmine]# ln -sv redmine-2.5.0 redmine
[root@ihuilian redmine]# cd redmine/config
[root@ihuilian 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相關庫的支持

[root@ihuilian redmine]# gem install bundler


此時,要修改redmine文件夾中的文件Gemfile 

[root@ihuilian redmine]# vim Gemfile
source 'https://ruby.taobao.org/'    #將源指向到淘寶的源

[root@ihuilian redmine]# bundle install
//如果不修改Gemfile文件,執行是不能成功的


生成一個session文件,在遷移中,這是很重要的一項,要指定原來的值

[root@ihuilian redmine]# rake generate_secret_token


爲redmine應用創建數據庫(確認這步執行成功了),在遷移過程中,此步驟是不需要執行的

[root@ihuilian redmine]#  RAILS_ENV=production rake db:migrate
[root@ihuilian redmine]#  RAILS_ENV=production rake redmine:load_default_data


創建一個文件夾,作爲redmine的存放目錄

[root@ihuilian ~]# mkdir  /redmine/files 
[root@ihuilian ~]# cd /redmine/redmine-2.5.0/config
[root@ihuilian config]# cp configuration.yml.example configuration.yml 
[root@ihuilian config]# vim configuration.yml
 attachments_storage_path: /redmine/files    #指定文件路徑


此時就可以啓動redmine程序了

[root@ihuilian redmine]# pwd 
/redmine 
[root@ihuilian redmine]# ruby redmine/script/rails server webrick -e production


通過瀏覽器訪問3000的端口

wKioL1SuJMOwR8AlAAEVTDEYbBc581.jpg到此,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

將上面的腳本寫到任務計劃中去

[root@ihuilian ~]# crontab -l
*/10 * * * * /bin/bash /redmine/redmine.sh &> /dev/null
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章