連接服務(wù)器
- 登錄阿里云:
ssh -p 22 root@47.242.185.151
- 登錄騰訊云:
ssh root@175.178.214.222
docker安裝gitlab
- 使用yum安裝yum-utils:
yum install yum-utils
- 阿里云的centos8在使用yum中遇到源找不到的問題
解決辦法:
step1:刪除/etc/yum.repos.d目錄下所有的配置文件
step2:執(zhí)行命令:wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
以及wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
step3:運(yùn)行以下命令替換repo文件中的鏈接
sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo
step4:檢查yum是否可用:
yum clean all && yum makecache
- centos安裝dnf:
yum install dnf
dnf是一個(gè)未來在linux中替換yum的工具
- 使用dnf安裝docker
step1:添加dnf的docker源:
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
step2:安裝docker:dnf install -y docker-ce
- 運(yùn)行docker
啟動(dòng):
systemctl enable docker
運(yùn)行:systemctl start docker
卸載:dnf -y remove docker-engine.x86_64
,rm -rf /var/lib/docker
- 使用docker安裝gitlab
拉取gitlab:
docker pull gitlab/gitlab-ce
- docker啟動(dòng)gitlab:
在/etc/docker目錄下創(chuàng)建docker掛載目錄docker-v,以后所有啟動(dòng)docker后麻裁,掛載文件都放在這個(gè)目錄下
啟動(dòng)命令docker run -d -p 1443:443 -p 1080:80 -p 1222:22 --name gitlab-docker --restart always -v /etc/docker/docker-v/gitlab/config:/etc/gitlab -v /etc/docker/docker-v/gitlab/logs:/var/log/gitlab -v /etc/docker/docker-v/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce
所有的gitlab的配置隱射到/etc/docker/docker-v
目錄中,同時(shí),默認(rèn)為第一個(gè)啟動(dòng)的應(yīng)用端口號(hào)+1000须肆,如1443對(duì)應(yīng)443
檢查是否能訪問gitlab:curl http://175.178.214.222:1080
打開瀏覽器,輸入網(wǎng)址:http://175.178.214.222:1080
,進(jìn)入gitlab
- docker設(shè)置gitlab管理員
docker進(jìn)入gitlab內(nèi)部:
docker exec -it gitlab-docker bash
在gitlab內(nèi)部執(zhí)行命令:gitlab-rails console -e production
在gitlab-rails內(nèi)部執(zhí)行命令:user = User.where(id: 1).first
在gitlab-rails中執(zhí)行修改管理員賬號(hào)命令:user.password="12345678"
在gitlab-rails中執(zhí)行二次確認(rèn)管理員賬號(hào)命令:user.password_confirmation="12345678"
保存:user.save!
退出:quit
- gitlab中使用管理員登錄
打開網(wǎng)址:http://120.24.221.167:1080桩皿,輸入用戶名:root,密碼:“xxxxxxxxx”進(jìn)入登錄
服務(wù)器使用nginx
- 安裝:
docker pull nginx
- 創(chuàng)建nginx的掛載目錄:
mkdir -p /etc/docker/docker-v/nginx/{conf,conf.d,html,logs}
- 創(chuàng)建nginx的config文件:
cd /etc/docker/docker-v/nginx/conf
,vim nginx.conf
- 在nginx.conf文件中插入nginx的默認(rèn)配置
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
- 創(chuàng)建nginx的config文件:
cd /etc/docker/docker-v/nginx/conf.d
,vim default.conf
插入以下內(nèi)容
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
運(yùn)行:
docker run -d -p 2080:80 --name nginx-docker -v /etc/docker/docker-v/nginx/conf.d:/etc/nginx/conf.d -v /etc/docker/docker-v/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /etc/docker/docker-v/nginx/logs:/var/log/nginx -v /etc/docker/docker-v/nginx/attachment:/www/html/attachment -v /etc/docker/docker-v/nginx/html:/usr/share/nginx/html nginx
進(jìn)入nginx http://175.178.214.222:2080
docker操作nginx的命令
- 通過docker檢查nginx的配置文件:
docker exec nginx-docker nginx -t
- 通過docker重新加載nginx的配置文件:
docker exec nginx-docker nginx -s reload
- 通過docker查看nginx的掛載信息:
docker inspect nginx-docker |grep Source -A 1
- 修改nginx學(xué)習(xí)nginx命令
- 修改nginx的默認(rèn)啟動(dòng)頁(yè)面豌汇,路徑:
/etc/docker/docker-v/nginx/html
,修改index.html里的內(nèi)容 - 打開掛截的nginx的default.conf文件:
/etc/docker/docker-v/nginx/conf.d
,vim default.conf
- 增加跳轉(zhuǎn)qq的配置:
location /qq/ {proxy_pass http://www.qq.com/;}
注意格式,特別是地址最后有個(gè)/ - 增加跳轉(zhuǎn)qq的配置:
location /baidu/ {proxy_pass http://www.baidu.com/;}
同樣注意格式 - 這樣泄隔,當(dāng)我們使用默認(rèn)地址:http://175.178.214.222:2080 我們就進(jìn)入了nginx的標(biāo)準(zhǔn)頁(yè)
- 當(dāng)我們使用
http://175.178.214.222:2080/qq/
或是http://175.178.214.222:2080/baidu/
時(shí)拒贱,就會(huì)自行跳轉(zhuǎn)qq或是baidu