ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

搭配Phabricator服务端

2021-01-22 14:03:55  阅读:280  来源: 互联网

标签:sudo phabricator Phabricator 搭配 hostname git ssh ubuntu 服务端


一、概述

1. 官方链接

(1)用Phabricator管理的Phabricator开发
(2)Phabricator服务端的官方安装文档
(3)相关项目的GitHub地址

2. 简单介绍

Phabricator由两个项目组成:phabricatorarcanist,主要使用PHP开发,数据库使用MySQL,服务器可选ApacheNginx等Web服务器,代码仓库可选GitSVN

注:之前的第三个项目libphutil不再独立,而是整合到以上两个项目中。

3. 环境说明

Phabricator服务端目前支持在Windows上部署。

根据自己选的OS来安装以上提到的软件。除软件的安装外,其他的配置操作应当和本文一样,只是相关配置文件的位置由你的OS和Phabricator版本决定。

本文使用的Phabricator版本时间戳2021-01-16,使用的操作系统如下:

# 查看主机的全部信息:系统架构、操作系统等
ubuntu@hostname: uname -a
Linux ubuntu 5.4.0-1015-raspi @15-Ubuntu SMP Fri Jul 10 05:34:24 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux

# 查看Ubuntu的具体版本,该命令可能要自己安装
ubuntu@hostname: lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

配置较长,建议先总览一遍;遇到问题,建议查看官方文档。

二、搭建

1. 准备PHP环境

PHP的版本需要>=v5.2,但不含v7.0,本文使用v7.1

# 使用指定的语言和编码从php官方库获取相关包,而不是从ubuntu的镜像缓存
ubuntu@hostname: sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php

ubuntu@hostname: sudo apt-get update

# 安装v7.1,和下载所有将要使用的依赖包
ubuntu@hostname: sudo apt-get -y install php7.1 php7.1-mysql php7.1-fpm php7.1-curl php7.1-xml php7.1-mcrypt php7.1-json php7.1-gd php7.1-mbstring

ubuntu@hostname: php -v

# 修改fpm的配置,修改内容如下添加两行自定义配置
ubuntu@hostname: sudo vim /etc/php/7.1/fpm/pool.d/www.conf
......
; Note: This value is mandatory.
listen = /run/php/php7.1-fpm.sock
listen = 9000 # 增加
listen.allowed_clients = 127.0.0.1 # 增加
......

# 重启PHP
ubuntu@hostname: sudo service php7.1-fpm reload

# 查看配置是否生效
ubuntu@hostname: netstat -na | grep 9000
tcp6       0      0 :::9000                 :::*                    LISTEN

2. 安装版本控制工具

如果你想使用远程仓库可以跳过此步骤。Git在本机上是可选的,它可以用来clone项目和作为Phabricator本地仓库的管理工具,或者选择安装SVN。

# 查看是否已安装
ubuntu@hostname: git --version

# 安装命令,版本无要求
ubuntu@hostname: sudo apt-get install git

3. Clone项目

使用本文Ubuntu自带的Git进行clone,你也可以手动下载压缩包进行解压操作,用Git管理的另一个好处是方便升级Phabricator。

# 创建项目存放目录
ubuntu@hostname: sudo mkdir /var/www/phab/

# 在该目录下clone相关项目
ubuntu@hostname: sudo git clone https://github.com/phacility/arcanist.git
ubuntu@hostname: sudo git clone https://github.com/phacility/phabricator.git

4. 安装Web服务器

本文使用Nginx服务器。

# 简单安装,无版本要求
ubuntu@hostname: sudo apt-get install nginx

ubuntu@hostname: nginx -v

# 查看是否已自启动,打印多行记录即为已启动
ubuntu@hostname: ps -aux | grep nginx

# 手动启动nginx
ubuntu@hostname: sudo service nginx start

在另一台同局域网主机上用浏览器访问本机IP,如无法访问,请检查本机80端口是否被墙。

# 修改项目目录所有者,让Web服务器进程能够访问该目录,此处是Nginx用户名为www-data的进程
ubuntu@hostname: sudo chown -R www-data:www-data /var/www/phab

添加Web服务的配置文件,不同的web服务器配置不同,具体参阅官方安装文档。以下是Nginx的配置。

你可以设置域名或IP访问,也可以同时设置。例如,你想通过浏览器访问域名phabricator.your.domain和IPv4xx.xx.xx.xx都能生效,需要在/etc/nginx/conf.d/下分别添加对应的配置文件phabricator.your.domain.confxx.xx.xx.xx.conf,文件内容如下(非80端口要加端口号):

