git config设置用户名_Phabricator发邮件、基于SSH的Git仓库托管以及配置杂项等

发送邮件的基本配置

发送邮件的功能是必须配置的,否则无法创建用户,因为需要通过邮件发送邀请通知。

执行如下命令,设置发送邮件邮箱配置:编辑/alidata2/phabricator/phabricator/conf/local/local.json

"cluster.mailers": [

{

"key": "phabricator@59et.com",

"type": "smtp",

"options": {

"host": "smtp.ym.163.com",

"port": 994,

"user": "phabricator@59et.com",

"password": "xxxxxx",

"protocol": "SSL"

}

}

]

这里使用的是网易企业邮箱配置的。

设置完毕,检查是否可以发送邮件:

./bin/mail send-test --to myname@59et.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=/alidata2/phabricator/phabricator/bin/phd start

ExecStop=/alidata2/phabricator/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 /alidata2/repo/

sudo chgrp -R phd /alidata2/repo/

phabricator设置git-core路径:

sudo ./bin/config set environment.append-paths '["/usr/local/libexec/git-core"]'

phabricator设置git用户:

sudo ./bin/config set diffusion.ssh-user git

创建git ssh hook配置文件 phabricator项目中提供了模版文件,将这个文件复制到需要的地方:

sudo cp /alidata2/phabricator/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="/alidata2/phabricator/phabricator" # 配置

if [ "$1" != "$VCSUSER" ];

then

exit 1

fi

exec "$ROOT/bin/ssh-auth" $@

创建git ssh配置文件 phabricator也提供了模版文件,复制到需要的地方:

sudo cp /alidata2/phabricator/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 # 配置

AuthorizedKeysCommandRunAs 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@phabricator.59et.com conduit conduit.ping

如果出现:

{"result":"hello","errorcode":null,"errorinfo":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-pygments

phabricator打开pygments功能:

sudo ./bin/config set pygments.enabled true

最大下载文件限制 编辑php配置文件:

sudo vim /etc/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',''));

这一问题,也可能会出现在有类似数据库操作的地方。

开启http访问代码仓库

74651b858775bfcc076498066c772733.png

开启后效果

a36e17687d4d67ed09615f5fd054cb2c.png

参考资料:

https://www.jianshu.com/p/d7630e1fe4f9

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值