如何在 Ubuntu 16.04 上安装 OTRS (开源问题单系统)
OTRS ,即开源问题单(ticket)申请系统,是一个用于客户服务、帮助台和 IT 服务管理的开源问题单软件。该软件是用 Perl 和 javascript 编写的。对于那些需要管理票据、投诉、支持请求或其他类型的报告的公司和组织来说,这是一个问题单解决方案。OTRS 支持包括 MySQL、PostgreSQL、Oracle 和 SQL Server 在内的多个数据库系统,它是一个可以安装在 Windows 和 Linux 上的多平台软件。
在本教程中,我将介绍如何在 Ubuntu 16.04 上安装和配置 OTRS。我将使用 PostgreSQL 作为 OTRS 的数据库,将 Apache Web 服务器用作 Web 服务器。
先决条件
- Ubuntu 16.04。
- 最小 2GB 的内存。
- root 权限
步骤 1 - 安装 Apache 和 PostgreSQL
在第一步中,我们将安装 Apache Web 服务器以及 PostgreSQL。我们将从 ubuntu 仓库中使用最新的版本。
使用 SSH 登录到你的 Ubuntu 服务器中:
<span class="kwd">ssh</span><span class="pln"> root@192</span><span class="pun">.</span><span class="lit">168.33</span><span class="pun">.</span><span class="lit">14</span>
更新 Ubuntu 仓库。
<span class="kwd">sudo</span><span class="kwd">apt-get</span><span class="pln"> update</span>
使用 apt 安装 Apache2 以及 PostgreSQL:
<span class="kwd">sudo</span><span class="kwd">apt-get</span><span class="pln"> install </span><span class="pun">-</span><span class="pln">y apache2 libapache2</span><span class="pun">-</span><span class="pln">mod</span><span class="pun">-</span><span class="pln">perl2 postgresql</span>
通过检查服务器端口确保 Apache 以及 PostgreSQL 运行了。
<span class="kwd">netstat</span><span class="pun">-</span><span class="pln">plntu</span>
Install Apache and PostgreSQL
你可以看到 80 端口被 apache 使用了,5432 端口被 postgresql 数据库使用了。
步骤 2 - 安装 Perl 模块
OTRS 基于 Perl,因此我们需要安装一些 OTRS 需要的 Perl 模块。
使用这个 apt 命令安装 perl 模块:
<span class="kwd">sudo</span><span class="kwd">apt-get</span><span class="pln"> install </span><span class="pun">-</span><span class="pln">y libapache2</span><span class="pun">-</span><span class="pln">mod</span><span class="pun">-</span><span class="pln">perl2 libdbd</span><span class="pun">-</span><span class="kwd">pg</span><span class="pun">-</span><span class="pln">perl libnet</span><span class="pun">-</span><span class="pln">dns</span><span class="pun">-</span><span class="pln">perl libnet</span><span class="pun">-</span><span class="pln">ldap</span><span class="pun">-</span><span class="pln">perl libio</span><span class="pun">-</span><span class="pln">socket</span><span class="pun">-</span><span class="pln">ssl</span><span class="pun">-</span><span class="pln">perl libpdf</span><span class="pun">-</span><span class="pln">api2</span><span class="pun">-</span><span class="pln">perl libsoap</span><span class="pun">-</span><span class="pln">lite</span><span class="pun">-</span><span class="pln">perl libgd</span><span class="pun">-</span><span class="pln">text</span><span class="pun">-</span><span class="pln">perl libgd</span><span class="pun">-</span><span class="pln">graph</span><span class="pun">-</span><span class="pln">perl libapache</span><span class="pun">-</span><span class="pln">dbi</span><span class="pun">-</span><span class="pln">perl libarchive</span><span class="pun">-</span><span class="pln">zip</span><span class="pun">-</span><span class="pln">perl libcrypt</span><span class="pun">-</span><span class="pln">eksblowfish</span><span class="pun">-</span><span class="pln">perl libcrypt</span><span class="pun">-</span><span class="pln">ssleay</span><span class="pun">-</span><span class="pln">perl libencode</span><span class="pun">-</span><span class="pln">hanextra</span><span class="pun">-</span><span class="pln">perl libjson</span><span class="pun">-</span><span class="pln">xs</span><span class="pun">-</span><span class="pln">perl libmail</span><span class="pun">-</span><span class="pln">imapclient</span><span class="pun">-</span><span class="pln">perl libtemplate</span><span class="pun">-</span><span class="pln">perl libtemplate</span><span class="pun">-</span><span class="pln">perl libtext</span><span class="pun">-</span><span class="pln">csv</span><span class="pun">-</span><span class="pln">xs</span><span class="pun">-</span><span class="pln">perl libxml</span><span class="pun">-</span><span class="pln">libxml</span><span class="pun">-</span><span class="pln">perl libxml</span><span class="pun">-</span><span class="pln">libxslt</span><span class="pun">-</span><span class="pln">perl libpdf</span><span class="pun">-</span><span class="pln">api2</span><span class="pun">-</span><span class="pln">simple</span><span class="pun">-</span><span class="pln">perl libyaml</span><span class="pun">-</span><span class="pln">libyaml</span><span class="pun">-</span><span class="pln">perl</span>
安装完成后,我们需要为 apache 激活 Perl 模块,接着重启 apache 服务。
<span class="pln">a2enmod perl</span>
<span class="kwd">systemctl</span><span class="pln"> restart apache2</span>
接下来,使用下面的命令检查模块是否已经加载了:
<span class="pln">apachectl </span><span class="pun">-</span><span class="pln">M </span><span class="pun">|</span><span class="kwd">sort</span>
Enable Apache Perl Module
你可以在 “Loaded Modules” 部分下看到 perl_module。
步骤 3 - 为 OTRS 创建新用户
OTRS 是一个基于 web 的程序并且运行与 apache web 服务器下。为了安全,我们需要以普通用户运行它,而不是 root 用户。
使用 useradd 命令创建一个 otrs
新用户:
<span class="kwd">useradd</span><span class="pun">-</span><span class="pln">r </span><span class="pun">-</span><span class="pln">d </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs </span><span class="pun">-</span><span class="pln">c </span><span class="str">'OTRS User'</span><span class="pln"> otrs</span>
-r
:将用户作为系统用户。-d /opt/otrs
:在/opt/otrs
下放置新用户的主目录。-c
:备注。
接下来,将 otrs
用户加入到 www-data
用户组,因为 apache 运行于 www-data
用户及用户组。
<span class="kwd">usermod</span><span class="pun">-</span><span class="pln">a </span><span class="pun">-</span><span class="pln">G www</span><span class="pun">-</span><span class="pln">data otrs</span>
在 /etc/passwd
文件中已经有 otrs
用户了。
<span class="kwd">grep</span><span class="pun">-</span><span class="pln">rin otrs </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="kwd">passwd</span>
Create new user for OTRS
OTRS 的新用户已经创建了。
步骤 4 - 创建和配置数据库
在这节中,我们会为 OTRS 系统创建一个新 PostgreSQL 数据库,并对 PostgreSQL 数据库的配置做一些小的更改。
登录到 postgres
用户并访问 PostgreSQL shell。
<span class="kwd">su</span><span class="pun">-</span><span class="pln"> postgres</span>
<span class="pln">psql</span>
创建一个新的角色 otrs
,密码是 myotrspw
,并且是非特权用户。
<span class="pln">create user otrs password </span><span class="str">'myotrspw'</span><span class="pln"> nosuperuser</span><span class="pun">;</span>
接着使用 otrs
用户权限创建一个新的 otrs
数据库:
<span class="pln">create database otrs owner otrs</span><span class="pun">;</span>
<span class="pln">\q</span>
接下来为 otrs
角色验证编辑 PostgreSQL 配置文件。
<span class="kwd">vim</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">postgresql</span><span class="pun">/</span><span class="lit">9.5</span><span class="pun">/</span><span class="pln">main</span><span class="pun">/</span><span class="pln">pg_hba</span><span class="pun">.</span><span class="pln">conf</span>
在 84 行后粘贴下面的配置:
<span class="kwd">local</span><span class="pln"> otrs otrs password</span>
<span class="pln">host otrs otrs </span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pun">/</span><span class="lit">32</span><span class="pln"> password</span>
保存文件并退出 vim
Database Authentication OTRS
使用 exit
回到 root 权限并重启 PostgreSQL:
<span class="kwd">exit</span>
<span class="kwd">systemctl</span><span class="pln"> restart postgresql</span>
PostgreSQL 已经为 OTRS 的安装准备好了。
Configure PostgreSQL for OTRS
步骤 5 - 下载和配置 OTRS
在本教程中,我们会使用 OTRS 网站中最新的版本。
进入 /opt
目录并使用 wget
命令下载 OTRS 5.0:
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span>
<span class="kwd">wget</span><span class="pln"> http</span><span class="pun">:</span><span class="com">//ftp.otrs.org/pub/otrs/otrs-5.0.16.tar.gz</span>
展开该 otrs 文件,重命名目录并更改所有 otrs 的文件和目录的所属人为 otrs
。
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">xzvf otrs</span><span class="pun">-</span><span class="lit">5.0</span><span class="pun">.</span><span class="lit">16.tar</span><span class="pun">.</span><span class="pln">gz</span>
<span class="kwd">mv</span><span class="pln"> otrs</span><span class="pun">-</span><span class="lit">5.0</span><span class="pun">.</span><span class="lit">16</span><span class="pln"> otrs</span>
<span class="kwd">chown</span><span class="pun">-</span><span class="pln">R otrs</span><span class="pun">:</span><span class="pln">otrs otrs</span>
接下来,我们需要检查系统并确保可以安装 OTRS 了。
使用下面的 otrs 脚本命令检查 OTRS 安装需要的系统软件包:
<span class="str">/opt/</span><span class="pln">otrs</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="typ">CheckModules</span><span class="pun">.</span><span class="pln">pl</span>
确保所有的结果是对的,这意味着我们的服务器可以安装 OTRS 了。
OTRS Chek Module needed for Installation
OTRS 已下载,并且我们的服务器可以安装 OTRS 了。
接下,进入 otrs 目录并复制配置文件。
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">/</span>
<span class="kwd">cp</span><span class="typ">Kernel</span><span class="pun">/</span><span class="typ">Config</span><span class="pun">.</span><span class="pln">pm</span><span class="pun">.</span><span class="pln">dist </span><span class="typ">Kernel</span><span class="pun">/</span><span class="typ">Config</span><span class="pun">.</span><span class="pln">pm</span>
使用 vim 编辑 Config.pm
文件:
<span class="kwd">vim</span><span class="typ">Kernel</span><span class="pun">/</span><span class="typ">Config</span><span class="pun">.</span><span class="pln">pm</span>
更改 42 行的数据库密码:
<span class="pln">$Self</span><span class="pun">->{</span><span class="typ">DatabasePw</span><span class="pun">}</span><span class="pun">=</span><span class="str">'myotrspw'</span><span class="pun">;</span>
注释 45 行的 MySQL 数据库支持:
<span class="com">#</span><span class="pln"> $Self</span><span class="pun">->{</span><span class="typ">DatabaseDSN</span><span class="pun">}</span><span class="pun">=</span><span class="str">"DBI:mysql:database=$Self->{Database};host=$Self->{DatabaseHost};"</span><span class="pun">;</span>
取消注释 49 行的 PostgreSQL 数据库支持:
<span class="pln">$Self</span><span class="pun">->{</span><span class="typ">DatabaseDSN</span><span class="pun">}</span><span class="pun">=</span><span class="str">"DBI:Pg:dbname=$Self->{Database};"</span><span class="pun">;</span>
保存文件并退出 vim。
接着编辑 apache 启动文件来启用 PostgreSQL 支持。
<span class="kwd">vim</span><span class="pln"> scripts</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">-</span><span class="pln">perl</span><span class="pun">-</span><span class="pln">startup</span><span class="pun">.</span><span class="pln">pl</span>
取消注释 60 和 61 行:
<span class="com">#</span><span class="pln"> enable </span><span class="kwd">this</span><span class="kwd">if</span><span class="pln"> you </span><span class="kwd">use</span><span class="pln"> postgresql</span>
<span class="kwd">use</span><span class="pln"> DBD</span><span class="pun">::</span><span class="typ">Pg</span><span class="pun">();</span>
<span class="kwd">use</span><span class="typ">Kernel</span><span class="pun">::</span><span class="typ">System</span><span class="pun">::</span><span class="pln">DB</span><span class="pun">::</span><span class="pln">postgresql</span><span class="pun">;</span>
保存文件并退出编辑器。
最后,检查缺失的依赖和模块。
<span class="pln">perl </span><span class="pun">-</span><span class="pln">cw </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">cgi</span><span class="pun">-</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">index</span><span class="pun">.</span><span class="pln">pl</span>
<span class="pln">perl </span><span class="pun">-</span><span class="pln">cw </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">cgi</span><span class="pun">-</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">customer</span><span class="pun">.</span><span class="pln">pl</span>
<span class="pln">perl </span><span class="pun">-</span><span class="pln">cw </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="typ">Console</span><span class="pun">.</span><span class="pln">pl</span>
你可以在下面的截图中看到结果是 “OK”:
Check all modules again
步骤 6 - 导入样本数据库
在本教程中,我们会使用样本数据库,这可以在脚本目录中找到。因此我们只需要将所有的样本数据库以及表结构导入到第 4 步创建的数据库中。
登录到 postgres
用户并进入 otrs 目录中。
<span class="kwd">su</span><span class="pun">-</span><span class="pln"> postgres</span>
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">/</span>
作为 otrs 用户使用 psql
命令插入数据库以及表结构。
<span class="pln">psql </span><span class="pun">-</span><span class="pln">U otrs </span><span class="pun">-</span><span class="pln">W </span><span class="pun">-</span><span class="pln">f scripts</span><span class="pun">/</span><span class="pln">database</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">-</span><span class="pln">schema</span><span class="pun">.</span><span class="pln">postgresql</span><span class="pun">.</span><span class="pln">sql otrs</span>
<span class="pln">psql </span><span class="pun">-</span><span class="pln">U otrs </span><span class="pun">-</span><span class="pln">W </span><span class="pun">-</span><span class="pln">f scripts</span><span class="pun">/</span><span class="pln">database</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">-</span><span class="pln">initial_insert</span><span class="pun">.</span><span class="pln">postgresql</span><span class="pun">.</span><span class="pln">sql otrs</span>
<span class="pln">psql </span><span class="pun">-</span><span class="pln">U otrs </span><span class="pun">-</span><span class="pln">W </span><span class="pun">-</span><span class="pln">f scripts</span><span class="pun">/</span><span class="pln">database</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">-</span><span class="pln">schema</span><span class="pun">-</span><span class="pln">post</span><span class="pun">.</span><span class="pln">postgresql</span><span class="pun">.</span><span class="pln">sql otrs</span>
在需要的时候输入数据库密码 myotrspw
。
Import OTRS Sample Database
步骤 7 - 启动 OTRS
数据库以及 OTRS 已经配置了,现在我们可以启动 OTRS。
将 otrs 的文件及目录权限设置为 www-data
用户和用户组。
<span class="str">/opt/</span><span class="pln">otrs</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="typ">SetPermissions</span><span class="pun">.</span><span class="pln">pl </span><span class="pun">--</span><span class="pln">otrs</span><span class="pun">-</span><span class="pln">user</span><span class="pun">=</span><span class="pln">www</span><span class="pun">-</span><span class="pln">data </span><span class="pun">--</span><span class="pln">web</span><span class="pun">-</span><span class="pln">group</span><span class="pun">=</span><span class="pln">www</span><span class="pun">-</span><span class="pln">data</span>
通过创建一个新的链接文件到 apache 虚拟主机目录中启用 otrs apache 配置。
<span class="kwd">ln</span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">/</span><span class="pln">scripts</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">-</span><span class="pln">httpd</span><span class="pun">.</span><span class="kwd">include</span><span class="pun">.</span><span class="pln">conf </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="pln">conf</span>
启用 otrs 虚拟主机并重启 apache。
<span class="pln">a2ensite otrs</span>
<span class="kwd">systemctl</span><span class="pln"> restart apache2</span>
确保 apache 启动没有错误。
Enable OTRS Apache Virtual Host
步骤 8 - 配置 OTRS 计划任务
OTRS 已经安装并运行在 Apache Web 服务器中了,但是我们仍然需要配置 OTRS 计划任务。
登录到 otrs
用户,接着以 otrs 用户进入 var/cron
目录。
<span class="kwd">su</span><span class="pun">-</span><span class="pln"> otrs</span>
<span class="kwd">cd</span><span class="kwd">var</span><span class="pun">/</span><span class="kwd">cron</span><span class="pun">/</span>
<span class="kwd">pwd</span>
使用下面的命令复制所有 .dist
计划任务脚本:
<span class="kwd">for</span><span class="pln"> foo </span><span class="kwd">in</span><span class="pun">*.</span><span class="pln">dist</span><span class="pun">;</span><span class="kwd">do</span><span class="kwd">cp</span><span class="pln"> $foo </span><span class="str">`basename $foo .dist`</span><span class="pun">;</span><span class="kwd">done</span>
使用 exit
回到 root 权限,并使用 otrs 用户启动计划任务脚本。
<span class="kwd">exit</span>
<span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="typ">Cron</span><span class="pun">.</span><span class="pln">sh start otrs</span>
Enable OTRS Cron
接下来,手动收取电子邮件的 PostMaster 创建一个新的计划任务。我会配置为每 2 分钟收取一次邮件。
<span class="kwd">su</span><span class="pun">-</span><span class="pln"> otrs</span>
<span class="pln">crontab </span><span class="pun">-</span><span class="pln">e</span>
粘贴下面的配置:
<span class="pun">*</span><span class="str">/2 * * * * $HOME/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="typ">PostMasterMailbox</span><span class="pun">.</span><span class="pln">pl </span><span class="pun">>></span><span class="str">/dev/</span><span class="kwd">null</span>
保存并退出。
现在停止 otrs 守护进程并再次启动。
<span class="pln">bin</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="typ">Daemon</span><span class="pun">.</span><span class="pln">pl stop</span>
<span class="pln">bin</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="typ">Daemon</span><span class="pun">.</span><span class="pln">pl start</span>
Enable OTRS Fetching Email
OTRS 安装以及配置完成了。
步骤 9 - 测试 OTRS
打开你的 web 浏览器并输入你的服务器 IP 地址: http://192.168.33.14/otrs/
使用默认的用户 root@localhost
以及密码 root
登录。
Installation Successfully OTRS Home Page
使用默认的 root 账户你会看到一个警告。点击警告信息来创建一个新的 admin root 用户。
下面是用另外的 admin root 用户登录后出现的 admin 页面,这里没有出现错误信息。
OTRS Admin Dashboard Without Error Messages
如果你想作为客户登录,你可以使用 customer.pl
:http://192.168.33.14/otrs/customer.pl
你会看到客户登录界面,输入客户的用户名和密码。
OTRS Customer Login Page
下面是一个创建新单据的客户页面。
Customer Open Ticket
步骤 10 - 疑难排查
如果你仍旧看到 “OTRS Daemon is not running” 的错误,你可以像这样调试 OTRS 守护进程。
<span class="kwd">su</span><span class="pun">-</span><span class="pln"> otrs</span>
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">/</span>
停止 OTRS 守护进程:
<span class="pln">bin</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="typ">Daemon</span><span class="pun">.</span><span class="pln">pl stop</span>
使用 --debug
选项启动 OTRS 守护进程。
<span class="pln">bin</span><span class="pun">/</span><span class="pln">otrs</span><span class="pun">.</span><span class="typ">Daemon</span><span class="pun">.</span><span class="pln">pl start </span><span class="pun">--</span><span class="pln">debug</span>
参考
- http://wiki.otterhub.org/index.php?title=InstallationonDebian6with_Postgres
- http://www.geoffstratton.com/otrs-installation-5011-ubuntu-1604
- https://www.linkedin.com/pulse/ticketing-system-otrs-ubuntu-1404-muhammad-faiz-khan
作者:Muhammad Arul 译者:geekpi 校对:wxy