server {
  server_name xxx.xxx.xxx.xxx; # 配置域名或IP
  root        /var/www/phab/phabricator/webroot; # 配置Web根目录

  location / {
    index   index.php;
    rewrite ^/(.*)$ /index.php?__path__=/$1 last;
  }

  location /index.php {
    fastcgi_pass    localhost:9000;
    fastcgi_index   index.php;

    #required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;

    #variables to make the $_SERVER populate in PHP
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;

    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

    fastcgi_param  REMOTE_ADDR        $remote_addr;
  }
}

重启Nginx使配置生效

ubuntu@hostname: sudo service nginx restart

5. 安装MySQL

官方推荐版本>=v5.5,使用v8.x系列的需要注意新版本的特性,如密码修改完全不同。

# 如要求输入密码,按照提示完成
ubuntu@hostname: sudo apt install mysql-server

ubuntu@hostname: mysql --version

如果安装过程未提示输入root密码,直接安装完成,根据自己的版本查找如何修改密码即可。

# 进入Phabricator项目目录
ubuntu@hostname: cd /var/www/phab/phabricator

# 设置MySQL密码让Phabricator可以访问数据库
ubuntu@hostname: sudo ./bin/config set mysql.pass "mysql-root-password"

# 初始化MySQL,生成数据库及表
ubuntu@hostname: sudo ./bin/storage upgrade

# 设置Phabricator的主访问URI,非80端口要加端口号
ubuntu@hostname: sudo ./bin/config set phabricator.base-uri 'http://xxx.xxx.xxx.xxx'

6. 第一节完成

这时是可以通过Nginx配置的url访问的,访问后最好不要关闭本页面。

作为第一个访问用户,可创建管理员账号,创建后可以添加登录认证的方式Auth Provider,最常用用户名/密码的Provider。

以下介绍必须配置的邮箱系统,和本文使用的Git。

三、配置

管理员访问路由/config/settings/all/可以查看全部配置,每个配置的介绍都很详细,还可以在该页面上配置某些信息。不过为了方便我们统一用命令行来配置,记得进入Phabricator项目目录,所有的手动配置都在./conf/local/local.json中,该文件是热部署的,修改实时生效。

1. 添加邮箱服务

事先准备好你的域名邮箱,点击这里可申请免费的邮箱服务。

# 设置发通知的邮箱地址,建议创建机器人邮箱,你也可以用自己的邮箱
ubuntu@hostname: sudo ./bin/config set metamta.default-address no_reply@your.domain

# 旧版是设置phpmailer相关的属性,这里是配置cluster.mailers
ubuntu@hostname: sudo vim ./conf/local/local.json
# 添加如下内容
...
    cluster.mailers: [
        {
            "key": "main-mailbox", # 标识多个邮箱服务
            "type": "mailgun" # 枚举值,普通邮箱用这个,还有ses、sns...
            "options": {
                "host": "sender.and.receiver.host",
                "port": "994",
                "user": "no_reply@your.domain",
                "password": "no_reply_password",
                "protocol": "ssl" # 可选,但端口要对应
            }
        },
    ]
...

# 测试能否发送邮件,应当接收到no_reply@your.domain的邮件,如无请检查配置
ubuntu@hostname: sudo ./bin/mail send-test --to your@mail.addr --subject hello-world <README.md

2. 配置Phabricator的守护进程

Phabricator有个任务队列,并运行一个守护进程phd,执行队列中的任务。可在/daemon路由中看到Active Daemons中还没有可用的守护进程。phd主要负责:

  • git repository相关的操作
  • 发送邮件
  • 垃圾回收,如旧的日志和缓存
    你可以现在启动该进程并查看是否成功
ubuntu@hostname: sudo ./bin/phd start

为了方便,我们为该进程创建phd用户,并让它自启动。

# 创建phd用户
ubuntu@hostname: sudo adduser phd --home /home/phd

# 禁止phd登录
ubuntu@hostname: sudo usermod -p NP phd

# 添加临时文件
ubuntu@hostname: vim ~/service.file
# 内容如下
...
[Unit]
Description=phabricator-phd
After=syslog.target network.target mysql.service
Before=nginx.service
[Service]
Type=oneshot
User=phd
Group=phd
Enviroment="PATH=/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"
ExecStart=/var/www/phab/phabricator/bin/phd start
ExecStop=/var/www/phab/phabricator/bin/phd stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
...

