Phabricator(代码review)服务器安装部署

Phabricator是Facebook一个开源可视化的代码审查工具,它集成了一系列开源的Web应用,其中包括审查代码、代码(git/svn)托管、语法检查、单元测试、wiki等功能,还可以bug跟踪,直接做jira与代码review关联,支持两种代码审查工作流:“review”(提交前审查)和 “audit”(提交后审查)。

一、安装

1、通过脚本安装

打开CentOS安装脚本(ubuntu不同):
https://secure.phabricator.co...
进入/opt,新建文件install_rhel-derivs.sh,拷贝脚本内容保存,修改文件权限,执行:

$ chmod 777 install_rhel-derivs.sh 
$ ./install_rhel-derivs.sh

安装内容包括:apache, mysql, php;
然后git下载phabricator, arcanist, libphutil,若linux支持不https模式,可修改安装脚本中的https://为git://模式。

如果在mac安装

脚本安装不行了,只能手动: nginx + php + php-fpm + mysql,mac自带php和php-fpm,但需要安装php插件php-pcntl
nginx配置:
server {
  listen 8000;
  server_name 127.0.0.1;
  root      /Users/xxx/phabricator/phabricator/webroot;
  try_files $uri $uri/ /index.php;

  location / {
     index   index.php;
     if ( !-f $request_filename ){
       rewrite ^/(.*)$ /index.php?__path__=/$1 last;
       break;
     }
  }

  location /index.php {
    fastcgi_pass   localhost:9000;    # 需要本地启动Fast CGI,可直接运行:$ php-fpm
    fastcgi_index   index.php;
    fastcgi_param  REDIRECT_STATUS    200;
    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;
  }
}

2、移动phabricator相关文件到apache的发布目录下:

新建一个项目目录,如:code-review:

$ mv /opt/arcanist /var/www/html/code-review
$ mv /opt/libphutil /var/www/html/code-review
$ mv /opt/phabricator /var/www/html/code-review

3、关闭防火墙和SELinux

a.) 关闭防火墙
$ service iptables status     # 查看防火墙状态
$ service iptables stop       # 先临时关闭防火墙
$ chkconfig iptables off      # 再永久关闭,开机不启动
b.) 修改防火墙(防火墙需要,不能关闭)
$ service iptables status     # 查看防火墙状态
$ vi /etc/sysconfig/iptables

若web服务或数据库连接不上,添加以下端口:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

$ service iptables restart    # 重启防火墙
c.) 关闭SELinux
$ getenforce                  # 查看SELinux状态 或sestatus查看详细
$ setenforce 0                # 临时关闭SElinux
$ vi /etc/selinux/config      # 修改SELINUX=disabled,重启后永久关闭

4、修改apache配置:

在系统变量(非用户变量)的Path变量里添加以下两个路径(win7及以下记得中间用;隔开):

$ vi /etc/httpd/conf/httpd.conf
或新建: /etc/httpd/conf.d/vhost.conf   # 在httpd.conf中有Include包括

添加虚拟机:
ServerName localhost
Listen     8800

<VirtualHost *:8800>
  ServerName localhost
  DocumentRoot "/var/www/html/code-review/phabricator/webroot"
  DirectoryIndex index.php index.html index.html.var
  
  RewriteEngine on
  RewriteRule ^/rsrc/(.*)     -                       [L,QSA]
  RewriteRule ^/favicon.ico   -                       [L,QSA]
  RewriteRule ^(.*)$          /index.php?__path__=$1  [B,L,QSA]
</VirtualHost>

$ service httpd restart        # 重启apache
$ chkconfig httpd on           # 设置开机启动

如果启动apche访问不到任何信息,说明监听端口不对,查找Listen字段,修改相应端口;
如果启动apche出现内部错误,说明RewriteEngine有问题;
若启动命令时,提示ServerName相关错误,将虚拟机上一行的ServerName localhost注释去掉;
apache日志路径:/var/log/httpd

