Gitlab-Jekins-SpringBoot 可持续化集成系统

一、docker 安装nginx

  • 1、mkdir -p /usr/local/nginx/www /usr/local/nginx/logs /usr/local/nginx/conf
    www目录将映射为nginx容器配置的虚拟目录
    logs目录将映射为nginx容器的日志目录
    conf目录里的配置文件将映射为nginx容器的配置文件
    要先创建一个nginx.conf文件
  • 2、docker pull nginx
  • 3、运行
docker run -p 80:80 --name mynginx -v /usr/local/nginx/www:/www -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/logs:/wwwlogs -itd nginx /bin/bash
-p 80:80:将容器的80端口映射到主机的80端口 
--name mynginx:将容器命名为mynginx 
-v $PWD/www:/www:将主机中当前目录下的www挂载到容器的/www 
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf:将主机中当前目录下的nginx.conf挂载到容器的/etc/nginx/nginx.conf 
-v $PWD/logs:/wwwlogs:将主机中当前目录下的logs挂载到容器的/wwwlogs 

判断是否正确:

docker exec -it 31  /bin/bash 
nginx -t 

这里写图片描述
说明配置有问题
exit

  • 4、修改配置文件
user  root;
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;
    fastcgi_intercept_errors on;
    #gzip  on;

   # include /etc/nginx/conf.d/*.conf;

 server {
        listen       80;
        server_name  my.gitlab.com;


        location / {
               proxy_pass http://192.168.0.102:8010;
               proxy_set_header Host  $host;
               proxy_set_header X-Forwarded-For  $remote_addr;
        }

    }

   server {
        listen      80;
        server_name  my.jenkins.com;

        location ~/ {
               proxy_pass http://192.168.0.102:8011;
               proxy_set_header Host  $host;
               proxy_set_header X-Forwarded-For  $remote_addr;
        }
    }

    server {
    listen       80;
    server_name  my.nginx.com;

    #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;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

}
  • 5、防火墙

    通过systemctl status firewalld查看firewalld状态,发现当前是dead状态,即防火墙未开启。
    通过systemctl start firewalld开启防火墙,没有任何提示即开启成功。
    再次通过systemctl status firewalld查看firewalld状态,显示running即已开启了。
    如果要关闭防火墙设置,可能通过systemctl stop firewalld这条指令来关闭该功能。
    再次执行执行firewall-cmd –permanent –zone=public –add-port=80/tcp,提示success,表示设置成功,这样就可以继续后面的设置了。firewall-cmd –permanent –zone=public –add-port=8010/tcp
    systemctl restart firewalld
    查看已经开放的端口:
    firewall-cmd –list-ports

  • 6、重新配置

docker exec -it 31  /bin/bash 
nginx -t 
nginx -s reload

这里写图片描述

办法:

nginx -c /etc/nginx/nginx.conf

这里写图片描述

二、最好还是本机装nginx

  • 1、安装位置:/usr/local/webserver/nginx
  • 2、安装文件下载位置/usr/local
  • 3、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
[root@bogon src]# cd pcre-8.35
[root@bogon pcre-8.35]# ./configure
[root@bogon pcre-8.35]# make && make install
[root@bogon pcre-8.35]# pcre-config --version

5、安装 Nginx

[root@bogon src]# wget http://nginx.org/download/nginx-1.9.0.tar.gz
[root@bogon src]# tar zxvf nginx-1.9.0.tar.gz
[root@bogon src]# cd nginx-1.9.0
[root@bogon nginx-1.9.0]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.35
[root@bogon nginx-1.9.0]# make
[root@bogon nginx-1.9.0]# make install

6、将nginx永久加入到系统环境变量
cd /etc
vi profile
加入下面两行:

export NGINX_HOME=/usr/local/webserver/nginx
export PATH=$PATH:$NGINX_HOME/sbin

保存
执行 source /etc/profile 使配置文件生效

[root@bogon nginx-1.6.2]# nginx -v

7、修改配置文件

user  root;

worker_processes 1; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log warn; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;
    fastcgi_intercept_errors on;
    #gzip  on;

   # include /etc/nginx/conf.d/*.conf;

 server {
        listen       80;
        server_name  my.gitlab.com;


        location / {
               proxy_pass http://127.0.0.1:8010;
               proxy_set_header Host  $host;
               proxy_set_header X-Forwarded-For  $remote_addr;
        }

    }

   server {
        listen      80;
        server_name  my.jenkins.com;

        location ~/ {
               proxy_pass http://127.0.0.1:8011;
               proxy_set_header Host  $host;
               proxy_set_header X-Forwarded-For  $remote_addr;
        }
    }

    server {
    listen       80;
    server_name  my.nginx.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/local/webserver/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;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

}
[root@localhost conf]# nginx -c /usr/local/webserver/nginx/conf/nginx.conf
[root@localhost conf]# nginx -s reload

三、gitlab

  • 1、service docker status

  • 2、安装镜像
    docker pull gitlab/gitlab-ce

  • 3、docker images

  • 4、运行

sudo docker run --detach  --hostname my.gitlab.com  --publish 443:443 --publish 8010:8010  --name gitlab  --restart always  --volume /srv/gitlab/config:/etc/gitlab:Z  --volume /srv/gitlab/logs:/var/log/gitlab:Z --volume /srv/gitlab/data:/var/opt/gitlab:Z  gitlab/gitlab-ce:latest
--detach:-d 指定容器运行于前台还是后台 

-h, --hostname=""          指定容器的主机名 

--name=""                  指定容器名字,后续可以通过名字进行容器管理,links特性需要使用名字   

--restart=""               指定容器停止后的重启策略,待详述  no:容器退出时不重启  on-failure:容器故障退出(返回值非零)时重启  always:容器退出时总是重启  

--volume 将主机的文件或文件夹作为volume挂载时,可以用多个 -v标签为容器添加多个volume,还可以使用:ro指定该volume为只读。 -v /host-path:/container-path 
:Z 这个字符最关键,可以解决挂载目录时的权限问题  

这里写图片描述

四、jenkins

  • 1、安装目录
    /usr/local/webserver/jenkins
    mkdir -r /usr/local/webserver/jenkins/
    sudo chown -R 1000 /usr/local/webserver/
  • 2、安装镜像
    docker pull jenkins

  • 3、docker images

  • 4、运行
    docker run –detach –restart=always -p 8011:8080 -p 50000:50000 -v /usr/local/webserver/jenkins/home:/var/jenkins_home:Z jenkins:latest

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值