设为首页 收藏本站
查看: 1771|回复: 0

[经验分享] GitLab详细部署

[复制链接]

尚未签到

发表于 2018-9-19 11:34:02 | 显示全部楼层 |阅读模式
  最近由于开发的需求,需要在公司部署一个git的服务器,在刚开始选择的时候,我打算使用gitolite来管理git,后来发现gitlab这个系统更加方便,它既支持ssh方式,又支持http方式,用户能够通过命令行甚至是web来提交自己的代码,非常的实用。
  gitlab是一个基于ruby的开源项目,能够实现git仓库的功能,能够在网页上直接浏览自己的代码,下面主要介绍一下部署的过程,主要分为如下几个大步骤:
1、提供一些必须包,提供epel,关闭防火墙和selinux等操作;  
2、gitlab依赖的python功能比较多,需要升级python到2.7.X;
  
3、安装redis的内存数据库;
  
4、安装MySQL的关系型数据库;
  
5、为gitlab提供ruby的环境支持;
  
6、提供gitlab-shell来管理git仓库;
  
7、安装gitlab系统;
  
8、安装nginx的web服务,做反向代理。
  1、提供epel源,安装相应包
[root@gitlab ~]# rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm  
[root@gitlab ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  下面提示你安装的包,一定要装,要不然,你会在部署过程中折返回来装的
[root@gitlab ~]# yum install -y git gcc-c++ libyaml libicu-devel cmake nodejs  关闭防火墙和selinux,这对你的实验非常重要,要不然,排了半天错,原来是它搞的鬼
[root@gitlab ~]# iptables -F  
[root@gitlab ~]# setenforce 0
  2、升级python到2.7.X
  查看当前系统中python版本,CentOS6.5的默认是2.6.6
[root@gitlab ~]# python -V  
Python 2.6.6
  到python.org上去下载源代码,进行如下编译安装
[root@gitlab ~]# tar Jxf Python-2.7.6.tar.xz  
[root@gitlab ~]# cd Python-2.7.6
  
[root@gitlab ~]# ./configure --prefix=/usr/local/python
  
[root@gitlab ~]# make && make install
  备份python2.6的版本,并把新的2.7指向到系统中去
[root@gitlab ~]# mv /usr/bin/python /usr/bin/python2.6.6  
[root@gitlab ~]# ln -sv /usr/local/python/bin/python /usr/bin/python
  再次查看当前系统的python版本
[root@gitlab ~]# python -V  
Python 2.7.6
  为了防止yum安装软件出错,将yum的依赖的python指回2.6.6
[root@gitlab ~]# vim /usr/bin/yum  
#!/usr/bin/python2.6.6
  3、安装redis数据库
  首先去redis.io上去下载redis的稳定版源码,进行编译安装
[root@gitlab ~]# tar zxvf redis-3.0.3.tar.gz  
[root@gitlab ~]# cd redis-3.0.3
  
[root@gitlab ~]# make
  
[root@gitlab ~]# make install
  执行redis的安装脚本
[root@gitlab redis-3.0.3]# ./utils/install_server.sh  
Welcome to the redis service installer
  
This script will help you easily set up a running redis server
  

  
Please select the redis port for this instance: [6379]
  
Selecting default: 6379
  
Please select the redis config file name [/etc/redis/6379.conf] /etc/redis.conf
  
Please select the redis log file name [/var/log/redis_6379.log] /var/log/redis.log
  
Please select the data directory for this instance [/var/lib/redis/6379] /var/lib/redis.pid
  
Please select the redis executable path [/usr/local/bin/redis-server]
  
Selected config:
  
Port           : 6379
  
Config file    : /etc/redis.conf
  
Log file       : /var/log/redis.log
  
Data dir       : /var/lib/redis.pid
  
Executable     : /usr/local/bin/redis-server
  
Cli Executable : /usr/local/bin/redis-cli
  
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
  
Copied /tmp/6379.conf => /etc/init.d/redis_6379
  
Installing service...
  
Successfully added to chkconfig!
  
Successfully added to runlevels 345!
  
Starting Redis server...
  
Installation successful!
  更改redis的启动脚本,并启动服务
[root@gitlab ~]# mv /etc/init.d/redis_6379 /etc/init.d/redis  
[root@gitlab ~]# service redis start
  4、安装MySQL数据库
  MySQL的编译安装文档很多,这里为了方便,我采用的是yum安装过程
[root@gitlab ~]# yum install mysql mysql-server mysql-devel -y  为了保证数据的安全,应该数据和二进制日志会放在单独的分区中
[root@gitlab ~]# vim /etc/my.cnf  
datadir = /data/mysql
  对MySQL进行初始化操作
[root@gitlab ~]# mysql_install_db --user=mysql --datadir=/data/mysql/  启动MySQL数据库
[root@gitlab ~]# service mysqld start  设置root的密码和相关登录信息
[root@gitlab ~]# mysql_secure_installation  

  
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
  
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
  

  

  
In order to log into MySQL to secure it, we'll need the current
  
password for the root user.  If you've just installed MySQL, and
  
you haven't set the root password yet, the password will be blank,
  
so you should just press enter here.
  

  
Enter current password for root (enter for none):
  
OK, successfully used password, moving on...
  

  
Setting the root password ensures that nobody can log into the MySQL
  
root user without the proper authorisation.
  

  
Set root password? [Y/n] y
  
New password:
  
Re-enter new password:
  
Password updated successfully!
  
Reloading privilege tables..
  
... Success!
  

  

  
By default, a MySQL installation has an anonymous user, allowing anyone
  
to log into MySQL without having to have a user account created for
  
them.  This is intended only for testing, and to make the installation
  
go a bit smoother.  You should remove them before moving into a
  
production environment.
  

  
Remove anonymous users? [Y/n] y
  
... Success!
  

  
Normally, root should only be allowed to connect from 'localhost'.  This
  
ensures that someone cannot guess at the root password from the network.
  

  
Disallow root login remotely? [Y/n] y
  
... Success!
  

  
By default, MySQL comes with a database named 'test' that anyone can
  
access.  This is also intended only for testing, and should be removed
  
before moving into a production environment.
  

  
Remove test database and access to it? [Y/n] y
  
- Dropping test database...
  
... Success!
  
- Removing privileges on test database...
  
... Success!
  

  
Reloading the privilege tables will ensure that all changes made so far
  
will take effect immediately.
  

  
Reload privilege tables now? [Y/n] y
  
... Success!
  

  
Cleaning up...
  

  

  

  
All done!  If you've completed all of the above steps, your MySQL
  
installation should now be secure.
  

  
Thanks for using MySQL!
  上面对于数据库的部署已经OK了,下面就要为gitlab创建一个库用来存储数据
[root@gitlab ~]# mysql -uroot -pgitlab  
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
  
Query OK, 0 rows affected (0.00 sec)
  

  
mysql> CREATE DATABASE IF NOT EXISTS `gitlab` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  
Query OK, 1 row affected (0.01 sec)
  

  
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlab`.* TO 'gitlab'@'localhost';
  
Query OK, 0 rows affected (0.00 sec)
  

  
mysql> FLUSH PRIVILEGES;
  
Query OK, 0 rows affected (0.00 sec)
  5、提供ruby环境
  下载ruby的源代码包
[root@gitlab ~]# curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz  
[root@gitlab ~]# ./configure --prefix=/usr/local/
  
[root@gitlab ~]# make && make install
  由于是在国内,安装gem的相关包会特别的慢,建议换成淘宝的,此处为淘宝点赞
[root@gitlab ~]# gem sources --remove https://rubygems.org/  
[root@gitlab ~]# gem sources -a http://ruby.taobao.org/
  安装bundler,它是帮助管理ruby下的所有依赖的包,相当于yum的功能
[root@gitlab ~]# gem install bundler  添加一个git用户,作为git服务的授权用户
[root@gitlab ~]# useradd git  6、安装gitlab-shell来管理git仓库
[root@gitlab ~]# su - git  
[git@gitlab ~]$ git clone https://github.com/gitlabhq/gitlab-shell.git
  将分支切换到2.6.3,有些文档说1.4.0,我建议切到2.6.3,因为版本低了,不支持用户ssh形式的提交代码到git服务中去
[git@gitlab ~]$ cd gitlab-shell/  
[git@gitlab ~]$ git checkout v2.6.3
  提供配置文件,修改gitlab的URL地址
[git@gitlab ~]$ cp config.yml.example config.yml  
[git@gitlab ~]$ vim config.yml
  
gitlab_url: "http://192.168.190.138/"
  进行安装操作
[git@gitlab~ gitlab-shell]$ ./bin/install  
mkdir -p /home/git/repositories: true
  
mkdir -p /home/git/.ssh: true
  
chmod 700 /home/git/.ssh: true
  
touch /home/git/.ssh/authorized_keys: true
  
chmod 600 /home/git/.ssh/authorized_keys: true
  
chmod -R ug+rwX,o-rwx /home/git/repositories: true
  
find /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true
  7、安装gitlab系统
  克隆gitlab的代码到git家目录
[git@gitlab ~]$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab  
[git@gitlab ~]$ cd gitlab
  
[git@gitlab ~]$ git checkout 7-10-stable
  配置项目,提供配置文件
[git@gitlab ~]$ cp config/gitlab.yml.example config/gitlab.yml  将localhost改为本机ip或者是域名
[git@gitlab ~]$ sed -i 's/localhost/192.168.190.138/g' config/gitlab.yml  修改目录的相关权限
[git@gitlab ~]$ chown -R git log/  
[git@gitlab ~]$ chown -R git tmp/
  
[git@gitlab ~]$ chmod -R u+rwx log/
  
[git@gitlab ~]$ chmod -R u+rwx tmp/
[git@gitlab ~]$ mkdir /home/git/gitlab-satellites  #可以视为临时目录,通过web ui的提交请求文件以及检出版本库都会存放在这个位置
  提供unicorn的配置
[git@gitlab ~]$ cp config/unicorn.rb.example config/unicorn.rb  修改unicorn的配置,指明监听的端口和超时时间
[git@gitlab ~]$ vim config/unicorn.rb  
listen "192.168.190.138:8080", :tcp_nopush => true
  
timeout 300
  配置git的用户和邮件
[git@gitlab ~]$ git config --global user.name "GitLab"  
[git@gitlab ~]$ git config --global user.email "gitlab@test.com"
  
[git@gitlab ~]$ git config --global core.autocrlf input
  配置数据库,使gitlab将数据存入到MySQL数据库中
[git@gitlab ~]$ cp config/database.yml.mysql config/database.yml  
[git@gitlab ~]$ vim config/database.yml
  
production:
  
  adapter: mysql2
  
  encoding: utf8
  
  collation: utf8_general_ci
  
  reconnect: false
  
  database: gitlab
  
  pool: 10
  
  username: gitlab
  
  password: "gitlab"
  修改其权限,保证其他用户不能访问
[git@gitlab ~]$ chmod o-rwx config/database.yml  安装gem的相关包,进行gitlab的初始化操作
  切回root操作下面步骤
[root@gitlab ~]# gem install charlock_holmes --version '0.6.9.4'  切回git用户
[root@gitlab ~]# su - git  
[git@gitlab ~]$ cd gitlab
  修改Gemfile文件,将gem源改成淘宝的源
[git@gitlab ~]$ vim Gemfile  
source "http://ruby.taobao.org"
  安装一些依赖包
[git@gitlab ~]$ bundle install --deployment --without development test postgres puma aws  
...
  
Remember to run generator to generate sample file and include mousetrap-rails with Rails Asset Pipeline
  

  
    $ rails generate mousetrap:install
  

  
Post-install message from rdoc:
  
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
  

  
= 1.9.2 : nothing to do! Yay!
  当你看到上面这段的时候就成功了
  初始化gitlab
[git@gitlab ~]$ bundle exec rake gitlab:setup RAILS_ENV=production  
...
  
This will create the necessary database tables and seed the database.
  
You will lose any previous data stored in the database.
  
Do you want to continue (yes/no)? yes
  

  
Administrator account created:
  

  
login.........root
  
password......5iveL!fe
  只要显示上面的管理员账号被创建,就ok了
  为gitlab提供启动脚本
  切回root用户
[root@gitlab ~]# wget -O /etc/init.d/gitlab https://raw.githubusercontent.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn --no-check-certificate  
[root@gitlab ~]# chmod +x /etc/init.d/gitlab
  
[root@gitlab ~]# chkconfig --add gitlab
  启动gitlab服务
[root@gitlab ~]# service gitlab start  8、安装nginx做反向代理
  配置nginx官方源
[root@gitlab ~]# vim /etc/yum.repos.d/nginx.repo  
[nginx]
  
name=nginx repo
  
baseurl=http://nginx.org/packages/centos/$releasever/$basearch
  
gpgcheck=0
  
enabled=1
  安装nginx包
[root@gitlab ~]# yum install nginx -y  为gitlab配置反向代理的虚拟主机
[root@gitlab ~]# vim /etc/nginx/conf.d/gitlab.conf  
server {
  
    listen 80;
  
    server_name 192.168.190.138;
  

  
    client_max_body_size 512M;
  

  
    access_log  /var/log/nginx/gitlab_access.log;
  
    error_log   /var/log/nginx/gitlab_error.log;
  

  
    location / {
  
          proxy_pass http://192.168.190.138:8080;
  
    }
  
}
  启动nginx服务
[root@gitlab ~]# service nginx start  为提供服务的可靠性,建议将这些服务都设为开机自启动
  在浏览器中访问我们的IP地址
DSC0000.jpg

  本篇博客的主要目的是为了做个笔记,下次部署时,能更加方便快速一些,如果,大家有需要,也可以借鉴,博客中的错误之处,请帮忙之处,感谢!



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-594213-1-1.html 上篇帖子: Centos7安装gitlab 下篇帖子: 在centos里安装gitlab
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表