# 添加phd服务
ubuntu@hostname: sudo cp ~/service.file /lib/systemd/system/phabricator-phd.service

# 启用和启动phd服务
ubuntu@hostname: sudo systemctl enable phabricator-phd.service
ubuntu@hostname: sudo systemctl start phabricator-phd

# 可在/daemon路由下看到已启动的进程,设置phd.user
ubuntu@hostname: sudo ./bin/config set phd.user phd

配置完成就可以添加新用户和修改管理员密码了,记得先添加用户邮箱。

3. 配置SSH和Git托管

转移SSH的22端口,让Git使用22端口,这样配置可以避免客户端Git要自定义端口。

# 修改下列文件中的Port为2222
ubuntu@hostname: sudo vim /etc/ssh/sshd_config

# 重启ssh使配置生效,并在ssh客户端重新登录
ubuntu@hostname: sudo service ssh restart

# 创建Git用户,并禁止登录
ubuntu@hostname: sudo useradd git
ubuntu@hostname: sudo usermod -P NP git

# 设置git可以sudo为phd
ubuntu@hostname: sudo vim /etc/sudoers
# 加入一行内容
...
git ALL=(phd) SETENV: NOPASSWD: /usr/bin/git-upload-pack, /usr/bin/git-receive-pack
...

# 创建git仓库目录,此处为Phabricator默认值,非默认值要修改repository.default-local-path生效
ubuntu@hostname: sudo mkdir /var/repo

# 让phd进程可以访问该目录
ubuntu@hostname: sudo chown -R phd /var/repo
ubuntu@hostname: sudo chgrp -R phd /var/repo

# 设置基本的和git的bin目录
ubuntu@hostname: sudo ./bin/config set environment.append-paths '["/usr/lib/git-core", "/bin"]'

# 设置Phabricator的git用户
ubuntu@hostname: sudo ./bin/config set diffusion.ssh-user git

/var/www/phab/phabricator项目的模板下配置git ssh。

# 从模板创建git ssg hook配置文件
ubuntu@hostname: sudo cp ./resources/sshd/phabricator-ssh-hook.sh /usr/lib/phabricator-ssh-hook.sh

# 修改phabricator-ssh-hook.sh文件权限和内容
ubuntu@hostname: sudo chmod 755 /usr/lib/phabricator-ssh-hook.sh
ubuntu@hostname: sudo vim /usr/lib/phabricator-ssh-hook.sh
# 文件内容
...
#!/bin/sh
# NOTE: Replace this with the username that you expect users to connect with.
VCSUSER="git"  # 配置
# NOTE: Replace this with the path to your Phabricator directory.
ROOT="/var/www/phab/phabricator" # 配置
if [ "$1" != "$VCSUSER" ];
then
  exit 1
fi
exec "$ROOT/bin/ssh-auth" $@
...

# 从模板创建git ssh配置文件
ubuntu@hostname: sudo cp ./resources/sshd/sshd_config.phabricator.example /etc/ssh/sshd_config.phabricator

# 修改sshd_config.phabricator文件
ubuntu@hostname: sudo vim /etc/ssh/sshd_config.phabricator
# 文件内容
...
# NOTE: You must have OpenSSHD 6.2 or newer; support for AuthorizedKeysCommand
# was added in this version.
# NOTE: Edit these to the correct values for your setup.
AuthorizedKeysCommand /usr/lib/phabricator-ssh-hook.sh  # 配置
AuthorizedKeysCommandUser git # 配置
AllowUsers git # 配置
# You may need to tweak these options, but mostly they just turn off everything
# dangerous.
Port 22 # 配置
Protocol 2
PermitRootLogin no
AllowAgentForwarding no
AllowTcpForwarding no
PrintMotd no
PrintLastLog no
PasswordAuthentication no
AuthorizedKeysFile none
PidFile /var/run/sshd-phabricator.pid
...

启动和测试git ssh,这一步需要先将客户端ssh的public key上传至Phabricator账户的keys中,Web页面打开路径Settings >> AUTHENTICATION >> SSH Public Keys

客户端设置简述:在客户端的用户目录下查看.ssh文件夹是否生成id_rsa.pub公钥文件,如果没有,可以先设置git的user和email,再生成公私钥,完成后将公钥文件的内容复制到新建的SSH Public Keys

完成后,继续配置操作:

# 手动启动git ssh
ubuntu@hostname: sudo /usr/sbin/sshd -f /etc/ssh/sshd_config.phabricator

