在已安裝Apache和MySQL的Ubuntu上安裝gitlab
在已安裝Apache和MySQL的Ubuntu上安裝gitlab 摘要 在已安裝Apache和MySQL的Ubuntu上安裝gitlab
一 、 首先更新系統和軟件包
1 . 更新軟件包
# run as root! apt-get update -y apt-get upgrade -y apt-get install sudo -y
2 . 配置編輯器
# Install vim and set as default editor sudo apt-get install -y vim sudo update-alternatives --set editor /usr/bin/vim.basic
3 . 安裝ruby
curl -L --progress https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.gz | tar xz cd ruby-2.2.3 ./configure --prefix=/usr --disable-install-rdoc make sudo apt-get autoremove ruby sudo make install
4 . 安裝Bundler Gem:
sudo gem install bundler --no-ri --no-rdoc
如果出現:
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
sudo apt-get install zlib1g-devcd ext/zlib
ruby ./extconf.rb
make
make install
二 、 為gitlab創建一個git用戶
sudo adduser --disabled-login --gecos 'GitLab' git
三 、 配置數據庫
官方指南用的是PostgreSQL,不過官方也有MySQL的說明:
http://doc.gitlab.com/ce/install/database_mysql.html
# 查看版本,即檢查是否安裝 mysql --version # 登陸 MySQL , mysql -u root -p # 如果有密碼會提示輸入密碼 # 下面是已經進入mysql命令模式 mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY '$password'; # $password 改成創建用戶的密碼 # CREATE USER 'git'@'localhost' IDENTIFIED BY 'git'; # Ensure you can use the InnoDB engine which is necessary to support long indexes # If this fails, check your MySQL config files (e.g. `/etc/mysql/*.cnf`, `/etc/mysql/conf.d/*`) for the setting "innodb = off" mysql> SET storage_engine=INNODB; # 設置索引模式 # 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 database mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES ON `gitlabhq_production`.* TO 'git'@'localhost'; # 退出mysql模式 mysql> \q
確認數據庫用戶是否創建成功,即再次以新用戶登陸進mysql模式
# Try connecting to the new database with the new user sudo -u git -H mysql -u git -p -D gitlabhq_production # 會提示輸入密碼,輸入剛才你替換的 $password # 退出mysql模式 mysql> \q
四 、 安裝redis
sudo apt-get install redis-server # Configure redis to use sockets sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig # Disable Redis listening on TCP by setting 'port' to 0 sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf # Enable Redis socket for default Debian / Ubuntu path echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf # Grant permission to the socket to all members of the redis group echo 'unixsocketperm 770' | sudo tee -a /etc/redis/redis.conf # Create the directory which contains the socket mkdir /var/run/redis chown redis:redis /var/run/redis chmod 755 /var/run/redis # 這里是直接摘錄官方的步驟,下面的這步可跳過 # Persist the directory which contains the socket, if applicable if [ -d /etc/tmpfiles.d ]; then echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf fi # Activate the changes to redis.conf sudo service redis-server restart # Add git to the redis group sudo usermod -aG redis git
五 、 安裝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 2.0.0 git --version
按照上面的提示,如果版本號小于1.7.10,請按下面的步驟更新(下面的2.4.3的源,安裝后是:git version 1.9.1)
# 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 -L --progress https://www.kernel.org/pub/software/scm/git/git-2.4.3.tar.gz | tar xz cd git-2.4.3/ ./configure make prefix=/usr/local all # Install into /usr/local/bin sudo make prefix=/usr/local install # When editing config/gitlab.yml (Step 5), change the git -> bin_path to /usr/local/bin/git
六 、 gitlab源碼(這里選用的是,大神漢化版,文末進行介紹)
1 、 clone
# We'll install GitLab into home directory of the user "git" //默認安裝到/home/git 即git的用戶目錄 cd /home/git # Clone GitLab repository //clonegit上的源碼,這里試用了漢化版,下面的注釋是原版 #sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-1-stable gitlab sudo -u git -H git clone https://gitlab.com/larryli/gitlab.git # 最后一步不要急,據說網絡的原因導致很卡,看運氣吧
2 、 配置它gitlab:
# Go to GitLab installation folder cd /home/git/gitlab # Copy the example GitLab config sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml # Update GitLab config file, follow the directions at top of file # 這一步主要是配置郵箱和一些其他的東西,自己看需要把 sudo -u git -H editor config/gitlab.yml # Copy the example secrets file sudo -u git -H cp config/secrets.yml.example config/secrets.yml sudo -u git -H chmod 0600 config/secrets.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+rwX,go-w log/ sudo chmod -R u+rwX tmp/ # Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories sudo chmod -R u+rwX tmp/pids/ sudo chmod -R u+rwX tmp/sockets/ # Make sure GitLab can write to the public/uploads/ directory sudo chmod -R u+rwX public/uploads # Change the permissions of the directory where CI build traces are stored sudo chmod -R u+rwX builds/ # Copy the example Unicorn config sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb # Find number of cores nproc # Enable cluster mode if you expect to have a high load instance # Set the number of workers to at least the number of cores # 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, used when editing via web editor sudo -u git -H git config --global core.autocrlf input # Configure Redis connection settings sudo -u git -H cp config/resque.yml.example config/resque.yml # Change the Redis socket path if you are not using the default Debian / Ubuntu configuration sudo -u git -H editor config/resque.yml
上面主要是拷貝和編輯一些配置文件,基本不用改,別漏掉就行
3 、 下面配置數據庫(請注意數據庫配置的模板文件):
# PostgreSQL 請運行下面的: sudo -u git cp config/database.yml.postgresql config/database.yml # MySQL 請運行下面的: sudo -u git cp config/database.yml.mysql config/database.yml # 一定要注意,上面的兩個,只能執行一個 # 下面配置數據庫 將'secure password' 替換成你設置的 $password sudo -u git -H editor config/database.yml # PostgreSQL and MySQL: # Make config/database.yml readable to git only sudo -u git -H chmod o-rwx config/database.yml
4 、 安裝 gems (為了,方便國內的網速,可在此步前,配置淘寶的ruby服務器 https://ruby.taobao.org/ 詳情進入查看)
# For PostgreSQL (note, the option says "without ... mysql") sudo -u git -H bundle install --deployment --without development test mysql aws kerberos # Or if you use MySQL (note, the option says "without ... postgres") sudo -u git -H bundle install --deployment --without development test postgres aws kerberos
如果出現
Could not locate Gemfile
是因為安裝的時候,沒有再 /home/git/gitlab 文件下
5 、 安裝 gitlab shell
# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed): sudo -u git -H bundle exec rake gitlab:shell:install[v2.6.6] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production # By default, the gitlab-shell config is generated from your main GitLab config. # You can review (and modify) the gitlab-shell config as follows: sudo -u git -H editor /home/git/gitlab-shell/config.yml
6 、 初始化數據庫
# Go to Gitlab installation folder cd /home/git/gitlab 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:'
設置高級密碼
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword
參考文章:http://my.oschina.net/davehe/blog/220001
http://blog.sina.com.cn/s/blog_70bb32080102vlkj.html
http://doc.gitlab.com/ce/install/installation.html
https://gitlab.com/gitlab-org/gitlab-recipes/tree/master