5、配置数据库:

$ service mysqld restart       # 重启mysql
$ chkconfig mysqld on          # 设置开机启动
a.) 设置数据库root密码:
$ mysql -u root                # 若进不了,说明数据库有密码,查看后面的二、相关问题
  Mysql> use mysql;
  Mysql> update user set password=password("新密码") where user="root";  # 不能直接password="新密码"
  Mysql> flush privileges;
  Mysql> quit;
b.) 升级数据库:

默认安装的数据库5.1的,issues提示升到5.6+:

$ more /etc/redhat-release         # 查看当前linux版本
$ rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm    # 可以去http://repo.mysql.com/选择版本
$ yum -y upgrade mysql
c.) 更新数据库:
$ ./bin/storage upgrade

# 若删除数据库:
$ ./bin/storage destory
d.) 修改数据库默认编码:
$ service mysqld stop
$ vi /etc/my.cnf               # 修改mysql配置文件
                          
# 在下面两项中添加:
[client]
default_character_set=utf8

[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8

$ service mysqld restart       # 重启

ps: 数据库同步或传输数据时,记得在navicat的高级里,去掉包含字符集

6、修改phabricator配置:

进入/var/www/html/phabricator下修改配置文件,或用./bin/config set mysql.pass 000000 设置:

$ vi ./conf/local/local.json

# 修改内容如下(数据库、禁掉Test Plan,邮件配置):
{
  "phabricator.base-uri": "http:\/\/192.168.4.168:8800\/",
  "mysql.pass": "123456",
  "mysql.user": "root",
  "mysql.host": "localhost",
  "mysql.port": "3306",
  "differential.require-test-plan-field": false,
  "cluster.mailers": [
    {
      "key": "my-mailer",
      "type": "smtp",
      "options": {
        "host": "smtp.exmail.qq.com",
        "port": 465,
        "user": "auto@domain.com",
        "password": "123456",
        "protocol": "ssl"
      }
    }
  ],
  "metamta.default-address": "fe_auto@aicaigroup.com"
}

7、访问网址,部署邮件

进入左侧菜单config -> mail,设置默认邮箱metamta.default-address值,再设置metamta.mail-adapter值为:PhabricatorMailImplementationPHPMailerAdapter
重启邮件服务:

$ ./bin/phd restart

发送邮件试试,查看邮件发送是否正常:

$ ./bin/mail list-outbound

8、设置登录授权方式

左侧菜单-Auth,设置用户名/密码登录方式,若未设,退出后登录不了,执行:

$ ./bin/auth recover <管理员账号>

根据提示打开网址,登录后,进入auth菜单,添加一个登录授权方式

9、添加中文支持

进入phabricator/src/extensions/目录下,rm -fr README,再执行下面git命令,然后在客户端设置里,选择语言中文即可.

$ git clone https://github.com/wanthings/phabricator-zh_CN.git ./

9、解决issue

主要涉及文件:

/etc/php.d/apc.ini #apc相关
/etc/php.ini #部分php设置
/etc/my.cnf #mysql相关

修改完记得重启相应的httpd和mysqld服务.

二、仓库管理

1、观察已存在的远端仓库

如果不想让Phabricator托管git仓库,可以以观察者模式导入一个已存在的git项目,并设置一些策略,当用户有提交时,会触发一些审核策略,实现代码review,具体创建过程如下:

1.) 创建观察仓库

a. 创建一个新仓库(Create a new repository);
b. 点击左侧菜单URIs,再右侧Add New URI,填写URI(已存在的远端仓库),设置I/O模式为Observe;
c. 如果需要,配置一些认证(私钥等);
d. 在Basics项中启用仓库,并点立即更新,开始导入;

2.) 创建Herald规则

在更多应用里,添加Herald到左侧常用菜单上,进入Herald,创新一个"提交"类型(非commit Hook)的规则,例如,创建一条监听merge提交的规则:

