CentOS下安装Gitlab
环境
Requirements
软件 | 版本 |
---|---|
CentOS | 6.6 |
Python | 2.6 |
Ruby | 2.1.5 |
Git | 1.7.10+ |
Redis | 2.0+ |
MySQL | |
GitLab | 7-8-stable |
GitLab Shell | v2.6.0 |
#======================================================安装必要基础软件yum源======================================================
yum源
为了提高软件安装速度,将yum源设置为阿里云开源镜像
cd /etc/yum.repos.d
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
必要软件包
yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
#======================================================安装必要基础软件yum源======================================================
#======================================================安装Git===============================================================
安装Git
// 查看当前git版本
git --version
// 如果小于1.7.10则先卸载
yum remove git
// 下载最新的git并安装
wget -O git-src.zip https://github.com/git/git/archive/master.zip
unzip git-src.zip
cd git-src
make prefix=/usr/local all
make prefix=/usr/local install
ln -fs /usr/local/bin/git* /usr/bin/
这里可以自己下载git并安装
#======================================================安装Git===============================================================
#======================================================安装Ruby===============================================================
安装Ruby环境
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.5.tar.gz | tar xz
cd ruby-2.1.5
./configure --disable-install-rdoc
make && make install
ln -s /usr/local/bin/ruby /usr/bin/ruby
ln -s /usr/local/bin/gem /usr/bin/gem
ln -s /usr/local/bin/bundle /usr/bin/bundle
// 设置ruby gem源为淘宝
gem source -r https://rubygems.org/
gem source -a http://ruby.taobao.org/
gem install bundler --no-ri --no-rdoc
这里设置淘宝源地址时候需要注意,请使用:
gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org
# 请确保只有 ruby.taobao.org
这里我们不需要安装这个,则跳过gem install rails
#======================================================安装Ruby===============================================================
#======================================================安装MySQL===============================================================
安装MySQL及初始化GitLab库
yum install mysql mysql-devel mysql-server -y
/etc/init.d/mysqld start
chkconfig mysqld on
// 登录mysql创建gitab的帐号和数据库
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
//测试是否可以用git帐号登录数据库
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
更改MySQL用户密码
方法一:
(适用于管理员或者有全局权限的用户重设其它用户的密码)
进入命令行模式
mysql -u root -p
mysql>use mysql;
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='username';
mysql> FLUSH PRIVILEGES;
mysql> quit;
方法二:
mysql -u root -p
mysql>use mysql;
mysql> SET PASSWORD FOR username=PASSWORD('new password');
mysql> QUIT
方法三:
mysqladmin -u root "old password" "new password"
注:new password请输入你想要设置的密码。
(适用于管理员或者有全局权限的用户重设其它用户的密码)
进入命令行模式
mysql -u root -p
mysql>use mysql;
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='username';
mysql> FLUSH PRIVILEGES;
mysql> quit;
方法二:
mysql -u root -p
mysql>use mysql;
mysql> SET PASSWORD FOR username=PASSWORD('new password');
mysql> QUIT
方法三:
mysqladmin -u root "old password" "new password"
注:new password请输入你想要设置的密码。
#======================================================安装MySQL===============================================================
#======================================================安装Redis===============================================================
安装Redis
(1) 上传redis压缩包
(2) tar -xvf redis.xxx.tar.gz
(3) cd redis.xxx
(4) make && make install
(5) redis-server &
#======================================================安装Redis===============================================================
#======================================================安装Gitlab===============================================================
添加git帐号并允许sudo
useradd --comment 'GitLab' git
echo "git ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
安装GitLab
/home/git
sudo -u git -H git clone https://git.oschina.net/rainy.shu/gitlab-ce.git -b 7-8-stable gitlab
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
// 编辑git路径, gitlab的host:port
$ vim config/gitlab.yml
// bin_path: /usr/local/bin/git
// host: localhost
// port: 80
// 给文件夹添加相应的权限
$ chown -R git log/
$ chown -R git tmp/
$ chmod -R u+rwX log/
$ chmod -R u+rwX tmp/
// 创建必要的文件夹,以及复制配置文件
$ sudo -u git -H mkdir /home/git/gitlab-satellites
$ sudo -u git -H mkdir tmp/pids/
$ sudo -u git -H mkdir tmp/sockets/
$ sudo chmod -R u+rwX tmp/pids/
$ sudo chmod -R u+rwX tmp/sockets/
$ sudo -u git -H mkdir public/uploads
$ sudo chmod -R u+rwX public/uploads
$ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
$ sudo -u git -H cp config/initializers/rack_attack.rb.example
config/initializers/rack_attack.rb
// 配置数据库连接信息
$ sudo -u git cp config/database.yml.mysql config/database.yml
$ sudo -u git -H vim config/database.yml
$ vim config/database.yml
// production:
// username: gitlab
// password: "gitlab"
安装GitLab-Shell
$ cd /home/git
$ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v2.6.0
$ cd gitlab-shell/
$ sudo -u git -H cp config.yml.example config.yml
// 编辑配置文件, 设置gitlab_url, redis-cli, log-level...
$ vim config.yml
// gitlab_url: "http://localhost/"
// /usr/bin/redis-cli
// 安装git-shell
$ sudo -u git -H ./bin/install
#======================================================安装Gitlab===============================================================
安装需要ruby的gems
$ cd /home/git/gitlab
修改文件 Gemfile 下的
source 'http://ruby.taobao.org/'不要使用国外的,不然,不能安装,修改后即可安装
安装 cmake
下载
http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
获取CMake源码包
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
解压CMake源码包
tar -zxvf cmake-2.8.10.2.tar.gz
进入目录
cd cmake-2.8.10.2
./bootstrap
gmake
gmake install
安装 sudo -u git -H gem install rugged -v '0.21.2'
$ sudo -u git -H bundle install --deployment --without development test postgres aws
初始化数据库(创建GitLab相关表)
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
这里一定要初始化数据库,不然后面会报错
安装启动文件以及日志切割文件
cp lib/support/init.d/gitlab /etc/init.d/gitlab
cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
设置git帐号信息
$ sudo -u git -H git config --global user.name "Troy Zhang"
$ sudo -u git -H git config --global user.email "troyz@synnex.com"
$ sudo -u git -H git config --global core.autocrlf input
安装Nginx
$ yum -y install nginx
$ vim /etc/nginx/nginx.conf
https://raw.github.com/gitlabhq/gitlabhq/5-2-stable/lib/support/nginx/gitlab保存改文件
Nginx配置
你可以安装nginx来代理访问GitLab 配置过程如下
1. 安装nginx
sudo apt-get install nginx
1. 增加GitLab配置文件
浏览器打开地址:https://raw.github.com/gitlabhq/gitlabhq/5-2-stable/lib/support/nginx/gitlab
将内容拷贝到gitlab.conf中 vim /etc/nginx/conf.d/gitlab.conf
修改对应的:
listen YOUR_SERVER_IP:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com;
2. 重启nginx
sudo service nginx restart
这样你就可以通过nginx来访问gitlab了
更改权限,启动nginx
$ nginx -t
$ chown -R git:git /var/lib/nginx/
$ /etc/init.d/nginx start
检测当前环境
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
拉取gitlab静态资源文件
$ sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
启动gitlab
$ /etc/init.d/gitlab start
检测各个组件是否正常工作
$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
验证是否全部正常:
/home/git/gitlab-shell/bin/check //不报错就OK了
验证是否安装成功,浏览器,http://192.168.1.112:9999/users/sign_in
>用户名:admin@local.host
密 码:5iveL!fe
安装时出现很多问题,我这边感谢网友分享:
http://www.centoscn.com/image-text/install/2015/0320/4929.html
http://blog.51yip.com/server/1558.html