http://www.cnblogs.com/restran/p/4411133.html
https://www.dwhd.org/20160406_094416.html
https://docs.gitlab.com/ee/install/installation.html#clone-the-source
1、安装依赖 (有些可能显示不存在,因为官网是ubuntu。名字可能不一样,我装成功的依赖,我都放在这里了。还有依赖,自查吧。。。)
yum -y install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libre2-dev
libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev
libxslt-dev libcurl4-openssl-dev libicu-dev logrotate rsync python-docutils pkg-config cmake
runit install libkrb5-dev curl-devel openssl-devel mysql-devel icu libicu-devel
libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essentia zlib-devel
expat-devel
2、git
yum -y remove git
cd /tmp
curl --remote-name --location --progress https://www.kernel.org/pub/software/scm/git/git-2.18.0.tar.gz
tar -xzf git-2.18.0.tar.gz && cd git-2.18.0/
sudo make prefix=/usr/local install
git --version
3、ruby
yum remove ruby
mkdir /tmp/ruby && cd /tmp/ruby
wget http://mirrors.ustc.edu.cn/ruby/2.3/ruby-2.3.3.tar.gz
tar -xf ruby-2.3.3.tar.gz && cd ruby-2.3.3/
./configure && make && make install
gem install bundler --version '1.14.6' --no-ri --no-rdoc
4、安装Go
mkdir /tmp/go && cd /tmp/go/ && curl --remote-name --progress https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
tar -xf go1.10.3.linux-amd64.tar.gz -C /usr/local/
sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
5、添加用户 & 做软链
mkdir -p /data/home/git
ln -s /data/home/git /home/git
chown -R git:git /data/home/git/
adduser -c 'Gitlab' -s /bin/bash git
vim /etc/sudoers #修改git,参照www用户添加sudo权限,添加免密sudo
groupadd redis && useradd -g redis redis -s /sbin/nologin #添加redis用户
sudo usermod -aG redis git #git用户添加到redis组
6、安装数据库 & 初始化
6.1 安装
找的DBA帮忙(之前本地安装的mariadb,恢复数据导入失败)
6.2 初始化
CREATE USER 'git'@'localhost' IDENTIFIED BY '$password'; #新建密码(和database.yml一致)
CREATE DATABASE IF NOT EXISTS gitlab_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES, REFERENCES ON gitlab_production.* TO 'git'@'localhost';
quit;
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
6.3 mysql 启停
关闭mysql: mysqladmin -h127.0.0.1 -uroot shutdown
启动:/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/my3306/my.cnf &
7、安装redis
yum -y install redis
cp /etc/redis.conf /etc/redis.conf.orig
sed 's/^port .*/port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf
sed -i 's/daemonize no/daemonize yes/g' /etc/redis.conf
mkdir /var/run/redis
sudo chown redis:redis /var/run/redis
sudo chmod 755 /var/run/redis
if [ -d /etc/tmpfiles.d ]; then
echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf
fi
systemctl start redis
|
7、Gitlab
|
7.1 拉取源代码并配置:
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git -b 8-15-stable gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H vim config/gitlab.yml #拷贝线上服务器10.1.101.15:/home/git/gitlab/config/gitlab.yml文件,覆盖。修改host配置项为本机IP
sudo -u git -H vim config/secrets.yml #拷贝线上服务器10.1.101.15:/home/git/gitlab/config/secrets.yml文件,覆盖
sudo -u git -H chmod 0600 config/secrets.yml
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX,go-w log/
sudo chmod -R u+rwX tmp/
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
sudo -u git -H mkdir public/uploads/
sudo chmod 0700 public/uploads
sudo chmod -R u+rwX builds/
sudo chmod -R u+rwX shared/artifacts/
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H vim config/unicorn.rb #修改worker数量为cpu核心数
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H git config --global core.autocrlf input
sudo -u git -H git config --global gc.auto 0
sudo -u git -H cp config/resque.yml.example config/resque.yml #如果redis的sock在其它位置,则修改
sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H vim config/database.yml #修改production环境的socket为mysql的sock文件,通常在/var/lib/mysql/mysql.sock。确认MySQL的用户、密码、库名等配置
sudo -u git -H chmod o-rwx config/database.yml
7.2 Gems安装:
sudo -u git -H bundle install --deployment --without development test postgres aws kerberos -j ${n} #n为cpu数目 提升安装速度。静静等待
7.3 gitlab-shell:
sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production #如果安装成功,会有一系列ok提示
sudo -u git -H vim /home/git/gitlab-shell/config.yml #确认一下配置
7.4 Gitlab-workhorse
sudo -u git -H bundle exec rake "gitlab:workhorse:install/home/git/gitlab-workhorse,[https://gitlab.com/gitlab-org/gitlab-workhorse.git]" RAILS_ENV=production
cd /home/git/gitlab-workhorse
sudo -u git -H make
7.5 Gitlab初始化数据库
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production #中途需要输入yes
7.6 安装Gitlab执行脚本
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
chkconfig gitlab on #设置gitlab开机启动 推荐
7.7 安装logrotate
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
7.8 检查环境配置
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production #此时,除了bundle版本,其它版本应该基本相同
7.9 生成Gitlab前端资源
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
7.10 安装、配置Nginx
sudo yum install nginx
sudo vim /etc/nginx/nginx.conf #配置80端口到8080端口到proxy_pass
sudo service nginx restart
7.10.1 修改权限
usermod -a -G git nginx
chmod g+rx /home/git/
chmod -R g+rx /home/git/gitlab/
chmod o+x /home/git
7.11 启动gitlab
sudo service gitlab start
7.12 最后确认 (check时候,服务器上也要绑定host)
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
根据上述命令产生的检查结果和推荐命令,执行并再次检查
|
8、恢复及备份 8.1 在备份机上恢复线上备份
su - git cd /home/git/gitlab
sudo -u git -H vim config/gitlab.yml #确认backup path配置,确保备份的包在该目录下存在、或移动至该位置。备份的包为$时间戳_gitlab_backup.tar
sudo -u git -H vim config/secrets.yml #确保配置与线上服务器10.1.101.15:/home/git/gitlab/config/secrets.yml文件相同
sudo vim /etc/my.cnf #确保该配置文件添加了 max_allowed_packet=500M 配置
sudo -u git -H bundle exec rake gitlab:backup:restore BACKUP=$时间戳 RAILS_ENV=production #执行恢复备份 中途需要输入yes确认
9、服务器其他配置
9.1 SSH配置 从线上机器,拷贝所有SSH配置,覆盖备份机器
9.2 定时任务配置 从10.37.0.166,复制所有git用户的定时任务(crontab)
9.3 其他脚本</pre>
网友评论