is any of:
Is merge commit: is true
Commit message: does not match regexp: @\sof\s@
email to: ....

2、ssh方式托管Git仓库

1.) 账户配置
$ useradd git         # 添加一个git账户,可设密码或不设
$ vi /etc/shadow      # 最底部查看git用户的第二字段是不是!!,如果是,改为空,如果有密码也没事,只要不是!!
$ vi /etc/passwd      # 找到git用户对应的那行,如果有类似于这样的配置/bin/false,请修改为 /bin/sh,没有就不用修改
2.) 修改Phabricator配置

进入phabricator目录:

$ ./bin/config set phd.user root
$ ./bin/config set diffusion.ssh-user git    # 这里的设置会表现在clone的url里
$ ./bin/phd restart
3.) 配置git账户运行权限

运行visudo命令,或vi /etc/sudoers,或没有sodu,需要运行yum install sudo安装。
查找Defaults requiretty字段,如果未注释,注释掉,在文件尾部添加如下代码:

git ALL=(root) SETENV: NOPASSWD: /bin/sh, /usr/bin/git-upload-pack, /usr/bin/git-receive-pack
4.) 配置ssh端口
$ vi /etc/ssh/sshd_config
修改端口为:
#Port 22                    # 注释掉22端口,在后面另起的git项目ssh服务里用
Port 2222                   # 更改远程登录端口为2222
其它ListenAddress字段都不要改,保持注释状态

$ vi service sshd restart   # 重启ssh服务

如果不用默认22端口,需要在phabricator配置里添加设置,或在本地~/.ssh/config里添加Port端口
$ ./bin/config set diffusion.ssh-port 2222

如果都设置了,还是不行,考虑是不是端口被远程占用或启动phabricator ssh服务。

5.) 添加脚本及ssh服务

进入phabricator下resources/sshd/目录
a.) 添加phabricator ssh脚本:

$ cp phabricator-ssh-hook.sh /usr/libexec/phabricator-ssh-hook.sh
$ chown root /usr/libexec/phabricator-ssh-hook.sh
$ chmod 755 /usr/libexec/phabricator-ssh-hook.sh        # 千万不要用错成chown 755命令了
$ vi /usr/libexec/phabricator-ssh-hook.sh
修改两个字段:
VCSUSER="git"                                           # ssh帐户
ROOT="/var/www/html/code-review/phabricator"            # phabricator安装目录路径

b.) 添加phabricator ssh配置文件:

$ cp sshd_config.phabricator.example  /etc/ssh/sshd_config.phabricator
$ vi /etc/ssh/sshd_config.phabricator
修改:
AuthorizedKeysCommand /usr/libexec/phabricator-ssh-hook.sh           # 此处路径应该与a.)步骤中脚本路径一致
AuthorizedKeysCommandRunAs git              # openSSH6.2以上,此字段为AuthorizedKeysCommandUser
AllowUsers git

Port 22           # 启用ssh默认端口22,为避免冲突,应注释掉ssh默认配置文件/etc/ssh/sshd_config中22端口

c.) 启动phabricator ssh服务:
先用调试模式启动,查看错误及端口绑定是否成功:

$ /usr/sbin/sshd -d -d -d -f /etc/ssh/sshd_config.phabricator
正式启用:
$ /usr/sbin/sshd -f /etc/ssh/sshd_config.phabricator           # 此ssh服务跟系统默认ssh不是一个进程
重启只要执行上面相同的命令即可,若要关闭服务:
$ ps -ef | grep sshd
$ kill <id>
6.) 添加ssh公钥

a.) 生成ssh密钥:

$ ssh-keygen -t rsa -f ~/.ssh/phabricator -C <邮箱>         # -f 可修改生成名

b.) ~/.ssh/config添加一条:

# phabricator
Host 192.168.1.5
HostName 192.168.1.5
Port 22                                  
PreferredAuthentications publickey
IdentityFile ~/.ssh/phabricator

