本文介绍Phabricator的安装和配置过程。
Phabricator的安装过程比较繁琐,为了保证得到可靠的过程,步骤在以下公有云平台:
微软Azure国内阿里云国内AWS首尔分别做了测试。
安装环境为:
Ubuntu 16.04 ServerNginxPHP7.1MySQL以下分两个部分:
安装:Phabricator基本安装、运行和检验配置:发邮件、基于SSH的Git仓库托管以及配置杂项等安装clone Phabricator项目文件创建目录:
sudo mkdir /var/www/phaclone相关项目:
sudo git clone https://github.com/phacility/libphutil.git sudo git clone https://github.com/phacility/arcanist.git sudo git clone https://github.com/phacility/phabricator.git修改目录所有者,用nginx进程的用户,www-data
sudo chown -R www-data:www-data /var/www/pha安装Nginx使用Nginx官方源。命令如下:
sudo apt-get install software-properties-common sudo add-apt-repository ppa:nginx/stable sudo apt-get update sudo apt install -y nginx安装后,Nginx应自动启动,检查80端口是否正常:
netstat -na | grep 80应看到类似这样的结果:
tcp6 0 0 :::80 :::* LISTEN如能找到,说明Nginx安装成功,如无法外网访问,检查防火墙设置。
有关防火墙的设置后续安装配置,需要允许如下端口的外网访问:
22,将用于git ssh使用80,默认http443,https,phabricator正式环境端口2222,ssh登录端口安装PHP环境Phabricator不支持PHP7.0版本,需要安装7.1版本:
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php sudo apt-get update 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修改fpm的配置:
sudo vim /etc/php/7.1/fpm/pool.d/www.conf文件内容,在listen = /run/php/php7.1-fpm.sock之后加入2行:
… ; Note: This value is mandatory. listen = /run/php/php7.1-fpm.sock listen = 9000 # 增加 listen.allowed_clients = 127.0.0.1 # 增加 ...重启PHP:
sudo service php7.1-fpm stop sudo service php7.1-fpm start测试配置是否生效:
netstat -na | grep 9000如能显示,说明fpm正常启动:
tcp6 0 0 :::9000 :::* LISTEN配置Nginx域名比如是:p.mydomain.com,那么创建配置文件:/etc/nginx/conf.d/p.mydomain.com.conf,内容如下:
server { server_name p.mydomain.com; # 配置域名 root /var/www/pha/phabricator/webroot; # 配置根目录 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; } }安装和配置MySQL安装:
sudo apt install mysql-server提示输入root用户密码,在本例中,密码是:password
在phabricator目录下(git clone https://github.com/phacility/phabricator.git 的那个目录)执行命令,将mysql密码设置到phabricator:
sudo ./bin/config set mysql.pass 'password'为phabricator创建mysql相关数据表:
sudo ./bin/storage upgrade设置和重启Nginx设置下phabricator的url:
sudo ./bin/config set phabricator.base-uri 'http://p.mydomain.com'Nginx重新加载:
sudo service nginx reload设置管理员和认证方式这时,浏览器应该可以访问Phabricator了:http://p.mydomain.com
作为第一个访问用户,可创建管理员账号。
注意,管理员不是标准用户。
如果能创建管理员,说明安装过程成功。
这时可以添加认证方式(Auth Provider)。phabricator提供了多种认证方式,其中最基本的是用户名/密码的provider。
作为管理员,访问Auth,选择Add Provider ,然后添加 Username/Password Provider即可。
安装过程到此基本结束,但还不能:
发送用户邀请邮件及其他通知邮件创建git repository下一部分将解决这些问题。
配置发送邮件的基本配置发送邮件的功能是必须配置的,否则无法创建用户,因为需要通过邮件发送邀请通知。
执行如下命令,设置发送邮件邮箱配置:
sudo ./bin/config set metamta.default-address robot@mydomain.com sudo ./bin/config set metamta.domain mydomain.com sudo ./bin/config set metamta.can-send-as-user false sudo ./bin/config set metamta.mail-adapter PhabricatorMailImplementationPHPMailerAdapter sudo ./bin/config set phpmailer.mailer smtp sudo ./bin/config set phpmailer.smtp-host smtp.exmail.qq.com sudo ./bin/config set phpmailer.smtp-port 465 sudo ./bin/config set phpmailer.smtp-user robot@mydomain.com sudo ./bin/config set phpmailer.smtp-password my_password sudo ./bin/config set phpmailer.smtp-protocol SSL这里使用的是qq企业邮箱配置的。
设置完毕,检查是否可以发送邮件:
./bin/mail send-test --to myname@qq.com --subject hello <README.md如果能收到邮件,说明邮箱配置正确。
配置和自启动守护进程phabricator有个任务队列,并运行一个守护进程,执行队列中的任务。可在 http://p.mydomain.com/daemon 中看到Active Daemons中还没有可用的守护进程。
phabricator守护进程,phd,主要负责:
git repository相关的操作发送邮件垃圾回收,如旧的日志和缓存我们可以直接启动守护进程:
sudo ./bin/phd start但是有问题:
当前用户权限过大需要设置为自启动服务创建phd用户创建phd用户:
sudo adduser phd --home /home/phd使phd用户不可远程登录:
sudo usermod -p NP phd创建和启动phd自启动服务创建systemd service文件/tmp/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/pha/phabricator/bin/phd start ExecStop=/var/www/pha/phabricator/bin/phd stop RemainAfterExit=yes [Install] WantedBy=multi-user.target将服务加入到systemd目录:
sudo cp /tmp/service.file /lib/systemd/system/phabricator-phd.service使phabricator-phd.service可用:
sudo systemctl enable phabricator-phd.service启动phabricator-phd.service服务:
sudo systemctl start phabricator-phd如没有报错,访问:http://p.mydomain.com/daemon/ 可以看到Active Daemons不为空了。
将phd用户设置为phd.user:
sudo ./bin/config set phd.user phd注:其他用户如需操作git命令,需要sudo为phd用户,上面的设置就是告诉它们需要sudo的用户名。
phd用户将守护进程跑起来后,就可以创建新用户了。通过管理员账号,选择people,添加standard用户。会收到邀请邮件,如果phd和邮箱配置都没问题的话。
用这个standard用户登录,并上传public key,后面要用到。
www-data用户的配置如果将来要用到http git时,需要将www-data用户设置为可sudo为phd用户。
编辑/etc/sudoers,加入:
www-data ALL=(phd) SETENV: NOPASSWD: /usr/lib/git-core/git-http-backend实际上,我们没有用到这个,我们用的是SSH Git。
配置SSH Git托管准备工作将当前SSH服务转移到2222端口,将来运行的Git SSH服务使用22端口。这是多次配置后,觉得后续比较方便的做法。否则,Git用户都要自定义端口,给开发/部署带来不必要的麻烦。
修改文件:
sudo vim /etc/ssh/sshd_config将Port改为2222后重启ssh服务:
sudo service ssh restart用2222端口ssh重新登录服务器:
ssh -p2222 p.mydomain.com 创建git用户创建用户:
sudo adduser git禁止登录:
sudo usermod -p NP git设置git可以sudo为phd,修改/etc/sudoers,加入:
git ALL=(phd) SETENV: NOPASSWD: /usr/bin/git-upload-pack, /usr/bin/git-receive-pack创建存放git repository的目录:
sudo mkdir /var/repo改变目录所有者为phd:
sudo chown -R phd /var/repo sudo chgrp -R phd /var/repophabricator设置git-core路径:
sudo ./bin/config set environment.append-paths '["/usr/lib/git-core"]'phabricator设置git用户:
sudo ./bin/config set diffusion.ssh-user git创建git ssh hook配置文件phabricator项目中提供了模版文件,将这个文件复制到需要的地方:
sudo cp /var/www/pha/phabricator/resources/sshd/phabricator-ssh-hook.sh /usr/lib/phabricator-ssh-hook.sh修改文件权限:
sudo chmod 755 /usr/lib/phabricator-ssh-hook.sh修改hook文件:
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/pha/phabricator" # 配置 if [ "$1" != "$VCSUSER" ]; then exit 1 fi exec "$ROOT/bin/ssh-auth" $@创建git ssh配置文件phabricator也提供了模版文件,复制到需要的地方:
sudo cp /var/www/pha/phabricator/resources/sshd/sshd_config.phabricator.example /etc/ssh/sshd_config.phabricator修改sshd_config.phabricator文件:
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及测试这个步骤,是为了检查前面2个文件是否正确。正式启动git ssh需要后面使用systemd的自启动服务方式。
启动git ssh服务:
sudo /usr/sbin/sshd -f /etc/ssh/sshd_config.phabricator在客户端终端命令行下:
echo {} | ssh git@p.mydomain.com conduit conduit.ping如果出现:
{"result":"hello","error_code":null,"error_info":null}就说明成功了。
可能出现的错误:
没有将客户端的public key上传到phabricator,或者不匹配各种服务器端配置问题,包括用户权限问题针对服务器端配置问题,可这样启动git ssh服务,参照debug信息一般能找到问题:
sudo /usr/sbin/sshd -d -d -d -f /etc/ssh/sshd_config.phabricator或者可阅读官方文档Diffusion User Guide: Repository Hosting的Troubleshooting SSH部分。
这时,需要杀掉当前启动的phd服务,因为后面要设置自动启动它。
设置git ssh自启动服务复制ssh的服务文件,作为git ssh服务的模版:
sudo cp /lib/systemd/system/ssh.service /lib/systemd/system/phabricator-ssh.service修改phabricator-ssh.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即,修改1行(见代码注释),另外,删除最后一行Alias=sshd.service。
然后:
sudo systemctl enable phabricator-ssh sudo systemctl start phabricator-ssh再次在客户端测试,如果没有问题,基本上就配置好了。
配置杂项可以在:http://p.mydomain.com/config/issue/ 查看配置上的问题,并根据建议做相应修改。
以下给出一些常用的配置情况。
语法高亮安装pigment:
sudo apt install -y python-pygmentsphabricator打开pygments功能:
sudo ./bin/config set pygments.enabled true最大下载文件限制编辑php配置文件:
sudo vim /etc/php/7.1/fpm/php.ini找到这行并改为:
post_max_size = 100M修改Nginx配置文件:
sudo vim /etc/nginx/nginx.conf在http块中加入:
client_max_body_size 100m;因为默认使用mysql存储,还需要修改对mysql存储的限制,默认是1M,执行命令:
sudo ./bin/config set storage.mysql-engine.max-size 104857600重启Nginx。
增加邮件地址时的报错处理在添加邮件地址时出现了这样的报错:
Unhandled Exception ("AphrontQueryException") #1055: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'phabricator_system.system_actionlog.actorIdentity' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by原因是sql_mode的限制,可连接msyql:
mysql -u root -ppassword然后:
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));这一问题,也可能会出现在有类似数据库操作的地方。
---来自腾讯云社区的---音视频_李超
微信扫一扫打赏
支付宝扫一扫打赏