侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

第二版CentOS源码安装GitLab汉化版

2023-11-21 星期二 / 0 评论 / 0 点赞 / 63 阅读 / 14974 字

软件版本:CentOS 7.2Git 2.12.0Ruby 2.3.3Node.js 6.10.1Redis 3.2.8MariaDB 10.1.20GitLab 8.8.5汉化版GitLab She

软件版本:

  • CentOS 7.2
  • Git 2.12.0
  • Ruby 2.3.3
  • Node.js 6.10.1
  • Redis 3.2.8
  • MariaDB 10.1.20
  • GitLab 8.8.5汉化版
  • GitLab Shell 2.7.2
  • Nginx 1.10.3
  • Go 1.8
  • GitLab-Workhorse 0.7.1

一、安装依赖

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 cmake pcre-devel

二、安装 Git

  • 查看当前 git 版本:
git --version
  • 如果 git 版本小于1.7.10则先卸载:
rpm -e --nodeps git
  • 下载最新 git 源码包并编译安装:
cd /App/src/wget https://www.kernel.org/pub/software/scm/git/git-2.12.0.tar.xztar Jxf git-2.12.0.tar.xzcd git-2.12.0./configure --prefix=/App/gitmake && make installecho 'export PATH=/App/git/bin:$PATH' >> /etc/profile. /etc/profileln -s /App/git/bin/git /bin/ln -s /App/git/bin/git-receive-pack /bin/ln -s /App/git/bin/git-upload-pack /bin/

三、安装 Ruby

cd /App/src/wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.gztar zxf ruby-2.3.3.tar.gzcd ruby-2.3.3./configure --prefix=/App/ruby --disable-install-rdocmake && make installln -s /App/ruby/bin/ruby /bin/echo 'export PATH=/App/ruby/bin:$PATH' >> /etc/profile. /etc/profile
  • 修改 RubyGems 镜像提高下载速度:
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/gem install bundler --no-ri --no-rdoc

四、安装 Node.js

cd /App/src/wget https://nodejs.org/dist/v6.10.1/node-v6.10.1-linux-x64.tar.xztar Jxf node-v6.10.1-linux-x64.tar.xzmv node-v6.10.1-linux-x64 /App/nodeecho 'export PATH=/App/node/bin:$PATH' >> /etc/profile. /etc/profile

五、安装 Go

cd /App/src/wget http://www.golangtc.com/static/go/1.8/go1.8.linux-amd64.tar.gztar zxf go1.8.linux-amd64.tar.gzmv go /App/
  • /etc/profile 添加环境变量配置:
export GOROOT=/App/goexport GOPATH=/root/code/goexport PATH=$GOROOT/bin:$GOPATH/bin:$PATH

六、安装 Redis

cd /App/src/wget http://download.redis.io/releases/redis-3.2.8.tar.gztar zxf redis-3.2.8.tar.gzcd redis-3.2.8make PREFIX=/App/redis installecho 'export PATH=/App/redis/bin:$PATH' >> /etc/profile. /etc/profile
  • 添加Redis配置 /App/redis/redis.conf
daemonize yespidfile /App/redis/redis.pidport 0unixsocket /tmp/redis.sockunixsocketperm 777tcp-backlog 60000timeout 0tcp-keepalive 60loglevel warninglogfile "/App/redis/redis.log"syslog-enabled nodatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /App/redisslave-serve-stale-data yesrepl-diskless-sync yesrepl-diskless-sync-delay 5repl-ping-slave-period 10repl-timeout 60repl-disable-tcp-nodelay noslave-priority 100maxclients 60000maxmemory-policy noevictionappendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
  • 启动 Redis:
/App/redis/bin/redis-server /App/redis/redis.conf

七、安装 MariaDB

cd /App/src/wget https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.1.20/source/mariadb-10.1.20.tar.gztar zxf mariadb-10.1.20.tar.gzcd mariadb-10.1.20cmake . /-DCMAKE_BUILD_TYPE:STRING=Release /-DCMAKE_INSTALL_PREFIX:PATH=/App/mariadb /-DDEFAULT_CHARSET=utf8 /-DDEFAULT_COLLATION=utf8_general_ci /-DWITH_EMBEDDED_SERVER:BOOL=OFF /-DWITH_UNIT_TESTS:BOOL=OFF /-LAHmake && make installcp /App/mariadb/support-files/mysql.server /etc/init.d/mariadbchmod u+x /etc/init.d/mariadbecho 'export PATH=/App/mariadb/bin:$PATH' >> /etc/profile. /etc/profile
  • 添加 MariaDB 配置 /etc/my.cnf