# 在客户端命令行测试,如`Git Bash`
ubuntu@hostname: echo {} | ssh git@xxx.xxx.xxx.xxx conduit conduit.ping
# 打印结果应该类似:
{"result":"hello","error_code":null,"error_info":null}

# 如果测试失败,检查上述public key是否上传,用户权限问题如下DEBUG检查
ubuntu@hostname: sudo /usr/sbin/sshd -d -d -d -f /etc/ssh/sshd_config.phabricator

# 设置git ssh自启动,复制ssh做模板
ubuntu@hostname: sudo cp /lib/systemd/system/ssh.service /lib/systemd/system/phabricator-ssh.service
ubuntu@hostname: sudo vim /lib/systemd/system/phabricator-ssh.service
# 内容如下,修改一行,删除最后一行Alias=sshd.service
...
[Unit]
Description=OpenBSD Secure Shell server
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
[Service]
EnvironmentFile=-/etc/default/ssh
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS -f /etc/ssh/sshd_config.phabricator # 修改
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
[Install]
WantedBy=multi-user.target
...

# 重启git ssh,并再次测试没问题即可
ubuntu@hostname: sudo systemctl enable phabricator-ssh
ubuntu@hostname: sudo systemctl start phabricator-ssh

4. 第二节完成

如果你的软件或配置没有采用本文使用的方案,都可以在官方文档查到具体配置信息。

到这里为止,Phabricator已经可以正常使用了。用管理员账号登录会发现有些警告信息,提示你可以优化的选项,接下来就对这部分和常用配置进行说明。

四、更多

1. 消除系统警告

在Web页面,系统警告都有详细提示,大部分都可以自己查看解决,这里介绍个人认为最有用的几个。

(1)设置上传文件大小限制

能传输的最大文件取决于Nginx、PHP、Storages(存储引擎)三者设置的最小值。

# 修改nginx的限制
ubuntu@hostname: sudo vim /etc/nginx/nginx.conf
# 在http块中加入
...
client_max_body_size 32m; # Phabricator建议的最小值
...

# 修改PHP的限制
ubuntu@hostname: sudo vim /etc/php/7.1/fpm/php.ini
# 找到并修改以下内容
...
post_max_size = 32M
memory_limit = -1; # -1表示在内存中没有限制
...

# 如果没有配置其他引擎,文件默认用MySQL存储,需要修改;0代表禁用,如果打算用其他引擎存储大文件,建议设为100K左右
ubuntu@hostname: sudo ./bin/config set storage.mysql-engine.max-size 33554432

修改完后,记得重启相关服务生效。

(2)其他感觉没啥特别的,以后有机会再补充

2. 一些有用配置

(1)设置文件存储引擎Storage

默认存储引擎只有MySQL,引擎名为blob。如果没有禁用MySQL存储文件,那么小于等于限制大小的文件将存入MySQL,更大的文件将存入其他已配置的引擎,如本地文件系统local-disk,未配置则无法上传成功。

# 设置本地文件引擎的存放路径即启用了大文件存储路径
ubuntu@hostname: sudo ./bin/config set storage.local-disk.path "/your/path"

# 如果需要从MySQL中迁移某些文件,在Web页面的More Application中的Files中查看已上传文件的编号(F88)
ubuntu@hostname: sudo ./bin/files migrate --engine local-disk F88

# 迁移全部将文件名替换为--all
ubuntu@hostname: sudo ./bin/files migrate --engine local-disk --all
(2)设置允许访问的uris

如果你既想通过ip访问,又想通过域名访问,除了要进行最开始Nginx那样的配置,还需要进行如下配置。

ubuntu@hostname: sudo ./bin/config set phabricator.allowed-uris '["http://domain", "http://ip1", "http://ip2"]'

五、总结

1. 遇事不决,查看官文

本人在参照其他一些博客时,经常会遇到一些独特的问题,用了很长时间才解决,在初写这篇文章时,作者已经配置了2.5遍,后来才搜索到官方文档,Phabricator的官方文档真的很详细。

由于自己没有完整的了解Phabricator,欢迎各位看官对文中的不足和错误之处提出指正。

2. 主要参考博客

(1)Phabricator安装和配置过程记录,本文是在该文基础上针对新版Phabricator和自我思考做的重构
(2)使用Phabricator做为Code Review工具

标签:sudo,phabricator,Phabricator,搭配,hostname,git,ssh,ubuntu,服务端
来源: https://www.cnblogs.com/ourscraft/p/14284724.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有