GitLab使用

2016-12-31 10:37:36来源:oschina作者:yangzhiwen人点击

第七城市
官网:https://github.com/gitlabhq/gitlabhq/blob/6-7-stable/doc/install/installation.md#important-notes
系统,ubuntu 14.01/64
概述:
gitlab安装包括安装下列组件
1、Packages / Dependencies
2、Ruby
3、System Users
4、GitLab shell
5、Database
6、GitLab
7、Nginx
首先修改ubuntu 更新源URL
将 /etc/apt/sources.list 文件的 所有URL 改为:http://old-releases.ubuntu.com/ubuntu/
1、依赖包/更新下。
# run as root!
apt-get update -y
apt-get upgrade -y
apt-get install sudo -y
2、安装vim
sudo apt-get install -y vim
sudo update-alternatives --set editor /usr/bin/vim.basic
3、安装所需要的包:
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate
4、确保你已经正确安装git
# Install Git
sudo apt-get install -y git-core
# Make sure Git is version 1.7.10 or higher, for example 1.7.12 or 1.8.4
git --version
5、删除它、编译源代码。
# Remove packaged Git
sudo apt-get remove git-core
# Install dependencies
sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
# Download and compile from source
cd /tmp
curl --progress https://git-core.googlecode.com/files/git-1.8.5.2.tar.gz | tar xz
cd git-1.8.5.2/
make prefix=/usr/local all
# Install into /usr/local/bin
sudo make prefix=/usr/local install
# When editing config/gitlab.yml (Step 6), change the git bin_path to /usr/local/bin/git
6、为了接收邮件通知,请确保安装邮件服务器。
sudo apt-get install -y postfix
7、 安装 ruby
sudo apt-get remove ruby1.8
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
cd ruby-2.0.0-p353
./configure --disable-install-rdoc
make
sudo make install
sudo gem install bundler --no-ri --no-rdoc
这步可能报错,使用淘宝源
8、创建git用户
sudo adduser --disabled-login --gecos 'GitLab' git
9、gitlab Shell是一个SSH访问和存储管理软件的开发,专门为gitlab提供。
# Go to home directory
cd /home/git
# Clone gitlab shell
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.9.1
cd gitlab-shell
sudo -u git -H cp config.yml.example config.yml
# Edit config and replace gitlab_url
# with something like 'http://domain.com/'
sudo -u git -H editor config.yml
# Do setup
sudo -u git -H ./bin/install
10、 数据库安装,官网建议用的数据库是 PostgreSQL 我用的是mysql数据库
mysql数据库安装
# Install the database packages
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
# Pick a database root password (can be anything), type it and press enter
# Retype the database root password and press enter
# Secure your installation.
sudo mysql_secure_installation
# Login to MySQL
mysql -u root -p
# Type the database root password
# Create a user for GitLab
# do not type the 'mysql>', this is part of the prompt
# change $password in the command below to a real password you pick
mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
# Create the GitLab production database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Grant the GitLab user necessary permissions on the table.
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
# Quit the database session
mysql> /q
# Try connecting to the new database with the new user
sudo -u git -H mysql -u git -p -D gitlabhq_production
# Type the password you replaced $password with earlier
# You should now see a 'mysql>' prompt
# Quit the database session
mysql> /q
# You are done installing the database and can go back to the rest of the installation.
启动数据库 ,看下是否启动
11、进入githome目录
cd /home/git
克隆GitLab 库
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-7-stable gitlab 期间有些慢
cd /home/git/gitlab
配置
cd /home/git/gitlab
# Copy the example GitLab config
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# Make sure to change "localhost" to the fully-qualified domain name of your
# host serving GitLab where necessary
#
# If you installed Git from source, change the git bin_path to /usr/local/bin/git
sudo -u git -H editor config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwXlog/
sudo chmod -R u+rwXtmp/
# Create directory for satellites
sudo -u git -H mkdir /home/git/gitlab-satellites
# Create directories for sockets/pids and make sure GitLab can write to them
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwXtmp/pids/
sudo chmod -R u+rwXtmp/sockets/
# Create public/uploads directory otherwise backup will fail
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwXpublic/uploads
# Copy the example Unicorn config
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
# Enable cluster mode if you expect to have a high load instance
# Ex. change amount of workers to 3 for 2GB RAM server
sudo -u git -H editor config/unicorn.rb
# Copy the example Rack attack config
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in gitlab.yml
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input
配置GitLabDB 进行设置
# Mysql
sudo -u git cp config/database.yml.mysql config/database.yml
# Make config/database.yml readable to git only
sudo -u git -H chmod o-rwx config/database.yml
12、安装Gems
cd /home/git/gitlab
# Or if you use MySQL (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws
成功后,最下端会显示 登录gitlab的账号和密码如下
Administrator account created:
login.............admin@local.host
password..........5iveL!fe
13、初始化数据库,
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database tables.
# When done you see 'Administrator account created:'
13、安装脚本
启动脚本
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
14、gitlab开机启动:
sudo update-rc.d gitlab defaults 21
建立logrotate
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检查应用程序的状态
检查gitlab及其环境的配置是正确的:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
开始你的gitlab实例
启动 gitlab
sudo service gitlab start
# or
sudo /etc/init.d/gitlab restart
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production15、nginx安装使用部署
sudo apt-get install -y nginx
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
# Change YOUR_SERVER_FQDN to the fully-qualified
# domain name of your host serving GitLab.
sudo editor /etc/nginx/sites-available/gitlab
启动nginx
sudo service nginx restart
完成
确保你没有错过任何运行更彻底的检查
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
如果所有的项目都是绿色的,那么恭喜你成功安装gitlab!
16、更改gitlab端口
默认web端口为80:,
为了便于开放到外部访问,肯定需要把端口改为其他的,比如3000
root@ubuntu:/home/git/gitlab# vim /home/git/gitlab-shell/config.yml
更改第四行URLgitlab_url: "http://192.168.83.113:3000/"
root@ubuntu:/home/git/gitlab# vim /home/git/gitlab/config/gitlab.yml
更改 host、port 为:
host: 192.168.83.113
port: 3000
./gitlab 配置文件的listen 192.168.1.80:99 的端口设置为一致 .
18、初始登录
root@ubuntu:/home/git/gitlab# vim /etc/nginx/sites-available/default
更改端口
listen 3000 default_server;
listen [::]:3000 default_server ipv6only=on;
root@ubuntu:/home/git/gitlab# vim /etc/nginx/sites-available/gitlab
listen 192.168.83.113:3000 default_server;
检查端口被监听起来没有
root@ubuntu:/home/git/gitlab# netstat -ano |grep 3000
tcp 00 0.0.0.0:3000 0.0.0.0:* LISTENoff (0.00/0/0)
tcp600 :::3000 :::*LISTENoff (0.00/0/0)
root@ubuntu:/home/git/gitlab# netstat -ano |grep 80
tcp 00 127.0.0.1:8080 0.0.0.0:* LISTENoff (0.00/0/0)
unix3[ ]STREAM CONNECTED 148056
unix3[ ]STREAM CONNECTED 148083 /var/run/mysqld/mysqld.sock
unix3[ ]STREAM CONNECTED 148055
unix3[ ]STREAM CONNECTED 148052
unix3[ ]STREAM CONNECTED 148058
unix3[ ]STREAM CONNECTED 148053
unix3[ ]STREAM CONNECTED 148059
unix3[ ]STREAM CONNECTED 148068 /var/run/mysqld/mysqld.sock
unix3[ ]STREAM CONNECTED 10580
unix3[ ]STREAM CONNECTED 148067
unix3[ ]STREAM CONNECTED 148054
unix3[ ]STREAM CONNECTED 148082
unix3[ ]STREAM CONNECTED 148057
然后浏览器打开访问 http://192.168.83.113:3000/
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台