使用阿里云资源在centos7上配置docker安装gitlab、mysql、jira
Docker要求64位的系统且内核版本至少为3.10
一、安装docker
1、添加yum源。
yum install epel-release –y
yum clean all
yum list
2、安装并运行Docker。
yum install docker-io –y
systemctl start docker
3、检查安装结果
docker info
二、安装gitlab
1、查找镜像:docker search gitlab
2、安装镜像
docker pull docker.io/gitlab/gitlab-ce(这个过程会很久,下载需要一定时间)
3、查看镜像
docker images
4、创建容器
docker run -d \
--hostname gitlab \ # 指定容器域名,未知功能:创建镜像仓库的时候使用到
-p 8443:443 \ # 将容器内443端口映射到主机8443,提供https服务
-p 8888:80 \ # 将容器内80端口映射到主机8888,提供http服务
-p 2222:22 \ # 将容器内22端口映射到主机2222,提供ssh服务
-p 9090:9090 \ # 将容器内9090端口映射到主机9090,提供prometheus服务
--name gitlaba \ # 指定容器名称
--restart always \ # 容器退出时,自动重启
-v /home/gitlab/config:/etc/gitlab \ # 将本地/home/gitlab/config挂载到容器内/etc/gitlab
-v /home/gitlab/log:/var/log/gitlab \ # 将本地/home/gitlab/log挂载到容器内/var/log/gitlab
-v /home/gitlab/opt:/var/opt/gitlab \ # 将本地/home/gitlab/opt挂载到容器内/var/opt/gitlab
gitlab/gitlab-ce:latest # 镜像名称:版本
5、查看Gitlab容器运行情况
docker inspect gitlaba --format "{{.State.Status}}"
6、配置web请求地址
vim /home/gitlab/config/gitlab.rb,更改如下信息:
external_url 'http://192.168.217.128'
7、配置重载
docker exec -t gitlaba gitlab-ctl reconfigure
docker exec -t gitlaba gitlab-ctl restart
8、其他配置
时区设置
gitlab_rails['time_zone'] = 'Asia/Shanghai'
Gitlab镜像自带nginx配置
nginx['enable'] = true
nginx['client_max_body_size'] = '250m'
nginx['redirect_http_to_https'] = false
nginx['listen_addresses'] = ['0.0.0.0', '[::]']
nginx['listen_port'] = 80
nginx['listen_https'] = false
nginx['custom_gitlab_server_config'] = "location ^~ /foo-namespace/bar-project/raw/ {\n deny all;\n}\n"
nginx['custom_nginx_config'] = "include /etc/nginx/conf.d/*.conf;"
nginx['proxy_read_timeout'] = 3600
nginx['proxy_connect_timeout'] = 300
nginx['proxy_set_headers'] = {
"Host" => "$http_host_with_default",
"X-Real-IP" => "$remote_addr",
"X-Forwarded-For" => "$proxy_add_x_forwarded_for",
"Upgrade" => "$http_upgrade",
"Connection" => "$connection_upgrade"
}
nginx['proxy_cache_path'] = 'proxy_cache keys_zone=gitlab:10m max_size=1g levels=1:2'
nginx['proxy_cache'] = 'gitlab'
nginx['http2_enabled'] = false
nginx['real_ip_trusted_addresses'] = ['172.16.0.0/16']
nginx['real_ip_header'] = 'X-Real-IP'
nginx['real_ip_recursive'] = on
nginx['custom_error_pages'] = {
'404' => {
'title' => 'Example title',
'header' => 'Example header',
'message' => 'Example message'
}
}
nginx['dir'] = "/var/opt/gitlab/nginx"
nginx['log_directory'] = "/var/log/gitlab/nginx"
nginx['worker_processes'] = 4
nginx['worker_connections'] = 10240
nginx['log_format'] = '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'
nginx['sendfile'] = 'on'
nginx['tcp_nopush'] = 'on'
nginx['tcp_nodelay'] = 'on'
nginx['gzip'] = "on"
nginx['gzip_http_version'] = "1.0"
nginx['gzip_comp_level'] = "2"
nginx['gzip_proxied'] = "any"
nginx['gzip_types'] = [ "text/plain", "text/css", "application/x-javascript", "text/xml", "application/xml", "application/xml+rss", "text/javascript", "application/json" ]
nginx['keepalive_timeout'] = 65
nginx['cache_max_size'] = '5000m'
nginx['server_names_hash_bucket_size'] = 64
nginx['status'] = {
"enable" => false,
}
配置邮件服务
# 设置邮件抬头发件人地址
gitlab_rails['gitlab_email_from'] = 'aaa@qq.com'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "aaa@qq.com"
gitlab_rails['smtp_password'] = "xxxx"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'none'
# 设置邮件抬头发件人昵称
user['git_user_name'] = "GitLab"
邮件部分参考小狐濡尾特此注明出处
邮件功能调试命令
gitlab-rails console Notify.test_email('***@163.com', 'Message Subject', 'Message Body').deliver_now
Gitlab镜像自带Postgresql配置
postgresql['enable'] = true
postgresql['ssl'] = 'off'
Gitlab镜像自带Redis配置
gitlab_rails['redis_host'] = "127.0.0.1"
gitlab_rails['redis_port'] = 6379
gitlab_rails['redis_password'] = '00e05611e8f68d6e9c9cc62f'
gitlab_rails['redis_database'] = 0
redis['enable'] = true
redis['username'] = "gitlab-redis"
redis['maxclients'] = "10000"
redis['maxmemory'] = "1gb"
redis['maxmemory_policy'] = "allkeys-lru"
redis['maxmemory_samples'] = "5"
redis['tcp_timeout'] = "60"
redis['tcp_keepalive'] = "300"
redis['port'] = 6379
redis['password'] = '00e05611e8f68d6e9c9cc62f'
Gitlab备份路径配置
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
监控Prometheus配置
prometheus['enable'] = true
prometheus['monitor_kubernetes'] = false # 如果用k8s安装Gitlab,此处应设置为true
prometheus['username'] = 'gitlab-prometheus'
prometheus['uid'] = nil
prometheus['gid'] = nil
prometheus['shell'] = '/bin/sh'
prometheus['home'] = '/var/opt/gitlab/prometheus'
prometheus['log_directory'] = '/var/log/gitlab/prometheus'
prometheus['scrape_interval'] = 15
prometheus['scrape_timeout'] = 15
prometheus['chunk_encoding_version'] = 2
prometheus['listen_address'] = '0.0.0.0:9090' # 注意端口和之前docker run -p 9090一致
prometheus_monitoring['enable'] = true
# 以下为设置加入Prometheus的开关和配置项
node_exporter['enable'] = true
redis_exporter['enable'] = true
redis_exporter['log_directory'] = '/var/log/gitlab/redis-exporter'
redis_exporter['flags'] = {
'redis.addr' => "127.0.0.1:6379",
'redis.password' => '00e05611e8f68d6e9c9cc62f'
}
postgres_exporter['enable'] = true
gitlab_monitor['enable'] = true
配置重载
docker exec -t gitlab gitlab-ctl reconfigure
docker exec -t gitlab gitlab-ctl restart
结束
配置到处为止
内网使用,暂时不开启HTTPS
自签证书实现Gitlab HTTPS双向认证部分等有空了再说吧
日常管理
-
配置重载
docker exec -t gitlab gitlab-ctl reconfigure docker exec -t gitlab gitlab-ctl restart
- 备份恢复
# 备份 docker exec -t gitlab gitlab-rake gitlab:backup:create # gitlab还原 docker exec -t gitlab gitlab-ctl stop unicorn docker exec -t gitlab gitlab-ctl stop sidekiq docker exec -t gitlab gitlab-rake gitlab:backup:restore BACKUP=1521789664_2018_03_23_10.5.6 docker exec -t gitlab gitlab-ctl restart docker exec -t gitlab gitlab-rake gitlab:check SANITIZE=true
参考资料
Docker安装报错参考docker.libseccomp2
配置文件参考官网配置Gitlab.doc
Gitlab镜像自带的监控Prometheus配置可以参照官方Gitlab.Prometheus.doc
三、安装mysql
1、docker search mysql
2、docker pull docker.io/centos/mysql-56-centos7
3、docker run -d --name=mysql-db --hostname=mysql-db -p 20010:3306 -e MYSQL_ROOT_PASSWORD=123456 centos/mysql-56-centos7:latest
用Navicat远程连接,新建数据库,字符集选择如下:
四、安装jira
1、docker search jira
2、docker pull docker.io/cptactionhank/atlassian-jira-software
3、docker run -d --name jira --hostname jira --link mysql-db:mysql -p 20011:8085 -p 20012:8080 -p 20013:8443 -p 20014:8090 -p 20015:22 -v /home/jira/opt:/opt/atlassian/jira -v /home/jira/var:/var/atlassian/application-data/jira cptactionhank/atlassian-jira-software:latest
(docker run --privileged=true -ti -v /home/wjira:/home -p 20011:8085 -p 20012:8080 -p 20013:8443 -p 20014:8090 -p 20015:22 --restart always cptactionhank/atlassian-jira-software:latest)
4、登陆jira页面
http://localhost:20012
如果报错,执行以下操作:
(1)在命令行界面输入docker ps -a查看容器id
(2)进入jira容器docker exec -ti f9ca3748bd4b /bin/bash
(3)重新启动jira服务
cd /opt/atlassian/jira/bin
./shutdown.sh
./startup.sh
5、配置数据库
重新打开web页面:http://localhost:20012
选择I'll set it up myself
-Next
在Database setup
,选择My Own Database
,按以下信息选择和输入
Database Type:MySQL
Hostname:mysql
Port:3306
Database:jiradb
Username:root
Password:123456
上一篇: MySQL学习笔记(二)
下一篇: 爬虫断了?