ITPub博客

首页 > 应用开发 > IT综合 > Linux GitLab安装

Linux GitLab安装

原创 IT综合 作者:百联达 时间:2015-07-28 14:24:19 0 删除 编辑
一:准备
操作系统(server端):CentOS Linux release 7.0.1406


二: 安装 Gitlab 依赖的工具
yum -y update
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 git redis ruby sudo wget crontabs logwatch logrotate perl-Time-HiRes


三: 安装 Redis
 cd /usr/local/src
 wget http://download.redis.io/releases/redis-3.0.0.tar.gz
 tar -zxvf redis-3.0.0.tar.gz
 cd redis-3.0.0/
 make
 cp -R redis-3.0.0 /usr/local
 make install
 ./utils/install_server.sh


配置
 创建 /etc/init.d/redis添加如下内容:
###########################
PATH=/usr/local/bin:/sbin:/usr/bin:/bin




REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli




PIDFILE=/var/run/redis.pid
CONF="/etc/redis/6379.conf"




case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        if [ "$?"="0" ]
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac
##############################


保存后,添加可执行权限:
chmod +x /etc/init.d/redis
确保 redis 能随系统启动:
vi /etc/rc.d/rc.local 
在文件末尾添加下面这行:
service redis start
启动RREDIS
service redis start


四: 安装邮件服务器 
yum -y install postfix


五: 安装Git
先删除系统中原有的老版本 git:
yum -y remove git
cd /usr/local/src
curl --progress https://www.kernel.org/pub/software/scm/git/git-2.4.0.tar.gz | tar xz
cd git-2.4.0/
./configure
make
make prefix=/usr/local install


六: 安装 ruby
 cd ~ 
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz | tar xz 
cd ruby-2.2.2 
./configure --disable-install-rdoc 
make 
make prefix=/usr/local install 


七:  安装Bundler Gem
 
# 用taobao源替换rubygems
gem source -r https://rubygems.org/
gem source -a http://ruby.taobao.org/
gem sources -l
gem install bundler --no-ri --no-rdoc
gem install rugged -v '0.21.4'
 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. - Redmine instalation on Debian 7 
  解决办法:yum   
 install cmake


八:  为 Gitlab 添加系统用户 
 
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git 
为了包含/usr/local/bin到git用户的$PATH,一个方法是编辑超级用户文件。以管理员身份运行:

visudo 
然后搜索:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin 
 将其改成:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin 
 
九:  安装数据库 
  MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB,先搜索 MariaDB 现有的包    
rpm -qa | grep mariadb 
 
 然后全部删除:
   
rpm -e --nodeps mariadb-* 
 
然后创建 /etc/yum.repos.d/MariaDB.repo:
  
vi /etc/yum.repos.d/MariaDB.repo 


 
将以下内容添加至该文件中:
  
# MariaDB 10.0 CentOS repository list - created 2015-05-04 19:16 UTC 
  
# http://mariadb.org/mariadb/repositories/ 
[mariadb] 
name = MariaDB 
baseurl = http://yum.mariadb.org/10.0/centos7-amd64 
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB 
gpgcheck=1 
然后运行下面命令安装 MariaDB 10.0:
  
sudo yum install MariaDB-server MariaDB-client 
 
然后启动 MariaDB 服务:
  
service mysql start 
 
接着运行 mysql_secure_installation:
  
mysql_secure_installation 
 
登录 MariaDB 并创建相应的数据库用户与数据库:
  
mysql -uroot -p 
  
CREATE USER 'git'@'localhost' IDENTIFIED BY '$password'; 
SET storage_engine=INNODB; 
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; 
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost'; 
\q 
尝试使用新用户连接数据库:
 sudo -u git -H mysql -u git -p -D gitlabhq_production 
 \q 

Error installing mysql2: Failed to build gem native extension

解决办法:
yum install mysql-devel  
 yum install libmysql-ruby libmysqlclient-dev

十: 安装 Gitlab 
克隆源
sudo -u -git cd /home/git 
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-10-stable gitlab 
配置
cd /home/git/gitlab 
# Copy the example GitLab config 
# 复制GitLab的示例配置文件 
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 
# 确保修改“localhost”为你的GitLab主机的FQDN 
# 
# If you want to use https make sure that you set `https` to `true`. See #using-https for all necessary details. 
# 如果你想要使用https确保你设置了`https`为`true`。具体必要的细节参见#using-https 
# 
# If you installed Git from source, change the git bin_path to /usr/local/bin/git 
# 如果你从源代码安装了Git,修改git的bin_path为/usr/local/bin/git 
sudo -u git -H editor config/gitlab.yml 
 
# Make sure GitLab can write to the log/ and tmp/ directories 
# 确保GitLab可以写入log/和temp/目录 
chown -R git {log,tmp} 
chmod -R u+rwX {log,tmp} 
 
# Create directory for satellites 
# 为卫星(?)创建目录 
sudo -u git -H mkdir /home/git/gitlab-satellites 
chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites 
 
# Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories 
# 确保GitLab可以写入tmp/pids/和temp/sockets/目录 
chmod -R u+rwX  tmp/{pids,sockets} 
 
# Make sure GitLab can write to the public/uploads/ directory 
# 确保GitLab可以写入public/uploads/目录 
chmod -R u+rwX public/uploads 
 
