首页
常用命令
About Me
推荐
weibo
github
Search
1
linuxea:gitlab-ci之docker镜像质量品质报告
48,760 阅读
2
linuxea:如何复现查看docker run参数命令
19,491 阅读
3
Graylog收集文件日志实例
17,808 阅读
4
git+jenkins发布和回滚示例
17,364 阅读
5
linuxea:jenkins+pipeline+gitlab+ansible快速安装配置(1)
17,353 阅读
ops
Openvpn
Sys Basics
rsync
Mail
NFS
Other
Network
HeartBeat
server 08
Code
Awk
Shell
Python
Golang
virtualization
KVM
Docker
openstack
Xen
kubernetes
kubernetes-cni
Service Mesh
Data
Mariadb
PostgreSQL
MongoDB
Redis
MQ
Ceph
TimescaleDB
kafka
surveillance system
zabbix
ELK Stack
Open-Falcon
Prometheus
Web
apache
Tomcat
Nginx
自动化
Puppet
Ansible
saltstack
Proxy
HAproxy
Lvs
varnish
更多
音乐
影视
music
Internet Consulting
最后的净土
软件交付
持续集成
gitops
devops
登录
Search
标签搜索
kubernetes
docker
zabbix
Golang
mariadb
持续集成工具
白话容器
linux基础
nginx
elk
dockerfile
Gitlab-ci/cd
最后的净土
基础命令
jenkins
docker-compose
gitops
haproxy
saltstack
Istio
marksugar
累计撰写
675
篇文章
累计收到
140
条评论
首页
栏目
ops
Openvpn
Sys Basics
rsync
Mail
NFS
Other
Network
HeartBeat
server 08
Code
Awk
Shell
Python
Golang
virtualization
KVM
Docker
openstack
Xen
kubernetes
kubernetes-cni
Service Mesh
Data
Mariadb
PostgreSQL
MongoDB
Redis
MQ
Ceph
TimescaleDB
kafka
surveillance system
zabbix
ELK Stack
Open-Falcon
Prometheus
Web
apache
Tomcat
Nginx
自动化
Puppet
Ansible
saltstack
Proxy
HAproxy
Lvs
varnish
更多
音乐
影视
music
Internet Consulting
最后的净土
软件交付
持续集成
gitops
devops
页面
常用命令
About Me
推荐
weibo
github
搜索到
10
篇与
GitLab
的结果
2018-10-19
linuxea: Git 指定检出目录
git在检出时,默认检出所有文件,那如果我只想稀疏的检出某一个目录该怎么办。git是可以支持这种类似的需求方式,如下:第一次克隆,不检出[root@linuxea ~]# git clone --no-checkout https://github.com/LinuxEA-Mark/docker-subversion.git Cloning into 'docker-subversion'... remote: Enumerating objects: 119, done. remote: Total 119 (delta 0), reused 0 (delta 0), pack-reused 119 Receiving objects: 100% (119/119), 17.97 KiB | 0 bytes/s, done. Resolving deltas: 100% (62/62), done. [root@linuxea ~]# cd docker-subversion/启用稀疏的方式[root@linuxea docker-subversion]# git config core.sparsecheckout true[root@linuxea docker-subversion]# ls .git/info/ exclude [root@linuxea docker-subversion]# ls接下来就需要将目录名称写入sparse-checkout文件
2018年10月19日
2,526 阅读
0 评论
0 点赞
2017-09-23
linuxea:jenkins+pipeline+gitlab+ansible快速安装配置(1)
jenkins+gitlab+ansible配合使用考虑了一下子,还是整理了一些图片和文字,简单的记录安装的过程,主要想玩pipeline。那么在后面的几篇文章中会介绍jenkins+sonarqube的构建,当然,还是用来做pipeline来玩,告别之前的那种模式,本章主要介绍jenkins+gitlab+ansible快速部署sonarqube 安装:https://www.linuxea.com/1722.html1,jenkins在这里负责发布构建,主要插件pipeline,gitlab,sonarqube2,gitlab代码管理3,ansible用来推送代码jenkins安装参考:https://pkg.jenkins.io/redhat-stable/我这里安装的是2.73.1安装jenkins和插件安装jenkins[root@linuxea.com-Node113 ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo [root@linuxea.com-Node113 ~]# sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key [root@linuxea.com-Node113 ~]# yum install jenkins -y [root@linuxea.com-Node113 ~]# /etc/init.d/jenkins start [root@linuxea.com-Node113 ~]# iptables -I INPUT 5 -p tcp -m tcp -m state --state NEW -m multiport --dports 22,3306,10050,10051,8080 -m comment --comment "ALL" -j ACCEPT打开浏览器进行安装和配置cat /var/lib/jenkins/secrets/initialAdminPassword根据提示将密码输入安装gitlab和pipeline插件我这里有vpn,直接安装安装pipeline等待安装完成后进入界面安装ansible和配置jenkins和gitlab[root@linuxea.com-Node113 ~]# yum install jenkins添加主机[root@linuxea.com-Node113 ~]# cat /etc/ansible/hosts [webapp] 10.10.0.98 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass="mima"配置密钥和主机配置jenkins用户终端修改jenkins用户shell为bashjenkins:x:989:985:Jenkins Automation Server:/var/lib/jenkins:/bin/bash配置ansible和源站测试连通性[root@linuxea.com-Node113 /etc/ansible]# su - jenkins尝试链接一次[jenkins@linuxea.com-Node113 ~]$ ansible webapp -m ping 10.10.0.98 | SUCCESS => { "changed": false, "ping": "pong" }之后会用到sync模块,模块本身不支持密码,所以传递密钥即可[jenkins@DS-VM-Node113 ~]$ ssh-keygen -t rsa传递密钥给源站机器[jenkins@linuxea.com-Node113 ~]$ ssh-copy-id root@10.10.0.98 /bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@10.10.0.98's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@10.10.0.98'" and check to make sure that only the key(s) you wanted were added.测试[jenkins@linuxea.com-Node113 ~]$ ssh root@10.10.0.98 Last login: Wed Sep 20 13:41:41 2017 from 10.10.240.113 [root@linuxea.com-Node98 ~]# 配置gitlab密钥同时也需要将jenkins的id_rsa.pub文件添加到gitlab项目中方便拉代码[jenkins@linuxea.com-Node113 ~]$ cat /var/lib/jenkins/.ssh/id_rsa.pub 复制信息到项目中配置jenkins密钥在jenkins中修改credentials编辑到此位置,安装配置完成
2017年09月23日
17,353 阅读
0 评论
1 点赞
2017-02-16
mac上git报Connection refused端口错误解决
host gitub.com port 22: Connection refusedfatal: Could not read from remote repository.1,解决ssh connect to host github.com port 22 connection timed out[root@linuxea-com ~]# vim ~/.ssh/config Host github.com User xxx@163.com (你注册github时的邮箱,这里使用注册的用户名也行) Hostname ssh.github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Port 4432,mac提示ssh: connect to host localhost port 22: Connection refused解决方法:打开系统偏好设置 —— 共享,选中远程登录:3,加端口链接[root@linuxea-com ~]# git clone ssh://git@mydomain.com:[port]/gitolite-admin如:[root@linuxea-com ~]# git clone ssh://git@github.con:443/dt1k23eji/L21ao_3OS.git4,如果以上还是没有解决,可以尝试使用http,不过你可能需要一个记录密码的客户端
2017年02月16日
9,778 阅读
0 评论
0 点赞
2017-01-12
gitlab-8.9.9安装和汉化
下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/开始安装[root@linuxea-com ~]# yum install gitlab-ce-8.8.9-ce.0.el7.x86_64.rpm -y [root@linuxea-com ~]# cat /etc/gitlab/gitlab.rb|grep 'http://10.0.1.61' external_url 'http://10.0.1.61' [root@linuxea-com ~]# gitlab-ctl reconfigure [root@linuxea-com ~]# gitlab-ctl stop ok: down: gitlab-workhorse: 1s, normally up ok: down: logrotate: 0s, normally up ok: down: nginx: 1s, normally up ok: down: postgresql: 0s, normally up ok: down: redis: 0s, normally up ok: down: sidekiq: 0s, normally up ok: down: unicorn: 0s, normally up下载中文补丁[root@linuxea-com ~]# git clone https://gitlab.com/larryli/gitlab.git Gitlab-cn && cd Gitlab-cn查看版本[root@linuxea-com Gitlab-cn]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 8.9.9 [root@linuxea-com ~/sourceGitlab]# git diff origin/8-8-stable origin/8-8-zh > /tmp/8.8.diff回车,提示输入y即可[root@linuxea-com ~/sourceGitlab]# patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /tmp/8.9.9.diff [root@linuxea-com ~/sourceGitlab]# gitlab-ctl start不要被中文登陆界面所误导,登陆进去你看到的将会是中英交互模式....请下载8.8.0完美汉化重新安装清理:1,gitlab-ctl uninstall 2,rm -rf /etc/gitlab/* /var/log/gitlab/ /var/opt/gitlab/ /opt/gitlab/web密码重置:gitlab-rails console productionirb(main):011:0> user = User.where(id:1).first => #<User id: 1, email: "admin@example.com", encrypted_password: "$2a$10$hnGIO79zr4ldahTwWVK4OOb9RQvV5Z1q.SaWjeIg/E....", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2017-01-12 03:37:45", updated_at: "2017-01-12 03:49:19", name: "Administrator", admin: true, projects_limit: 10, skype: "", linkedin: "", twitter: "", authentication_token: "WzXKZNQ3vr3JMeCMvyBR", theme_id: 2, bio: nil, failed_attempts: 4, locked_at: nil, username: "root", can_create_group: true, can_create_team: false, state: "active", color_scheme_id: 1, password_expires_at: nil, created_by_id: nil, last_credential_check_at: nil, avatar: nil, confirmation_token: nil, confirmed_at: "2017-01-12 03:37:45", confirmation_sent_at: nil, unconfirmed_email: nil, hide_no_ssh_key: false, website_url: "", notification_email: "admin@example.com", hide_no_password: false, password_automatically_set: false, location: nil, encrypted_otp_secret: nil, encrypted_otp_secret_iv: nil, encrypted_otp_secret_salt: nil, otp_required_for_login: false, otp_backup_codes: nil, public_email: "", dashboard: 0, project_view: 0, consumed_timestep: nil, layout: 0, hide_project_limit: false, unlock_token: nil, otp_grace_period_started_at: nil, ldap_email: false, external: false> irb(main):012:0> user.password = 'admincom' => "admincom" irb(main):013:0> user.save! => true irb(main):014:0>
2017年01月12日
5,731 阅读
0 评论
0 点赞
2016-12-31
jenkins+gitlab+docker快速部署发布回滚示例
本章简单介绍docker+jenkins+gitlab发布和回滚,相比较上一篇中git+jenkins http://www.linuxea.com/1537.html来说,加入了docker,加入docker后,发布和回滚变得将是很简单,容器本身一次构建后,存放在docker仓库中,回滚只需要拉取仓库的镜像后直接run起来即可,回滚也是如此,而且他的备份可以直接打包成tar.gz压缩包,解压到其他机器,部署docker应用后,即可恢复。一,本地仓库下载1.1,参考本站中docker本地仓库搭建,链接:Docker本地仓库简单使用1.2,安装docker run -d -p 5000:5000 registry这时候可以看到运行了两个容器[root@linuxea-com ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ebe95cb71671 registry "/entrypoint.sh /etc/" 2 minutes ago Up 2 minutes 0.0.0.0:5000->5000/tcp tender_wright ca797ad15342 centos "bash" 20 hours ago Up 20 hours test [root@linuxea-com ~]# 二,构建一个docker的nginx镜像首先,构建一个nginx基础镜像, 只需要将日志放出来即可。当构建完成后,在编写一个Dockerfile,在本地通过git pull拉取代码到,COPY将本地代码复制到容器中后,build镜像并且push到本地仓库,此时。便可以使用远端docker pull拉取。其中每次构建会拿git reflog中的版本好做标记,回滚也是需要用上标记的版本号。如下图:docker基础镜像Dockfile和代码构建的Dockfile,在github上存储,直接可以拿来使用#!/bin/bash ######################################################################### # File Name: jc.sh:wq # Author: www.linuxea.com # Email: usertzc@gmail.com # Version: # Created Time: 2016年12月31日 星期六 16时15分16秒 ######################################################################### wwwp=/wwwroot/docker mkdir -p $wwwp curl -Lks4 https://raw.githubusercontent.com/LinuxEA-Mark/jenkins_gitlab/master/Dockerfile -o $wwwp/Dockerfile cd $wwwp && docker build -t nginx . && rm -rf Dockerfile culr -Lks4 https://raw.githubusercontent.com/LinuxEA-Mark/jenkins_gitlab/master/jenkins/Dockerfile -o $wwwp/Dockerfile我们下载一个脚本[root@linuxea-com ~]# curl -Lks4 https://raw.githubusercontent.com/LinuxEA-Mark/jenkins_gitlab_Docker/master/docker_fabu.sh -o /wwwroot/docker/docker_fabu.sh [root@linuxea-com ~]# chmod +x /wwwroot/docker/docker_fabu.sh [root@linuxea-com ~]# chown jenkins.jenkins /wwwroot/docker/docker_fabu.sh脚本最终是由jenkins运行,需要在visudo中注释掉Defaults requiretty,添加jenkins的命令权限,如下:[root@linuxea-com ~]# sed -i '/requiretty /s/^/#&/' /etc/visudoer [root@linuxea-com ~]# echo jenkins ALL = (root)NOPASSWD:/usr/bin/docker,(root)NOPASSWD:/usr/local/bin/docker-compose,(root)NOPASSWD:/bin/rm,(root)NOPASSWD:/bin/cp,(ALL)NOPASSWD:/usr/bin/git >> /etc/visudoer在wwwroot目录下,克隆一次代码[root@linuxea-com /wwwroot]# git clone git@10.0.1.61:root/docker_test.git 正克隆到 'docker_test'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) 接收对象中: 100% (6/6), done.三,jenkins构建和之前的几乎一样,创建自由风格,细节可参考git+jenkins发布和回滚示例 将jenkins和gitlab关联!这里指向脚本存放位置可以参考上一篇文章中的步骤,本章只是换了docker,加了docker仓库,其他没变:git+jenkins发布和回滚示例
2016年12月31日
11,487 阅读
0 评论
0 点赞
2016-12-30
git+jenkins发布和回滚示例
1, install gitlab[root@linuxea-com ]# yum install curl policycoreutils openssh-server openssh-clients [root@linuxea-com ]# systemctl enable sshd [root@linuxea-com ]# systemctl start sshd [root@linuxea-com ]# yum install postfix [root@linuxea-com ]# systemctl enable postfix [root@linuxea-com ]# systemctl start postfix [root@linuxea-com ]# systemctl mask firewalld [root@linuxea-com ]# systemctl stop firewalld [root@linuxea-com ]# yum install epel* -y [root@linuxea-com ]# yum -y install iptables-devel iptables-services iptables vim wget bash-completion-extras.noarch [root@linuxea-com ]# systemctl enable iptables [root@linuxea-com ]# systemctl start iptables [root@linuxea-com ]# iptables -F [root@linuxea-com ]# curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh |bash [root@linuxea-com ]# yum install gitlab-ce-8.15.1-ce.0.el7.x86_64 或者直接下载 [root@linuxea-com ]# axel -n 30 https://packages.gitlab.com/gitlab/gitlab-ce/packages/ol/7/gitlab-ce-8.15.1-ce.0.el7.x86_64.rpm [root@linuxea-com ]# gitlab-ctl reconfigure 修改external_url [root@linuxea-com ]# vim /etc/gitlab/gitlab.rb external_url 'http://10.10.239.222' 登陆账户 root 5iveL!fe其他文章推荐如下:官网安装:http://www.linuxea.com/1407.html国内源安装:http://www.fblinux.com/?p=6622, install jenkins[root@linuxea-com ]# curl -Lks4 http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo -o /etc/yum.repos.d/jenkins.repo [root@linuxea-com ]# rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key [root@linuxea-com ]# yum install jenkinsjenkins安装部署文章推荐:http://www.fblinux.com/?p=7053,配置我这里的git和jenkins分离开的,当gitlab和jenkins分别安装配置完成后,开始做一些简单的部署测试。我这里使用ansible的synchronize来进行推送,我们先在jenkins上安装ansible,可以参考第二步中西门飞雪博客的文章,这里关键提到的是推送代码和回滚3.1 安装ansible配置hosts[root@linuxea-com /var/lib/jenkins]# yum install ansible -y配置hosts,最终脚本以jenkins用户执行,这里需要指定ansible_ssh_user=root[root@linuxea-com /var/lib/jenkins]# cat /etc/ansible/hosts [php] 10.57.57.57 ansible_ssh_user=root3.2 配置jenkins在jenkins中配置一个自由风格的项目,配置好源码管理git在参数化构建过程选项卡中,设置如下:在构建的Execute shell的command中,写入如下:如果reset默认值为default(参数化构建过程 设置,如上图),也就是传入参数为空,则会执行脚本触发更新和发布,如果传入latest则运行git reset --hard HEAD^回退一个版本后进行发布,如果传入的不是latest,也不为空,则会进行git reset --hard进行固定版本好回退ff.sh脚本如下#!/bin/bash ######################################################################### # File Name: ff.sh # Author: mark # Email: usertzc@gmail.com # Version: # Created Time: 2016年12月27日 星期二 19时20分10秒 ######################################################################### wwwgit=/var/lib/jenkins/jenkins/ wwwroot=/data/wwwroot if [ $# == 1 ];then banbenhao=`echo $1` cd $wwwgit if [ $banbenhao == 'latest' ];then git reset --hard HEAD^ else git reset --hard $banbenhao fi ansible php -m synchronize -a "src=${wwwgit} dest=${wwwroot} rsync_opts=--delete" ansible php -a "chown -R www.www ${wwwroot}" else cd ${wwwgit} && git pull ansible php -m synchronize -a "src=${wwwgit} dest=${wwwroot} rsync_opts=--delete" ansible php -a "chown -R www.www ${wwwroot}" fi
2016年12月30日
17,364 阅读
2 评论
0 点赞
2016-08-29
gitlab文章内目录超链接
在gitlab中,目录的链接形式如果有空格,逗号冒号之类的将会被转义,如果用通常的办法是无法做文章内超链接的,如下图即可将url链接复制添加即可最终如下图:
2016年08月29日
4,359 阅读
0 评论
0 点赞
2016-08-23
gitlab入门操作笔记
如果你觉得本章对你有所收获,你可以在文章下方点击附件pdf文档下载一,Git基础操作1.1 git用户属性设置在开始我们需要声明下自己是谁,自己的邮箱是什么,这样方便我们后续的查询和管理git config --global user.name "USERNAME" git config --global user.email "USER@MAIL"示例: [root@localhost ~]# git config --global user.name "mark" [root@localhost ~]# git config --global user.email "user@163.com" [root@localhost ~]# git config --list user.name=mark user.email=user@163.com 1.2 颜色高亮在后续使用中可能会用到颜色高亮,设置如下:[root@localhost ~]# git config --global color.ui true [root@localhost ~]# git config --list user.name=mark user.email=user@163.com color.ui=true [root@localhost ~]# 二,Git仓库基本操作说明2.1 初始化本地仓库在初始化之前,我们仍然需要创建一个文件夹。[root@localhost ~]# mkdir git0819 && cd git0819/ [root@localhost git0819]# git init初始化空的 Git 版本库于 /root/git0819/.git/当初始化成功后会出现三个文件,我们不建议你修改这2两个文件内容[root@localhost git0819]# ls -a . .. .git 2.2 git文件提交我们追加一个字符串到readme.txt中[root@localhost git0819]# echo "1 helo git" readme.txt [root@localhost git0819]# cat readme.txt 1 helo git 2.2.1 git add追加完成后使用git add来进行提交到暂存区[root@localhost git0819]# git add readme.txt 2.2.2 git status请注意: 在每次使用git add提交到暂存区时,可以使用git status来查看,提交的分之,和第几次提交,提交的文件信息,如下所示:[root@localhost git0819]# git status # 位于分支 master # # 初始提交 # # 要提交的变更: # (使用 "git rm --cached <file>..." 撤出暂存区) # # 新文件: readme.txt # [root@localhost git0819]# 2.2.3 git commit当git add到暂存区后我们使用git commit -m "备注"来提交[root@localhost git0819]# git commit -m "the file commit" [master(根提交) 5ea98f2] the file commit 1 file changed, 1 insertion(+) create mode 100644 readme.txt [root@localhost git0819]# 当提交完成后,在使用git status查看工作目录则为干净的状态,由此可见,我们可以用git status来查看我们是否提交等信息[root@localhost git0819]# git status # 位于分支 master 无文件要提交,干净的工作区 2.2.3.1 修改最后一次提交有时候我们提交完了才发现漏掉了几个文件没有加,或者提交信息写错了。想要撤消刚才的提交操作,可以使用 --amend 选项重新提交:$ git commit --amend此命令将使用当前的暂存区域快照提交。如果刚才提交完没有作任何改动,直接运行此命令的话,相当于有机会重新编辑提交说明,但将要提交的文件快照和之前的一样。启动文本编辑器后,会看到上次提交时的说明,编辑它确认没问题后保存退出,就会使用新的提交说明覆盖刚才失误的提交。如果刚才提交时忘了暂存某些修改,可以先补上暂存操作,然后再运行 --amend 提交:$ git commit -m 'initial commit' $ git add forgotten_file $ git commit --amend 上面的三条命令最终只是产生一个提交,第二个提交命令修正了第一个的提交内容。2.2.3.2 取消已经暂存的文件如何取消工作目录中已修改的文件。git status查看文件状态的时候就提示了该如何撤消来看下面的例子,有两个修改过的文件,我们想要分开提交,但不小心用 git add . 全加到了暂存区域。该如何撤消暂存其中的一个文件呢?其实,git status 的命令输出已经告诉了我们该怎么做:$ git add . $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: README.txt modified: benchmarks.rb 就在 “Changes to be committed” 下面,括号中有提示,可以使用 git reset HEAD ... 的方式取消暂存。好吧,我们来试试取消暂存 benchmarks.rb 文件:$ git reset HEAD benchmarks.rb Unstaged changes after reset: M benchmarks.rb $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: README.txt Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: benchmarks.rb 现在 benchmarks.rb 文件又回到了之前已修改未暂存的状态。2.3.3.3 取消对文件的修改如果觉得刚才对 某个文件的修改完全没有必要,该如何取消修改,回到之前的状态(也就是修改之前的版本)呢?git status 同样提示了具体的撤消方法,接着上面的例子,现在未暂存区域看起来像这样:Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: benchmarks.rb 如下:$ git checkout -- benchmarks.rb $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: README.txt 可以看到,该文件已经恢复到修改前的版本。你可能已经意识到了,这条命令有些危险,所有对文件的修改都没有了,因为我们刚刚把之前版本的文件复制过来重写了此文件。所以在用这条命令前,请务必确定真的不再需要保留刚才的修改。如果只是想回退版本,同时保留刚才的修改以便将来继续工作,可以用分支来处理,应该会更好些。2.2.3.4 移除文件要从 Git 中移除某个文件,就必须要从已跟踪文件清单中移除(确切地说,是从暂存区域移除),然后提交。可以用 git rm 命令完成此项工作,并连带从工作目录中删除指定的文件,这样以后就不会出现在未跟踪文件清单中了。如果只是简单地从工作目录中手工删除文件,运行 git status 时就会在 “Changes not staged for commit” 部分(也就是未暂存清单)看到:$ rm grit.gemspec $ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: grit.gemspec no changes added to commit (use "git add" and/or "git commit -a")然后再运行 git rm 记录此次移除文件的操作:$ git rm grit.gemspec rm 'grit.gemspec' $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: grit.gemspec最后提交的时候,该文件就不再纳入版本管理了。如果删除之前修改过并且已经放到暂存区域的话,则必须要用强制删除选项 -f(译注:即 force 的首字母),以防误删除文件后丢失修改的内容。另外一种情况是,我们想把文件从 Git 仓库中删除(亦即从暂存区域移除),但仍然希望保留在当前工作目录中。换句话说,仅是从跟踪清单中删除。比如一些大型日志文件或者一堆 .a 编译文件,不小心纳入仓库后,要移除跟踪但不删除文件,以便稍后在 .gitignore 文件中补上,用 --cached 选项即可:$ git rm --cached readme.txt 后面可以列出文件或者目录的名字,也可以使用 glob 模式。比方说:$ git rm log/\*.log 注意到星号 * 之前的反斜杠 \,因为 Git 有它自己的文件模式扩展匹配方式,所以我们不用 shell 来帮忙展开(译注:实际上不加反斜杠也可以运行,只不过按照 shell 扩展的话,仅仅删除指定目录下的文件而不会递归匹配。上面的例子本来就指定了目录,所以效果等同,但下面的例子就会用递归方式匹配,所以必须加反斜杠。)。此命令删除所有 log/ 目录下扩展名为 .log 的文件。类似的比如:$ git rm \*~ 会递归删除当前目录及其子目录中所有 ~ 结尾的文件。2.2.3.5 移动文件不像其他的 VCS 系统,Git 并不跟踪文件移动操作。如果在 Git 中重命名了某个文件,仓库中存储的元数据并不会体现出这是一次改名操作。不过 Git 非常聪明,它会推断出究竟发生了什么,至于具体是如何做到的,我们稍后再谈。既然如此,当你看到 Git 的 mv 命令时一定会困惑不已。要在 Git 中对文件改名,可以这么做:$ git mv file_from file_to 它会恰如预期般正常工作。实际上,即便此时查看状态信息,也会明白无误地看到关于重命名操作的说明:$ git mv README.txt README $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: README.txt -> README其实,运行 git mv 就相当于运行了下面三条命令:$ mv README.txt README $ git rm README.txt $ git add README 如此分开操作,Git 也会意识到这是一次改名,所以不管何种方式都一样。当然,直接用 git mv 轻便得多,不过有时候用其他工具批处理改名的话,要记得在提交前删除老的文件名,再添加新的文件名。2.2.4 git暂存区和工作区当我们在使用时,可以add多次到暂存区,而后一次commit到工作区,如果没有暂存区则无法到工作区[root@localhost git0819]# echo 'is me mark' >> readme.txt [root@localhost git0819]# git add readme.txt [root@localhost git0819]# echo 'is me mark 1' >> readme.txt [root@localhost git0819]# git add readme.txt [root@localhost git0819]# git commit -m "is me mark" [master 10325bb] is me mark 1 file changed, 1 insertion(+) [root@localhost git0819]# 2.3 查看历史提交信息git log[root@localhost git0819]# git log commit 87ad99a080362adb10c07e80e0f75428d96120ac Author: mark <usertzc@163.com> Date: Fri Aug 19 22:31:20 2016 +0800 2th commit commit 5ea98f29e0d591ec2583eacf3af6e4df802ff356 Author: mark <usertzc@163.com> Date: Fri Aug 19 22:24:47 2016 +0800 the file commit [root@localhost git0819]# 如上所示,当你输入git log后,你会看到commit的效验和,和提交人已经实际,和备注信息,提交的次数等其他选项:-p:展开显示每次提交的内容差异git log -p -2-2:-2仅显示最近的两次更新2.4 文件比对git diff当我们修改了文件后可以使用git diff来进行文件比对示例如下:[root@localhost git0819]# echo 2 helo github >> readme.txt [root@localhost git0819]# git diff readme.txt diff --git a/readme.txt b/readme.txt index 74da0d9..eab080a 100644 --- a/readme.txt +++ b/readme.txt @@ -1 +1,2 @@ 1 helo git +2 helo github [root@localhost git0819]# 其他选项:当然,你也可以控制对比的条目:git log -U1 --word-diff -U1:如果你有三行,-U1选项则会显示1行另外,git log还提供了许多摘要选项,比如 --stat,仅显示摘要行数统计:git log --stat--pretty 选项,另外还有short,full 和 fuller可以指定使用完全不同于默认格式的方式展示提交历史当我们修改文件后,也就是文件发送改变,这时如果要让修改后的文件生效,仍然需要再次提交[root@localhost git0819]# git add readme.txt [root@localhost git0819]# git commit -m "readme.txt 2" [master 3fc47d0] readme.txt 2 1 file changed, 1 insertion(+) [root@localhost git0819]# git log commit 3fc47d0453dedf1923a5145562451d5157f75050 Author: mark <usertzc@163.com> Date: Fri Aug 19 22:35:45 2016 +0800 readme.txt 2 commit 87ad99a080362adb10c07e80e0f75428d96120ac Author: mark <usertzc@163.com> Date: Fri Aug 19 22:31:20 2016 +0800 2th commit commit 5ea98f29e0d591ec2583eacf3af6e4df802ff356 Author: mark <usertzc@163.com> Date: Fri Aug 19 22:24:47 2016 +0800 the file commit [root@localhost git0819]# 三,版本回退3.1 回退到上一个版本git reset --hard使用说明:这里不得不说的是在git中的另外一个命令git reset --hard,使用此命令我们能够回到任意一个版本git reset --hard HEAD,其中HEAD表示当前版本,HEAD^表示上一个版本,HEAD^^表示上上一个版本,HEAD^^^表示上上一个版本回退实例:在开始前我将一个文件删掉,在创建同样的文件,输入不同的内容进行回退:[root@localhost git0820]# cat readme.txt date +%F-%T [root@localhost git0820]# rm -rf readme.txt [root@localhost git0820]# ls dev.txt 分别提交三次不同的内容到readme.txt中,commit 名称分别是2 helo git 和3 helo git和4 helo git[root@localhost git0819]# echo 2 helo git >> readme.txt [root@localhost git0819]# git add readme.txt [root@localhost git0819]# git commit -m "2 helo git" [master a006a08] 2 helo git 1 file changed, 1 insertion(+) [root@localhost git0819]# echo 3 helo git >> readme.txt [root@localhost git0819]# git add readme.txt [root@localhost git0819]# git commit -m "3 helo git" [master cca52f3] 3 helo git 1 file changed, 1 insertion(+) [root@localhost git0819]# echo 4 helo git >> readme.txt [root@localhost git0819]# git add readme.txt [root@localhost git0819]# git commit -m "4 helo git" [master e9f932b] 4 helo git 1 file changed, 1 insertion(+) [root@localhost git0819]# 我们先回退到第一个版本[root@localhost git0819]# git reset --hard HEAD^HEAD 现在位于 cca52f3 3 helo git回退上两个版本[root@localhost git0819]# git reset --hard HEAD^^ HEAD 现在位于 5ea98f2 the file commit [root@localhost git0819]# cat readme.txt 1 helo git [root@localhost git0819]# 我提交三次,回退三次后就到了删除前的版本,回退正常。内容如下:[root@localhost git0820]# cat readme.txt date +%F-%T 请注意: 你会发现,当你回退到之前后,在此期间提交三次log是不会存在的,这相当于做了一次时空逆转,git log是看不到回退期间提交的日志3.2 回退到指定版本git reflog可以查看历史版本,我们可以使用git reset --herad 版本号即可回退到指定版本示例如下:[root@localhost git0819]# git reflog 5ea98f2 HEAD@{0}: reset: moving to HEAD^^ cca52f3 HEAD@{1}: reset: moving to HEAD^ e9f932b HEAD@{2}: commit: 4 helo git cca52f3 HEAD@{3}: commit: 3 helo git a006a08 HEAD@{4}: commit: 2 helo git 5ea98f2 HEAD@{5}: reset: moving to HEAD^^ 7cf1ea2 HEAD@{6}: commit: git 4 87ad99a HEAD@{7}: reset: moving to HEAD^ 3fc47d0 HEAD@{8}: commit: readme.txt 2 87ad99a HEAD@{9}: commit: 2th commit 5ea98f2 HEAD@{10}: commit (initial): the file commit我们指定一个版本号进行回退:[root@localhost git0819]# git reset --hard a006a08 HEAD 现在位于 a006a08 2 helo git [root@localhost git0819]# cat readme.txt 1 helo git 2 helo git [root@localhost git0819]# 四,关联到gitlab4.1 git lab New project第一步:我们打开gitlab,成功登陆后 选择右上角的+号 New project第二步:创建完成后会在调转的页面复制ssh中一行:如下所示4.2 ssh key在需要链接gitlab的主机上生成key,一路回车即可[root@localhost 0822]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 72:8a:c4:87:cb:d3:f6:35:5c:95:24:a6:7e:24:49:fc root@150 The key's randomart image is: +--[ RSA 2048]----+ | .. o . | | ..+ o . | | +.. o | | . . . oE. | | + o S . o | | o = + . o | | = + + | | o . . . | | . | +-----------------+ [root@localhost 0822]# 将id_rsa.pub内容复制到剪切板[root@localhost 0822]# cat /USERNAME/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5kmoitUCzznv00m2GgK66ksHpTQHYcQR/dOhKgRI9ut8YAHJC6LjfddWad+2/az6k1E6ecTbTvJNJnWQl3qv16E+MR6WSMvHWXyQT5t5w0mqBKDvITgXoZbmQW6QzVBYmy295T/IIbVxefv/rMmjHyj330DSZdad/MdcwvtfTZBvBAhBUXp28ifbEIMj00wYL7qspobniVDPjvcjkwYbhUqn0CjZdkXgcdSdyhEdcI1aLy3Ps/s3oyxXz/7jhrpI4s01Gx39caXX6e3Jn2oy8Ds8qcyhCTgFnt9QWEL6SOYX42FqHhOUxwSN3+/jOcj+c6zuZUanRch85QTplaiY1 root@150 [root@localhost 0822]# 现在回到gitlab web界面,在profile settings中选择ssh keys添加即可,如下图所示:4.3 将本地文件提交到gitlab创建目录,初始化,echo date +%T-%F > mark.txt文件中后提交[root@localhost ~]# mkdir 0822 [root@localhost ~]# cd 0822/ [root@localhost 0822]# ls [root@localhost 0822]# git config --global user.name "mark" [root@localhost 0822]# git config --global user.email "usertzc@163.com" [root@localhost 0822]# git init 初始化空的 Git 版本库于 /root/0822/.git/ [root@localhost 0822]# echo `date +%T-%F` > mark.txt [root@localhost 0822]# git add mark.txt [root@localhost 0822]# git commit -m "1th mark" [master(根提交) 772d967] 1th mark 1 file changed, 1 insertion(+) create mode 100644 mark.txt git remote add origin git@10.10.239.222:root/master.git这段操作可以在4.1的第二步中看到[root@localhost 0822]# git remote add origin git@10.10.239.222:root/master.git [root@localhost 0822]# cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = git@10.10.239.222:root/master.git fetch = +refs/heads/*:refs/remotes/origin/* [root@localhost 0822]# git add mark.txt [root@localhost 0822]# git commit -m "1th mark" # 位于分支 master 无文件要提交,干净的工作区 [root@localhost 0822]# git push -u origin master Counting objects: 3, done. Writing objects: 100% (3/3), 222 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@10.10.239.222:root/master.git * [new branch] master -> master 分支 master 设置为跟踪来自 origin 的远程分支 master 当push完成后,我们打开gitlab,在左上角点击后,选择project,你会发现有最新的提交也可看到内容4.4 远程仓库的使用4.4.1 查看当前的远程库要查看当前配置有哪些远程仓库,可以用 git remote 命令,它会列出每个远程库的简短名字。在克隆完某个项目后,至少可以看到一个名为 origin 的远程库,Git 默认使用这个名字来标识你所克隆的原始仓库:$ git clone git://github.com/schacon/ticgit.git Cloning into 'ticgit'... remote: Reusing existing pack: 1857, done. remote: Total 1857 (delta 0), reused 0 (delta 0) Receiving objects: 100% (1857/1857), 374.35 KiB | 193.00 KiB/s, done. Resolving deltas: 100% (772/772), done. Checking connectivity... done. $ cd ticgit $ git remote origin 也可以加上 -v 选项(译注:此为 --verbose 的简写,取首字母),显示对应的克隆地址:$ git remote -v origin git://github.com/schacon/ticgit.git (fetch) origin git://github.com/schacon/ticgit.git (push) 如果有多个远程仓库,此命令将全部列出。比如在我的 Grit 项目中,可以看到:$ cd grit $ git remote -v bakkdoor git://github.com/bakkdoor/grit.git cho45 git://github.com/cho45/grit.git defunkt git://github.com/defunkt/grit.git koke git://github.com/koke/grit.git origin git@github.com:mojombo/grit.git 这样一来,我就可以非常轻松地从这些用户的仓库中,拉取他们的提交到本地。请注意,上面列出的地址只有 origin 用的是 SSH URL 链接,所以也只有这个仓库我能推送数据上去4.4.2 添加远程仓库要添加一个新的远程仓库,可以指定一个简单的名字,以便将来引用,运行 git remote add [shortname] [url]:$ git remote origin $ git remote add pb git://github.com/paulboone/ticgit.git $ git remote -v origin git://github.com/schacon/ticgit.git pb git://github.com/paulboone/ticgit.git 现在可以用字符串 pb 指代对应的仓库地址了。比如说,要抓取所有 Paul 有的,但本地仓库没有的信息,可以运行 git fetch pb:$ git fetch pb remote: Counting objects: 58, done. remote: Compressing objects: 100% (41/41), done. remote: Total 44 (delta 24), reused 1 (delta 0) Unpacking objects: 100% (44/44), done. From git://github.com/paulboone/ticgit * [new branch] master -> pb/master * [new branch] ticgit -> pb/ticgit 现在,Paul 的主干分支(master)已经完全可以在本地访问了,对应的名字是 pb/master,你可以将它合并到自己的某个分支,或者切换到这个分支,看看有些什么更新。4.4.3 从远程仓库抓取数据正如之前所看到的,可以用下面的命令从远程仓库抓取数据到本地:$ git fetch [remote-name]此命令会到远程仓库中拉取所有你本地仓库中还没有的数据。运行完成后,你就可以在本地访问该远程仓库中的所有分支,将其中某个分支合并到本地,或者只是取出某个分支,一探究竟。如果是克隆了一个仓库,此命令会自动将远程仓库归于 origin 名下。所以,git fetch origin 会抓取从你上次克隆以来别人上传到此远程仓库中的所有更新(或是上次 fetch 以来别人提交的更新)。有一点很重要,需要记住,fetch 命令只是将远端的数据拉到本地仓库,并不自动合并到当前工作分支,只有当你确实准备好了,才能手工合并。如果设置了某个分支用于跟踪某个远端仓库的分支(可以使用 git pull 命令自动抓取数据下来,然后将远端分支自动合并到本地仓库中当前分支。在日常工作中我们经常这么用,既快且好。实际上,默认情况下 git clone 命令本质上就是自动创建了本地的 master 分支用于跟踪远程仓库中的 master 分支(假设远程仓库确实有 master 分支)。所以一般我们运行 git pull,目的都是要从原始克隆的远端仓库中抓取数据后,合并到工作目录中的当前分支。4.4.4 推送到远程仓库$ git push origin master 只有在所克隆的服务器上有写权限,或者同一时刻没有其他人在推数据,这条命令才会如期完成任务。如果在你推数据前,已经有其他人推送了若干更新,那你的推送操作就会被驳回。你必须先把他们的更新抓取到本地,合并到自己的项目中,然后才可以再次推送。推送远程仓库在4.3中已经提到4.4.5 查看远程仓库信息我们可以通过命令 git remote show [remote-name] 查看某个远程仓库的详细信息,比如要看所克隆的 origin 仓库,可以运行:$ git remote show origin * remote origin URL: git://github.com/schacon/ticgit.git Remote branch merged with 'git pull' while on branch master master Tracked remote branches master ticgit 除了对应的克隆地址外,它还给出了许多额外的信息。它友善地告诉你如果是在 master 分支,就可以用git pull 命令抓取数据合并到本地。另外还列出了所有处于跟踪状态中的远端分支。上面的例子非常简单,而随着使用 Git 的深入,git remote show 给出的信息可能会像这样:$ git remote show origin * remote origin URL: git@github.com:defunkt/github.git Remote branch merged with 'git pull' while on branch issues issues Remote branch merged with 'git pull' while on branch master master New remote branches (next fetch will store in remotes/origin) caching Stale tracking branches (use 'git remote prune') libwalker walker2 Tracked remote branches acl apiv2 dashboard2 issues master postgres Local branch pushed with 'git push' master:master 它告诉我们,运行 git push 时缺省推送的分支是什么(译注:最后两行)。它还显示了有哪些远端分支还没有同步到本地(译注:第六行的 caching 分支),哪些已同步到本地的远端分支在远端服务器上已被删除(译注:Stale tracking branches 下面的两个分支),以及运行 git pull 时将自动合并哪些分支(译注:前四行中列出的 issues 和 master 分支)。4.4.6 远程仓库的删除和重命名可以用 git remote rename 命令修改某个远程仓库在本地的简称,比如想把 pb 改成paul,可以这么运行:$ git remote rename pb paul $ git remote origin paul 注意,对远程仓库的重命名,也会使对应的分支名称发生变化,原来的 pb/master 分支现在成了paul/master。通常我们在web中进行修改碰到远端仓库服务器迁移,或者原来的克隆镜像不再使用,又或者某个参与者不再贡献代码,那么需要移除对应的远端仓库,可以运行 git remote rm 命令:$ git remote rm paul $ git remote origin五,分之使用5.1 git branch命令使用创建分之使用git branch 即可查看当前在什么分之使用:git branch切换分之使用:git checkout dev删除分之:git branch -d dev查看各个分支最后一次提交的对象信息:git branch -v查看哪些分支已被并入当前分支:git branch --merged一般来说,列表中没有 * 的分支通常都可以用 git branch -d 来删掉。原因很简单,既然已经把它们所包含的工作整合到了其他分支,删掉也不会损失什么。如:$ git branch --no-merged testing 另外可以用 git branch --no-merged 查看尚未合并的工作,它会显示还未合并进来的分支。由于这些分支中还包含着尚未合并进来的工作成果,所以简单地用 git branch -d 删除该分支会提示错误,因为那样做会丢失数据:$ git branch -d testing error: The branch 'testing' is not fully merged. If you are sure you want to delete it, run 'git branch -D testing'. 不过,如果你确实想要删除该分支上的改动,可以用大写的删除选项 -D 强制执行,就像上面提示信息中给出的那样。部分命令使用如下:[root@localhost 0822]# git branch dev [root@localhost 0822]# git branch dev * master [root@localhost 0822]# git checkout dev 切换到分支 'dev' [root@localhost 0822]# git branch * dev master [root@localhost 0822]# 5.2 分之合并分之中的文件在没有合并的情况下都是独立的。如:在已经创建的dev分之中创建一个文件,这个文件只能在dev分之中看到示例:当我在dev分之创建一个文dev.txt件在master分之中是看不到的,我现在将一个dev的分之合并到主干master中5.2.1 演示分之上传[root@localhost 0822]# echo "`date +%T-%F`dev" > dev.txt [root@localhost 0822]# cat dev.txt 17:08:56-2016-08-22dev [root@localhost 0822]# git add dev.txt [root@localhost 0822]# git commit -m "1th dev" [dev fb8d8ba] 1th dev 1 file changed, 1 insertion(+) create mode 100644 dev.txt [root@localhost 0822]# git push origin dev Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@10.10.239.222:root/master.git * [new branch] dev -> dev [root@localhost 0822]# 提交完成后打开web界面查看,dev已经存在在master下5.3 git merge 合并分之我们需要切换到master分之后,在使用git merge 分之名称 来合并dev[root@localhost 0822]# git checkout master 切换到分支 'master' [root@localhost 0822]# ls mark.txt [root@localhost 0822]# git merge dev 更新 772d967..fb8d8ba Fast-forward dev.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 dev.txt [root@localhost 0822]# ll 总用量 8 -rw-r--r--. 1 root root 23 8月 22 17:15 dev.txt -rw-r--r--. 1 root root 20 8月 22 16:20 mark.txt [root@localhost 0822]# 请注意:在合并分之的时候会出现一些问题,如下:假设有两个分支,分别是master和dev,现在master分支下又一个文件叫做top.txt,dev分支下也有一个top.txt,并且两个分支下的top.txt都不相同是会出现合并不成功的。六,轻量级标签管理轻量级标签实际上就是一个保存着对应提交对象的校验和信息的文件6.1 当前提交版本时间点打标签在之前, 我们已经将分之合并到master中,现在master中有两个文件,分别是dev.txt mark.txt,现在,对当前打taggit tag TAGNAME :打标签git tag :查看当前分之标签git show v1 查看当前标签[root@localhost 0822]# git tag v1 [root@localhost 0822]# git tag v1 [root@localhost 0822]# git show v1 commit fb8d8ba23030863245a9c8342b3b961937f93c44 Author: mark <usertzc@163.com> Date: Mon Aug 22 17:09:11 2016 +0800 1th dev diff --git a/dev.txt b/dev.txt new file mode 100644 index 0000000..0477007 --- /dev/null +++ b/dev.txt @@ -0,0 +1 @@ +17:08:56-2016-08-22dev [root@localhost 0822]# 6.2 推送标签[root@localhost 0822]# git push origin v1 Total 0 (delta 0), reused 0 (delta 0) To git@10.10.239.222:root/master.git * [new tag] v1 -> v1 推送标签,使用git push origin TAGNAME即可6.3 拉取标签git clone --bare :如果 git clone 出来的话,就是其中 .git 的目录;如果 git clone --bare 的话,新建的目录本身就是 Git 目录我在另外一台机器上重新拉取标签[root@localhost gitlab]# mkdir gitlab && cd gitlab && git init [root@localhost gitlab]# git clone git@10.10.239.222:root/master.git 正克隆到 'master'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) 接收对象中: 100% (6/6), done. 当克隆本地后,你会发现只有一个文件,[root@localhost gitlab]# cd master/ && ls mark.txt [root@localhost master]# cat mark.txt 16:20:03-2016-08-22 我们拉取到标签内的版本[root@localhost master]# git checkout v1 Note: checking out 'v1'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD 目前位于 fb8d8ba... 1th dev [root@localhost master]# ls dev.txt mark.txt [root@localhost master]# 6.4 后期添加标签[root@localhost 0822]# echo 3 th up > 3th.txt [root@localhost 0822]# git add 3th.txt [root@localhost 0822]# ls 3th.txt dev.txt mark.txt [root@localhost 0822]# git commit -m "3th up" [master be7d412] 3th up 1 file changed, 1 insertion(+) create mode 100644 3th.txt [root@localhost 0822]# git pull origin master 来自 10.10.239.222:root/master * branch master -> FETCH_HEAD Already up-to-date. [root@localhost 0822]# ls 3th.txt dev.txt mark.txt 查看push次数和校验和:[root@localhost 0822]# git log --pretty=oneline be7d4125b7f7563b3b55fc57a8abd1d0d897dd36 3th up fb8d8ba23030863245a9c8342b3b961937f93c44 1th dev 772d9674472af6cf9797f95f9d40ffe6bcb63a62 1th mark [root@localhost 0822]# git tag -a v4 校验和即可[root@localhost 0822]# git tag -a v4 be7d4125b7f7563b3b55fc57a8abd1d0d897dd36 -m "4th" [root@localhost 0822]# git push origin v4 Counting objects: 1, done. Writing objects: 100% (1/1), 148 bytes | 0 bytes/s, done. Total 1 (delta 0), reused 0 (delta 0) To git@10.10.239.222:root/master.git * [new tag] v4 -> v4 修改标签后在进行推送git push origin 标签号如果一次推送所有本地新增标签,可以使用git push origin --tags七,忽略文件一般我们总会有些文件无需纳入 Git 的管理,也不希望它们总出现在未跟踪文件列表。通常都是些自动生成的文件,比如日志文件,或者编译过程中创建的临时文件等。我们可以创建一个名为 .gitignore 的文件,列出要忽略的文件模式。来看一个实际的例子:$ cat .gitignore*.[oa]*~第一行告诉 Git 忽略所有以 .o 或 .a 结尾的文件。一般这类对象文件和存档文件都是编译过程中出现的,我们用不着跟踪它们的版本。第二行告诉 Git 忽略所有以波浪符(~)结尾的文件,许多文本编辑软件(比如 Emacs)都用这样的文件名保存副本。此外,你可能还需要忽略 log,tmp 或者 pid 目录,以及自动生成的文档等等。要养成一开始就设置好 .gitignore 文件的习惯,以免将来误提交这类无用的文件。文件 .gitignore 的格式规范如下:所有空行或者以注释符号 # 开头的行都会被 Git 忽略。可以使用标准的 glob 模式匹配。匹配模式最后跟反斜杠(/)说明要忽略的是目录。要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(!)取反。所谓的 glob 模式是指 shell 所使用的简化了的正则表达式。星号(*)匹配零个或多个任意字符;[abc]匹配任何一个列在方括号中的字符(这个例子要么匹配一个 a,要么匹配一个 b,要么匹配一个 c);问号(?)只匹配一个任意字符;如果在方括号中使用短划线分隔两个字符,表示所有在这两个字符范围内的都可以匹配(比如 [0-9] 表示匹配所有 0 到 9 的数字)。我们再看一个 .gitignore 文件的例子:# 此为注释 – 将被 Git 忽略 # 忽略所有 .a 结尾的文件 *.a # 但 lib.a 除外 !lib.a # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO /TODO # 忽略 build/ 目录下的所有文件 build/ # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt doc/*.txt # ignore all .txt files in the doc/ directory doc/**/*.txtgit-for-windows.pdfgitlab使用说明
2016年08月23日
6,625 阅读
0 评论
0 点赞
2016-08-23
rpm部署gitlab-ce-8.10.6
sysinfo[root@10 gitlab]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@10 gitlab]# uname -a Linux gitlab 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux 安装gitlab下载一个最新的gitlab安装包安裝依賴yum install curl policycoreutils openssh-server openssh-clients 安裝下載好的安裝包,這裡用的是8.10.6yum localinstall yum install gitlab-ce-8.10.6-ce.0.el7.x86_64.rpm -y 開始配置gitlab-ctl reconfigure 登錄密碼root 5iveL!fe 查看狀態[root@localhost ~]# gitlab-ctl status run: gitlab-workhorse: (pid 23393) 159s; run: log: (pid 23195) 175s run: logrotate: (pid 23352) 167s; run: log: (pid 23351) 167s run: nginx: (pid 23240) 173s; run: log: (pid 23239) 173s run: postgresql: (pid 22953) 205s; run: log: (pid 22952) 205s run: redis: (pid 22816) 211s; run: log: (pid 22815) 211s run: sidekiq: (pid 23151) 181s; run: log: (pid 23150) 181s run: unicorn: (pid 23421) 147s; run: log: (pid 23094) 183s 重啟[root@localhost ~]# gitlab-ctl restart ok: run: gitlab-workhorse: (pid 23646) 0s ok: run: logrotate: (pid 23654) 1s ok: run: nginx: (pid 23661) 0s ok: run: postgresql: (pid 23671) 0s ok: run: redis: (pid 23680) 0s ok: run: sidekiq: (pid 23685) 0s ok: run: unicorn: (pid 23690) 1s 查看nginx日誌[root@localhost ~]# gitlab-ctl tail nginx ==> /var/log/gitlab/nginx/current <== ==> /var/log/gitlab/nginx/error.log <== ==> /var/log/gitlab/nginx/gitlab_access.log <== ==> /var/log/gitlab/nginx/gitlab_error.log <== ^[[A^C/opt/gitlab/embedded/bin/omnibus-ctl: Interrupt 查看數據庫日誌[root@localhost ~]# gitlab-ctl tail postgresql 2016-08-20_10:32:51.75539 LOG: received fast shutdown request 2016-08-20_10:32:51.75541 LOG: aborting any active transactions 2016-08-20_10:32:51.75542 LOG: autovacuum launcher shutting down 2016-08-20_10:32:51.75651 FATAL: terminating connection due to administrator command 2016-08-20_10:32:51.75861 FATAL: terminating connection due to administrator command 2016-08-20_10:32:51.76010 LOG: shutting down 2016-08-20_10:32:52.04671 LOG: database system is shut down 2016-08-20_10:32:52.14372 LOG: database system was shut down at 2016-08-20 10:32:52 GMT 2016-08-20_10:32:52.18627 LOG: database system is ready to accept connections 2016-08-20_10:32:52.18628 LOG: autovacuum launcher started gitlab默认安装目录在/opt/gitlab/那麼現在,有一個問題,安裝完成它會以git@localhost:root/master.git形式展示出當然,這肯定不是我們要的格式,修改如下即可vim /etc/gitlab/gitlab.rb external_url 'http://10.10.239.222' 修改完成在進行配置一次:gitlab-ctl reconfigure
2016年08月23日
3,149 阅读
0 评论
0 点赞
2015-11-22
centos6.7 install gitlab7.13.5_zh
<p> 声明:本章内容由本章发布,其中感谢豆豆师兄,和郭师兄的鼎力相助才安装完成,如有看不懂的地方,那就看不懂吧!请在下方留言,或者加群讨论!</p><pre class="brush:bash; toolbar:false;">## 环境`OS : CentOS 6.6 X86_64GitLab Version : 7.13.5_zhWeb Server : NginxDataBase : MySQLAuthor : YxnData : 2015-08-21 12:03:07</pre><p> </p><p> </p><pre class="brush:bash; toolbar:false;">#/etc/init.d/iptables stop# setenforce 0</pre>## 简介翻译于官方文档 Install/CentOS 此篇没有关于SSL、防火墙、SElinux、PgSQL(PostgreSQL)、Apache的安装配置,官方文档中包含SElinx、防火墙、SSL、PgSQL、Apache的配置。由于GitLab为英文版本,所以选择了GitLab 中文版本。可能由于某些地区连接过慢,这里提供了一个国内的镜像版本库GitLab 中文版本以上翻译为个人翻译,如有问题请邮箱联系或者留言。谢谢!<p> </p><p> ### bug提交如果你发现有BUG请提交于 Issue</p><pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">### 配置大纲- - - 此篇安装文档的步骤如下:1. 安装基本的操作系统(CentOS 6.6 x86_64)以及一些依赖的程序包2. Ruby3. System Users4. DataBase(MySQL)5. Redis6. GitLab7. Web Server (Nginx)---------</pre></pre><p> 提示: 安装方式随自己心情,不想用 YUM 就用编译,开心就好。## 1. 安装基本的操作系统</p><p> 在这里操作系统的安装并不做任何演示操作,因为既然能看到这篇文章那么至少你是一个运维人员了,如果你连系统都不会装那就到这就可以结束了。</p><p> 注意: 保证开机自动连接网路,毕竟是放在公司使用的谁也不希望重启一下就连接不到了。1,#### 添加EPEL源从fedoraproject下载GPG key并且安装在系统中</p><p> </p><pre class="brush:bash; toolbar:false;"> wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6</pre><p> </p><p> 查看Key是否安装成功:</p><p> </p><pre class="brush:bash; toolbar:false;"> rpm -qa gpg gpg-pubkey-0608b895-4bd22942</pre> 在系统中安装epel源<p> </p><p> </p><pre class="brush:bash; toolbar:false;">rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm</pre> 提示: 也可以自己配置repo文件,看自己心情。<p> </p><p> #### 添加PUIAS源这段说明不会翻译 - -。</p><p> 下载 PUIAS repo文件</p><p> </p><pre class="brush:bash; toolbar:false;">wget -O /etc/yum.repos.d/PUIAS_6_computational.repo https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/install/centos/PUIAS_6_computational.repo </pre> 接下来下载并安装gpg key<p> </p><p> </p><pre class="brush:bash; toolbar:false;"> wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias</pre> 查看是否安装成功<p> </p><pre class="brush:bash; toolbar:false;">rpm -qa gpggpg-pubkey-41a40948-4ce19266</pre> 查看源是否添加成功<p> </p><p> </p><pre class="brush:bash; toolbar:false;">yum repolistrepo id repo name statusPUIAS_6_computational PUIAS computational Base 6 - x86_64 2,678epel Extra Packages for Enterprise Linux 6 - x86_64 11,772</pre>如果没有看到如上内容,则使用下面的命令来启用它们(需要安装yum-utils包)<pre class="brush:bash; toolbar:false;">yum-config-manager --enable epel --enable PUIAS_6_computational</pre> 2,#### 为GitLab安装一些必须的包<p> yum update # 其实这一步可以不需要的</p><pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">yum -y groupinstall 'Development Tools'yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs</pre></pre> 3,Note: 配置默认的编辑器<p> # 安装vim并且设置为默认的编辑器</p><pre class="brush:bash; toolbar:false;">yum -y install vim-enhancedupdate-alternatives --set editor /usr/bin/vim.basicln -s /usr/bin/vim /usr/bin/editor</pre><pre class="brush:bash; toolbar:false;"># reStructuredText markup语法支持,需要安装依赖包:yum install -y python-docutils</pre><p> 4,#### 可选:使用源码安装git确认Git的版本>=1.7.10,如果低于此版本需要进行安装</p><p> git --version移除git</p><pre class="brush:bash; toolbar:false;">yum -y remove git</pre>安装git编译所需要的包<pre class="brush:bash; toolbar:false;">yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel</pre>下载并解压它<pre class="brush:bash; toolbar:false;">mkdir /tmp/git && cd /tmp/gitcurl --progress https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.gz | tar xzcd git-2.1.3/./configuremakemake prefix=/usr/local install</pre><p> </p><p> 确认你的git路径,需要在后面编辑config/gitlab.yml时使用,</p><p> 5,## 2.Ruby如果系统中Ruby的版本是2.0以前的那么请移除,GitLab只支持Ruby 2.0+版本</p><p> </p><pre class="brush:bash; toolbar:false;">yum remove ruby</pre><p> </p><p> ### 下载并编译</p><p> </p><pre class="brush:bash; toolbar:false;">mkdir /tmp/ruby && cd /tmp/rubycurl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xzcd ruby-2.1.2./configure --disable-install-rdocmakemake prefix=/usr/local install</pre><p> </p><p> <span style="background-color:#E56600;">### 安装Bundler Gem</span><span style="background-color:#E56600;">由于http://rubygems.org已被墙,这里替换源为http://ruby.taobao.org</span><span style="background-color:#E56600;"> </span><span style="background-color:#E56600;"> # 添加淘宝源并且移除官方源</span> </p><pre class="brush:bash; toolbar:false;">sudo git gem sources -a http://ruby.taobao.orggem sources -r https://rubygems.org/</pre> # 安装Bundler<pre class="brush:bash; toolbar:false;">gem install bundler -v'1.5.2' --no-doc</pre><p> </p><p> 检查ruby版本</p><p> </p><pre class="brush:bash; toolbar:false;">ruby --versionruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]</pre> 6,## 3. System Users为GitLab创建用户 <pre class="brush:bash; toolbar:false;">adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git</pre><p> </p><p> 编辑sudoers文件,将ruby的程序路径添加到PATH中,使git用户作为root来使用gem命令</p><p> </p><pre class="brush:bash; toolbar:false;"> visudo# 搜索如下行Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin# 追加/usr/local/binDefaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin</pre>保存并退出<p> </p><p> 7,## 4. DataBase这里使用的是MariaDB,我用的是yum安装的自己配置的yum源(由于当时做实验的时候已经凌晨1点了为了赶快做完去睡觉)还是那句:用什么包随心情,开心就好### 配置yum源</p><pre class="brush:bash; toolbar:false;">vim /etc/yum.repos.d/mariadb.repo# 增加如下内容:[mariadb]name=mariadbbaseurl=http://mirrors.aliyun.com/mariadb/mariadb-5.5.45/yum/centos6-amd64/gpgcheck=0</pre><pre class="brush:bash; toolbar:false;">### 安装MariaDByum install MariaDB MariaDB-devel</pre> 也可以使用编译安装,可以看本博客中Mariadb#### 连接数据库并创建用户<pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">mysql -u root 创建数据库CREATE USER 'git1'@'10.215.50.3' IDENTIFIED BY 'gitpassword'; 确定你的innode引擎支持长索引SET storage_engine=INNODB;创建数据库CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;</pre></pre><pre class="brush:bash; toolbar:false;">尝试使用新用户连接gitlab数据库sudo -u git -H mysql -u git -pgitpassword -D gitlabhq_production</pre><p> 8,## 5. Redis</p><pre class="brush:bash; toolbar:false;">开机启动redischkconfig redis on</pre><pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">配置Redis使用socketscp /etc/redis.conf /etc/redis.conf.orig 关闭Redis 监听于TCPsed 's/^port ./port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf 在CentOS上启用Redis socketecho 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.confecho -e 'unixsocketperm 0770' | sudo tee -a /etc/redis.conf 设置socket目录属主(组)为redischown redis:redis /var/run/redischmod 755 /var/run/redis 将git用户添加至redis组usermod -aG redis git 启动redis服务service redis start</pre></pre><p> 9, 6. GitLab</p><p> </p><pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">克隆源码cd /home/git/sudo -u git -H git clone http://git.oschina.net/Yxnt/gitlab配置gitlab进入Gitlab安装目录cd /home/git/gitlab复制gitlab的模板文-件sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml编辑gitlab配置文件sudo -u git -H editor config/gitlab.yml 访问地址host:10.1.13.5port:80https: false # 关闭https</pre></pre> ====================我是分割线=================================<pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">创建satellites目录sudo -u git -H mkdir /home/git/gitlab-satelliteschmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites确认gitlab可以写入tmp/pids、tmp/sockets以及public/uploads/目录chmod -R u+rwX tmp/pids/chmod -R u+rwX tmp/sockets/chmod -R u+rwX public/uploads复制Unicorn配置文件sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb复制Rack attack配置文件sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb配置Git 全局设置sudo -u git -H git config --global user.name "GitLab"sudo -u git -H git config --global user.email "example@example.com"sudo -u git -H git config --global core.autocrlf input配置Redis连接设置sudo -u git -H cp config/resque.yml.example config/resque.ymlsudo -u git -H editor config/resque.yml # 更改配置development: unix:/var/run/redis/redis.sock### 配置Gitlab 数据库设置MySQL Onlysudo -u git cp config/database.yml.mysql config/database.yml确定database.yml文件只为git用户可读sudo -u git -H chmod o-rwx config/database.yml</pre></pre> 10,### 安装Gems<p> </p><p> </p><pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">cd /home/git/gitlabgem sources --add https://rubygems.org --remove https://ruby.taobao.orgbundle config mirror.https://rubygems.org https://ruby.taobao.orggem install rails -V sudo -u git -H bundle install --deployment --without development test postgres awssudo -u git -H bundle install --deployment --without development test postgres aws安装gitlab-shellsudo -u git -H bundle exec rake gitlab:shell:install[v2.6.3] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production配置gitlab-shellsudo -u git -H editor /home/git/gitlab-shell/config.ymlgitlab_url: http://10.1.13.5</pre></pre><p> 11,### 初始化数据并且激活高级特性</p><pre class="brush:bash; toolbar:false;">这里会提示输入yes/no,输入yes即可sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production 设置管理员密码,其中newpassword替换成你的密码sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=gitpassword</pre><pre class="brush:bash; toolbar:false;">安装启动脚本wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn</pre><pre class="brush:bash; toolbar:false;">chmod +x /etc/init.d/gitlabchkconfig --add gitlab</pre><p> </p><pre class="brush:bash; toolbar:false;">开机启动 Gitlabchkconfig gitlab on设置日志滚动cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab检查应用程序状态sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production[git@gitlab gitlab]$ bundle exec rake gitlab:env:info RAILS_ENV=productionSystem informationSystem: CentOS 6.7Current User: gitUsing RVM: noRuby Version: 2.1.2p95Gem Version: 2.2.2Bundler Version:1.5.2Rake Version: 10.4.2Sidekiq Version:3.3.0GitLab informationVersion: 7.13.5Revision: 851306aDirectory: /home/git/gitlabDB Adapter: mysql2URL: http://10.215.50.3HTTP Clone URL: http://10.215.50.3/some-project.gitSSH Clone URL: git@10.215.50.3:some-project.gitUsing LDAP: noUsing Omniauth: noGitLab ShellVersion: 2.6.3Repositories: /home/git/repositories/Hooks: /home/git/gitlab-shell/hooks/Git: /usr/bin/git[git@gitlab gitlab]$</pre><p> </p><pre class="brush:bash; toolbar:false;">启动gitlabservice gitlab start</pre><p> </p><p> 7.Web Server</p><p> ### 安装nginx</p><p> 我这里是编译的,细节不在批示,可在本站搜索nginx编译安装</p><p> </p><pre class="brush:bash; toolbar:false;">./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi</pre><p> </p><p> </p><p> 如果你用的是install,则可以使用一下范式</p><pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">配置nginxwget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlabwget -O /etc/nginx/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab修改代理服务器[root@gitlab nginx]# sed -ie "38s/./server localhost:8080;/g" /etc/nginx/gitlab.conf[root@gitlab nginx]# sed -ie "s/YOUR_SERVER_FQDN/hostname/g" /etc/nginx/gitlab.conf[root@gitlab nginx]# sed -ie "52d" /etc/nginx/gitlab.conf[root@gitlab nginx]# usermod -a -G git nginx[root@gitlab nginx]# chmod g+rx /home/git/[root@gitlab nginx]# service nginx startupstream gitlab {server localhost:8080;} 修改server_nameserver_name www.baidu.com;</pre></pre><p> 如果你是编译的请复制一下内容到nginx.conf,<span style="background-color:#E53333;">请自行修改配置文件中的编译文件路径</span> </p><p> </p><pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">user root git;worker_processes 2;pid /var/run/nginx/nginx.pid;events {worker_connections 1024;}http {include /etc/nginx/mime.types;default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';#GITLAB# Maintainer: @randx# App Version: 5.0upstream gitlab {server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;}server {listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good ideaserver_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com;server_tokens off; # don't show the version number, a security best practiceroot /home/git/gitlab/public;# Set value of client_max_body_size to at least the value of git.max_size in gitlab.ymlclient_max_body_size 5m;# individual nginx logs for this gitlab vhostaccess_log /var/log/nginx/gitlab_access.log;error_log /var/log/nginx/gitlab_error.log;location / {# serve static files from defined root folder;.# @gitlab is a named location for the upstream fallback, see belowtry_files $uri $uri/index.html $uri.html @gitlab;}# if a file, which is not found in the root folder is requested,# then the proxy pass the request to the upsteam (gitlab unicorn)location @gitlab {proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694proxy_redirect off;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://gitlab;}}}</pre></pre><pre class="brush:bash; toolbar:false;"># 添加nginx到git组usermod -a -G git nginxchmod g+rx /home/git/ # 启动nginxservice nginx start</pre> <pre class="brush:bash; toolbar:false;">##附录(发送邮件配置),未经测试,请斟酌使用</pre><pre class="brush:bash; toolbar:false;"><pre class="brush:as3; toolbar:false;">### 复制gitlab自带的模板cd /home/git/gitlabsudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb### 替换邮箱sudo -u git -H vim config/initializers/smtp_settings.rb if Rails.env.production?Gitlab::Application.config.action_mailer.delivery_method = :smtpActionMailer::Base.smtp_settings = {address: "smtp.163.com", ## 发信地址port: 25, ## 发信端口user_name: "wpgitlab", ## 用户名password: "123456", ## 密码domain: "163.com", ## 域authentication: :plain, enable_starttls_auto: true}end### 修改gitlab.ymlcd /home/git/gitlabsudo -u git -H vim config/gitlab.yml email_from: wpgit@163.com 这里的邮箱配置和上面的一样</pre></pre><p> ## 结束语yum安装可能是有点影响智商了,如果你被领导用刀夹着脖子的话那就还是用吧。</p><p> 邮件内容未测试,请自行测试</p><p> 由于文章的代码高亮问题,可下载此文章链接:gitlab文档下载 </p>
2015年11月22日
3,461 阅读
0 评论
0 点赞