CentOS7.5上用Apache运行Redmine

之前已安装redmine,但它默认的WEB服务软件是WEBrick,这个是Rails开发测试用的服务器,性能很差。之前就发现打开响应特别慢,今天又出问题:只要在redmine上登录用户就卡死无响应,一气之下就想换apache来运行redmine。说干就干,下面就来记叙改造过程。

安装Apache

我下载的是apache2.4.33,在运行./configure命令时,报了error: APR not found.

原来是要安装如下软件包:

wget http://archive.apache.org/dist/apr/apr-1.6.3.tar.gz

wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz

wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz

具体步骤如下:

安装apr

[root@xt test]# tar -zxf apr-1.6.3.tar.gz
[root@xt test]# cd apr-1.6.3
[root@xt apr-1.6.3]# ./configure –prefix=/usr/local/apr
[root@xt apr-1.6.3]# make && make install

Centos7还需要装:
yum install expat-devel

安装APR-util

[root@xt test]# tar -zxf apr-util-1.6.1.tar.gz
[root@xt test]# cd apr-util-1.6.1
[root@xt apr-util-1.6.1]# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
[root@xt apr-util-1.6.1]# make && make install

安装pcre

[root@xt test]#tar -zxf pcre-8.42.tar.gz
[root@xt test]#cd pcre-8.42
[root@xt pcre-8.42]#./configure –prefix=/usr/local/pcre
[root@xt pcre-8.42]#make && make install

编译Apache

cd httpd-2.4.33

./configure –prefix=/usr/local/apache2.4.33 \
–with-apr=/usr/local/apr \
–with-apr-util=/usr/local/apr-util/ \
–with-pcre=/usr/local/pcre \
–enable-deflate \
–enable-expires \
–enable-headers \
–enable-modules=most \
–enable-so \
–with-mpm=worker \
–enable-rewrite

make

如果make过程中有如下报错:
collect2: ld returned 1 exit status make[2]: *** [htpasswd] խϳ 1 make[2]: Leaving
则可尝试安装libtools-ltdl-devel解决。

如果不行,将apr目录拷贝到httpd下:
cp -r apr-1.5.2 httpd-2.4.33/srclib/apr

然后运行:

./configure --prefix=/usr/local/apache2.4.33 \
--with-included-apr
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--with-pcre=/usr/local/pcre \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm=worker \
--enable-rewrite

再:

make install

配置apache

useradd apache -s /sbin/nologin

vim /usr/local/apache/conf/httpd.conf

改如下参数:

User apache

Group apache

ServerName 127.0.0.1:80  #前面的注释符去掉

Listen 80

Listen 3000

DirectoryIndex index.html index.php index.htm

Include conf/extra/httpd-vhosts.conf

运行apache服务:
vim /usr/lib/systemd/system/httpd.service

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking

EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/local/apache2/bin/apachectl start
ExecReload=/usr/local/apache2/bin/apachectl graceful
ExecStop=/usr/local/apache2/bin/apachectl stop
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

一般装完上述文件已存在,只要参照修改一下就行。

开启服务:systemctl start httpd
关闭服务:systemctl stop httpd

加入自启动功能:systemctl enable httpd

整合Redmine和Apache

设置redmine文件权限:

cd /usr/local/redmine

chown -R apache:apache files log tmp public/plugin_assets
chmod -R 755 files log tmp public/plugin_assets

安装httpd httpd-devel 

yum install -y httpd httpd-devel

绑定apache

gem install passenger

yum install libcurl-devel -y

passenger-install-apache2-module  #根据提示操作

在/usr/local/apache/conf/httpd.conf中加入:

LoadModule passenger_module /usr/local/rvm/gems/ruby-2.4.1/gems/passenger-5.3.2/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.4.1/gems/passenger-5.3.2
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.4.1/wrappers/ruby
</IfModule>

在/usr/local/apache/conf/httpd.conf中:

去掉两行注释,开启vhosts功能:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf

去掉ServerName注释:
ServerName www.testhost.com:80

 

在/usr/local/apache/conf/extra/httpd-vhosts.conf中:
<VirtualHost *:3000>
ServerAdmin nowguy@qq.com
DocumentRoot “/usr/local/redmine/public”
ServerName redmine.testhost.com
ServerAlias redmine.testhostalias.com
ErrorLog “logs/redmine-error_log”
CustomLog “logs/redmine-access_log” common

<Directory “/usr/local/redmine/public”>
AllowOverride None
Options None
Require all granted
</Directory>
</VirtualHost>

重启Aphache:

/usr/local/apache/bin/apachectl graceful

在浏览器中输入http://IP:3000即可看到网页了。

这里有个问题,涉及添加修改用户的页面给775的权限都不能打开,只好把files、 log 、tmp 、public设置成777才行。照理用apache用户访问的话前者权限就够了。因为只是个人在用,这个问题先放放,如果有知道的朋友麻烦留言告之,谢谢!