# Copy the example Unicorn config 
# 复制Unicorn的示例配置文件 
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 
# 启用集群模式如果你期望拥有一个高负载实例 
# 附:修改worker的数量到3用于2GB内存的服务器 
sudo -u git -H editor config/unicorn.rb 
 
# Copy the example Rack attack config 
# 复制Rack attack的示例配置文件 
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 config/gitlab.yml 
# 为git用户配置Git全局设定,当通过web修改时有用 
# 修改user.email根据config/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 
数据库配置


  
# MySQL only: 
  
# 仅限MySQL: 
sudo -u git cp config/database.yml.mysql config/database.yml 
  
# MySQL and remote PostgreSQL only: 
# Update username/password in config/database.yml. 
# You only need to adapt the production settings (first part). 
# If you followed the database guide then please do as follows: 
# Change 'secure password' with the value you have given to $password 
# You can keep the double quotes around the password 
# 仅限MySQL和远程PostgreSQL: 
# 在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 
# PostgreSQL和MySQL: 
# 设置config/database.yml仅对git可读。 
sudo -u git -H chmod o-rwx config/database.yml 
安装 Gems


  
cd /home/git/gitlab 
  
  
# For users from China mainland only 
# 仅限中国大陆用户 
nano /home/git/gitlab/Gemfile 
source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/" 
  
# For MySQL (note, the option says "without ... postgres") 
sudo -u git -H bundle install --deployment --without development test postgres aws 
Install GitLab shell


安装GitLab Shell


GitLab Shell是一个专门为GitLab开发的SSH访问和源管理软件。
  
# Go to the Gitlab installation folder: 
  
# 转到GitLab安装目录: 
cd /home/git/gitlab 
  
# For users from China mainland only 
# 仅限中国大陆用户 
nano /home/git/gitlab/Gemfile 
source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/" 
  
# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed): 
# 运行gitlab-shell的安装任务(替换`REDIS_URL`如果有需要的话): 
sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production 
  
# By default, the gitlab-shell config is generated from your main gitlab config. 
# 默认的,gitlab-shell的配置文件是由你的gitlab主配置文件生成的。 
# 
# Note: When using GitLab with HTTPS please change the following: 
# - Provide paths to the certificates under `ca_file` and `ca_path options. 
# - The `gitlab_url` option must point to the https endpoint of GitLab. 
# - In case you are using self signed certificate set `self_signed_cert` to `true`. 
# See #using-https for all necessary details. 
# 提示:当通过HTTPS使用GitLab时,请做出如下更改: 
# - 提供证书的路径在`ca_file`和`ca_path`选项; 
# - `gitlab_url`选项必须指向GitLab的https端点; 
# - 如果你使用自签名的证书,设置`self-signed_cert`为`true`。 
# 所有必需的具体细节参见#using-https 
# 
# You can review (and modify) it as follows: 
# 你可以检查(并修改该)通过以下方法: 
sudo -u git -H editor /home/git/gitlab-shell/config.yml 
  
# Ensure the correct SELinux contexts are set 
# Read http://wiki.centos.org/HowTos/Network/SecuringSSH 
# 确保正确的SELinux上下文被设置 
# 阅读http://wiki.centos.org/HowTos/Network/SecuringSSH 
restorecon -Rv /home/git/.ssh 
初始化数据库和激活高级功能


  
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:' 
提示:你可以设置管理员密码通过在环境变量GITLAB_ROOT_PASSWORD中提供,例如:
  
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword 
 
安装初始化脚本


下载初始化脚本(将放在/etc/init.d/gitlab):
  
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab 
  
chmod +x /etc/init.d/gitlab 
chkconfig --add gitlab 
设置GitLab开机启动:
  
chkconfig gitlab on 
 
设置日志翻转
   
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab 
 
检查应用状态


  
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production 
 
编译静态文件


  
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production 
 
启动实例


   
/etc/init.d/gitlab start 
 






十一:安装配置Nginx
yum -y install nginx
chkconfig nginx on
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
wget -O /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/nginx/gitlab-ssl
ln -sf /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
编辑/etc/nginx/nginx.conf,将 include /etc/nginx/conf.d/*.conf; 替换成 include /etc/nginx/sites-enabled/*;,就是修改额外加载的配置文件目录。


编辑/etc/nginx/sites-available/gitlab,将配置中server_name替换成实际访问的域名。


将nginx加入git用户组


$ usermod -a -G git nginx
$ chmod g+rx /home/git/
添加ssl证书或者自己生成一个


$ cd /etc/nginx
$ openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
启动nginx


$ service nginx start


十二:配置防火墙
配置iptables,使用户可以访问http、https和ssh的端口。


$ lokkit -s http -s https -s ssh
重新启动防火墙


$ service iptables restart
至此就算安装完成了。默认的账号密码:


root
5iveL!fe



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28624388/viewspace-1754136/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Linux Git安装
请登录后发表评论 登录
全部评论
15年以上互联网经验,先后从事过制造业,证券业,物业行业和物流行业信息系统和互联网产品的设计落地实施,8年系统架构经验。最近关注企业数字化转型、财务数字化服务共享、大语言模型、Kubernetes微服务架构和Istio微服务治理框架。

注册时间:2013-02-05

  • 博文量
    332
  • 访问量
    1265624