c.) 登录phabricator审核网站,个人管理页面,SSH Public Keys菜单里添加phabricator.pub公钥

$ cat ~/.ssh/phabricator.pub
完成后测试一下:
$ ssh -T -p 22 git@192.168.1.5       # -p 可修改端口,默认22,可不加参数

3、http方式托管Git仓库

1.) 修改apache权限

运行visudo,在sudoers里为apache(www-user用户)添加如下权限:

apache ALL=(root) SETENV: NOPASSWD: /usr/bin/git, /usr/bin/git-upload-pack, /usr/bin/git-receive-pack, /usr/bin/ssh, /usr/libexec/git-core/git-http-backend
2.) phabricator配置
$ ./bin/config set diffusion.allow-http-auth true                            # 显示http clone地址
$ ./bin/config set environment.append-paths '["/usr/libexec/git-core"]'      # 添加环境变量,数组可放多个   

再进入网站config菜单 -> all settings里,找到diffusion.allow-http-auth,点开,设置值为:Allow HTTP Basic Auth

3.) 设置git http访问密码

在Settings里VCS Password菜单里设置

4.) 本地保存登录信息

修改~/_netrc文件,添加:

machine 192.168.1.5
login wangwb
password aym000000  
5.) 调试
$ GIT_CURL_VERBOSE=1 git clone http://....   

如果有HTTP/1.0 500 Internal Server Error,说明git-http-backend路径不对(可去仓库->status里看),需添加environment.append-paths配置,见上面步骤2.)

3、仓库管理

1.) 修改仓库默认存储路径:
$ ./bin/config set repository.default-local-path '/路径/repo'
2.) 删除一个仓库:
$ ./bin/remove destroy R(n)

官网文档:https://secure.phabricator.co...

三、相关问题

1、mysql擦除root密码

$ mysql –skip-grant-table &
  Mysql> use mysql;
  Mysql> update user set password=password("新密码") where user="root";
  Mysql> flush privileges;
  Mysql> quit;

这里需要注意的是每句命令需要用分号“;”结尾,执行完以上得操作,root的密码就被清空。

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'错误:
原因:mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的.
处理方案:

# 1.关闭mysql
   $ service mysqld stop
# 2.屏蔽权限
   $ mysqld_safe --skip-grant-table
   屏幕出现: Starting demo from .....
# 3.新开起一个终端输入
   $ mysql -u root mysql
   Mysql> update user set password=password("新密码") where user="root";
   Mysql> flush privileges;
   Mysql> quit;

2、mysql远程root账户不能登录

先查看一下:

授权:

$ mysql -u root -p
  Mysql> use mysql;
  Mysql> select host from user where user='root';  # 先查看一下host有没有%这个值,如果有直接运行flush privileges;
  Mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysql root密码';
  Mysql> flush privileges;
  Mysql> quit;

3、mysql修改默认数据存放

$ mysqladmin -u root -p variables | grep datadir  # 查看mysql数据库存放目录
$ service mysqld stop
$ mv /var/lib/mysql /路径  # 移动数据库文件

$ vi /etc/my.cnf
# 修改datadir和socket两个字段,并添加以下:
[mysql] 
socket=/路径/mysql.sock

$ service mysqld start

4、备份/恢复mysql数据库

$ mysqldump --all-databases -h127.0.0.1 -u root -p > ./backup/mysql-bak.sql
$ mysqldump --all-databases -h127.0.0.1 -u root -p < ./backup/mysql-bak.sql

5、ssh远程不能登录root账户

修改ssh配置:

$ vi /etc/ssh/sshd_config        # 修改:PermitRootLogin yes

6、点开git仓库PHP报错

说明SELinux配置开起了,参照上文开机禁掉。

7、kill进程

$ kill -s 9 PID # 进程ID

官方参考: https://secure.phabricator.co...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值