[client]port = 3306socket = /tmp/mysql.sock[mysqld]user = mysqlport = 3306socket = /tmp/mysql.sockserver-id = 1log-bin = bin.loglog-error = error.logpid-file = mysql.pidlong_query_time = 1slow_query_logslow_query_log_file = slow.logbinlog_cache_size = 4Mbinlog_format = mixedmax_binlog_cache_size = 16Mmax_binlog_size = 1Gexpire_logs_days = 30ft_min_word_len = 4back_log = 4096max_allowed_packet = 64Mmax_connections = 65536max_connect_errors = 100join_buffer_size = 1Mread_buffer_size = 1Mread_rnd_buffer_size = 1Msort_buffer_size = 1Mquery_cache_size = 64Mtable_open_cache = 2048thread_cache_size = 256max_heap_table_size = 64Mtmp_table_size = 64Mthread_stack = 192Kconnect_timeout = 600interactive_timeout = 600wait_timeout = 600thread_concurrency = 8local-infile = 0skip-show-databaseskip-name-resolveskip-external-locking#*** MyISAMkey_buffer_size = 512Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 32Mmyisam_max_sort_file_size = 1Gmyisam_repair_threads = 1myisam_recover#*** INNODBinnodb_buffer_pool_size = 1Ginnodb_additional_mem_pool_size = 32Minnodb_data_file_path = ibdata:32M:autoextendinnodb_file_per_table = 1innodb_flush_log_at_trx_commit = 2innodb_lock_wait_timeout = 120innodb_log_buffer_size = 8Minnodb_log_file_size = 256Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 10innodb_thread_concurrency = 16#innodb_force_recovery = 4#*** Replication Slave#read-only#skip-slave-startrelay-log = relay.loglog-slave-updates
  • 初始化 MariaDB:
useradd -s /bin/false -M mysql/App/mariadb/scripts/mysql_install_db --basedir=/App/mariadb --datadir=/App/mariadb/data --user=mysql
  • 启动 MariaDB:
/etc/init.d/mariadb start
  • 执行命令 mysql -uroot 登录 MariaDB 创建数据库并授权:
CREATE DATABASE `gitlabhq_production` DEFAULT CHARSET utf8;GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES ON `gitlabhq_production`.* TO 'git'@'127.0.0.1' IDENTIFIED BY '数据库连接密码';GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES ON `gitlabhq_production`.* TO 'git'@'localhost' IDENTIFIED BY '数据库连接密码';FLUSH PRIVILEGES;QUIT;

八、安装 GitLab

useradd --system -s /bin/bash --comment 'GitLab' -m -d /home/git git
  • 修改 git 家目录权限,否则访问 gitlab.socket 报权限错误:
chmod 755 /home/git
  • 切换至 git 用户 clone 代码:
su - gitgit clone https://gitlab.com/larryli/gitlab.git -b 8-8-zh gitlab
  • 拷贝 GitLab 配置:
cd gitlab/cp config/gitlab.yml.example config/gitlab.yml
  • 修改 gitlab.yml 配置,将行 host: localhost 修改为本机IP地址或者域名,如为域名,确保域名已做解析。
  • 拷贝示例配置,修改权限:
cp config/secrets.yml.example config/secrets.ymlchmod 0600 config/secrets.ymlchmod -R u+rwX,go-w log/chmod -R u+rwX tmp/chmod -R u+rwX tmp/pids/chmod -R u+rwX tmp/sockets/mkdir public/uploads/chmod 0700 public/uploadschmod -R u+rwX builds/chmod -R u+rwX shared/artifacts/mkdir -p shared/pages/chmod -R ug+rwX shared/pages/cp config/unicorn.rb.example config/unicorn.rbcp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rbgit config --global core.autocrlf inputgit config --global gc.auto 0git config --global repack.writeBitmaps truecp config/resque.yml.example config/resque.yml
  • 修改 Redis 相关配置 config/resque.yml 内容 production: unix:/var/run/redis/redis.sockproduction: unix:/tmp/redis.sock
  • 拷贝数据库相关配置:
cp config/database.yml.mysql config/database.yml
  • 修改 config/database.yml 前段 PRODUCTION 部分内容, password: "secure password" 修改为 password: "数据库连接密码"
chmod o-rwx config/database.yml
  • 安装 Gems:
