连接服务器
- 登录阿里云:
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:执行命令: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:运行以下命令替换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是一个未来在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
- 运行docker
启动:systemctl enable docker 运行:systemctl start docker 卸载:dnf -y remove docker-engine.x86_64 ,rm -rf /var/lib/docker
- 使用docker安装gitlab
拉取gitlab:docker pull gitlab/gitlab-ce
- docker启动gitlab:
在/etc/docker目录下创建docker挂载目录docker-v,以后所有启动docker后,挂载文件都放在这个目录下 启动命令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 目录中,同时,默认为第一个启动的应用端口号+1000,如1443对应443 检查是否能访问gitlab:curl http://175.178.214.222:1080 打开浏览器,输入网址:http://175.178.214.222:1080 ,进入gitlab
- docker设置gitlab管理员
docker进入gitlab内部:docker exec -it gitlab-docker bash 在gitlab内部执行命令:gitlab-rails console -e production 在gitlab-rails内部执行命令:user = User.where(id: 1).first 在gitlab-rails中执行修改管理员账号命令:user.password="12345678" 在gitlab-rails中执行二次确认管理员账号命令:user.password_confirmation="12345678" 保存:user.save! 退出:quit
- gitlab中使用管理员登录
打开网址:http://120.24.221.167:1080,输入用户名:root,密码:“xxxxxxxxx”进入登录
服务器使用nginx
- 安装:
docker pull nginx - 创建nginx的挂载目录:
mkdir -p /etc/docker/docker-v/nginx/{conf,conf.d,html,logs} - 创建nginx的config文件:
cd /etc/docker/docker-v/nginx/conf ,vim nginx.conf - 在nginx.conf文件中插入nginx的默认配置
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;
}
- 创建nginx的config文件:
cd /etc/docker/docker-v/nginx/conf.d ,vim default.conf 插入以下内容
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;
}
}
-
运行: 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 -
进入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学习nginx命令
- 修改nginx的默认启动页面,路径:
/etc/docker/docker-v/nginx/html ,修改index.html里的内容 - 打开挂截的nginx的default.conf文件:
/etc/docker/docker-v/nginx/conf.d ,vim default.conf - 增加跳转qq的配置:
location /qq/ {proxy_pass http://www.qq.com/;} 注意格式,特别是地址最后有个/ - 增加跳转qq的配置:
location /baidu/ {proxy_pass http://www.baidu.com/;} 同样注意格式 - 这样,当我们使用默认地址:http://175.178.214.222:2080 我们就进入了nginx的标准页
- 当我们使用
http://175.178.214.222:2080/qq/ 或是http://175.178.214.222:2080/baidu/ 时,就会自行跳转qq或是baidu
|