bundle config mirror.https://rubygems.org https://gems.ruby-china.orgbundle install --deployment --without development test postgres aws kerberos
  • 安装 GitLab Shell:
bundle exec rake gitlab:shell:install REDIS_URL=unix:/tmp/redis.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
  • 安装 GitLab-Workhorse:
cd /home/gitgit clone https://gitlab.com/gitlab-org/gitlab-workhorse.gitcd gitlab-workhorsegit checkout v0.7.1make
  • 初始化数据库并激活高级功能:
cd /home/git/gitlabbundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=root密码

GITLAB_ROOT_PASSWORD 值为 GitLab 管理员 root 密码。

  • 切换为 root 用户后拷贝服务脚本:
exitcp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/
  • 配置 Logrotate:
cp /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/
  • 检查应用状态:
su - gitcd gitlab/bundle exec rake gitlab:env:info RAILS_ENV=production
  • 编译静态文件:
bundle exec rake assets:precompile RAILS_ENV=production

九、安装 Nginx

  • 切换至 root 用户安装:
exitcd /App/src/wget http://nginx.org/download/nginx-1.10.3.tar.gztar zxf nginx-1.10.3.tar.gzcd nginx-1.10.3./configure --prefix=/App/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_modulemake && make installuseradd -s /bin/false nginx
  • 修改 Nginx 配置 /App/nginx/conf/nginx.conf
user  nginx nginx;worker_processes  auto;error_log  logs/error.log error;pid        logs/nginx.pid;worker_rlimit_nofile    65536;events{    use epoll;    accept_mutex off;    worker_connections  65536;}http{    include       mime.types;    default_type  text/html;    charset	UTF-8;    server_names_hash_bucket_size	128;    client_header_buffer_size		4k;    large_client_header_buffers	 4	32k;    client_max_body_size            20m;    open_file_cache max=65536  inactive=60s;    open_file_cache_valid      80s;    open_file_cache_min_uses   1;    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for"';    access_log  logs/access.log  main;    sendfile    on;    server_tokens off;    keepalive_timeout  60;    gzip  on;    gzip_min_length	1k;    gzip_buffers  4	64k;    gzip_http_version	1.1;    gzip_comp_level	2;    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;    upstream gitlab     {        server unix:/home/git/gitlab/tmp/sockets/gitlab.socket fail_timeout=0;    }    upstream gitlab-workhorse     {        server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0;    }    server {        listen      80;        server_name _;        root        /home/git/gitlab/public;        location /        {            try_files $uri $uri/index.html $uri.html @gitlab;        }        location /uploads/        {            proxy_read_timeout      300;            proxy_connect_timeout   300;            proxy_redirect          off;            proxy_set_header    Host                $http_host;            proxy_set_header    X-Real-IP           $remote_addr;            proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;            proxy_set_header    X-Forwarded-Proto   $scheme;            proxy_set_header    X-Frame-Options     SAMEORIGIN;            proxy_pass http://gitlab;        }        location @gitlab        {            proxy_read_timeout      300;            proxy_connect_timeout   300;            proxy_redirect          off;            proxy_set_header    Host                $http_host;            proxy_set_header    X-Real-IP           $remote_addr;            proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;            proxy_set_header    X-Forwarded-Proto   $scheme;            proxy_set_header    X-Frame-Options     SAMEORIGIN;            proxy_pass http://gitlab;        }        location ~ [-///w/.]+/.git//        {            proxy_read_timeout      300;            proxy_connect_timeout   300;            proxy_redirect          off;            proxy_buffering off;            proxy_set_header    Host                $http_host;            proxy_set_header    X-Real-IP           $remote_addr;            proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;            proxy_set_header    X-Forwarded-Proto   $scheme;            proxy_pass http://gitlab-workhorse;        }        location ~ ^/(assets)/        {            root /home/git/gitlab/public;            gzip_static on;            expires max;            add_header Cache-Control public;        }        error_page 502 /502.html;    }}

十、SMTP 相关配置

  • 复制smtp示例配置:
cp /home/git/gitlab/config/initializers/smtp_settings.rb.sample /home/git/gitlab/config/initializers/smtp_settings.rb
  • smtp_settings.rbenable_starttls_auto: true 修改为 enable_starttls_auto: falseopenssl_verify_mode: 'peer' 行前添加 # 注释,其余按照自己的邮箱正常配置即可。

十一、启动 GitLab 实例

/etc/init.d/gitlab start

广告 广告

评论区