DevOps流程模拟(一)

发布于:2022-10-21 ⋅ 阅读:(524) ⋅ 点赞:(0)

 1. 初始化docker环境

yum install -y docker-ce docker-compose
systemctl start docker
echo '{"registry-mirrors":["https://ung2thfc.mirror.aliyuncs.com"]}' > /etc/docker/daemon.json
systemctl restart docker
systemctl enable docker
docker version

2. 安装Git

yum -y install git

3. 安装Gitlab

3.1 拉取Gitlab镜像

docker search gitlab
docker pull gitlab/gitlab-ce:latest

查看镜像

[root@ansible ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED        SIZE
gitlab/gitlab-ce   latest    46cd6954564a   9 months ago   2.36GB

3.2 启动Gitlab容器

[root@ansible ~]# mkdir -p /ajunyu/soft/docker/docker-gitlab
[root@ansible ~]# cd /ajunyu/soft/docker/docker-gitlab/
version: '3'
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    container_name: gitlab
    restart: always
    environment:
      TZ: 'Asia/Shanghai'
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://16.188.100.66:9999'            #端口号最好不要大于10000
        gitlab_rails['gitlab_shell_ssh_port'] = 9922
        gitlab_rails['time_zone'] = 'Asia/Shanghai'
        gitlab_rails['smtp_enable'] = true
        gitlab_rails['smtp_address'] = "smtp.163.com"
        gitlab_rails['smtp_port'] = 465
        gitlab_rails['smtp_user_name'] = "ajunyu163"
        gitlab_rails['smtp_password'] = "授权码"
        gitlab_rails['smtp_authentication'] = "login"
        gitlab_rails['smtp_enable_starttls_auto'] = true
        gitlab_rails['smtp_tls'] = true
        gitlab_rails['gitlab_email_from'] = 'ajunyu163@163.com'
    ports:
      - '9999:9999'
      - '9922:9922'
    volumes:
      - /ajunyu/gitlab/config:/etc/gitlab
      - /ajunyu/gitlab/data:/var/opt/gitlab
      - /ajunyu/gitlab/logs:/var/log/gitlab
[root@ansible docker-gitlab]# docker-compose up -d
Creating network "dockergitlab_default" with the default driver
Creating gitlab ... done
[root@ansible docker-gitlab]# docker ps
CONTAINER ID   IMAGE                     COMMAND             CREATED         STATUS                   PORTS                                                                                                           NAMES
d43930885743   gitlab/gitlab-ce:latest   "/assets/wrapper"   3 minutes ago   Up 3 minutes (healthy)   22/tcp, 80/tcp, 0.0.0.0:9922->9922/tcp, :::9922->9922/tcp, 443/tcp, 0.0.0.0:9999->9999/tcp, :::9999->9999/tcp   gitlab

查询日志,查看启动情况

[root@ansible docker-gitlab]# docker-compose logs -f
......
gitlab    |       - execute the ruby block restart_log_service
gitlab    |     * directory[/opt/gitlab/service] action create (up to date)
gitlab    |     * link[/opt/gitlab/service/grafana] action create (up to date)
gitlab    |     * ruby_block[wait for grafana service socket] action run (skipped due to not_if)
gitlab    |
gitlab    |   * execute[/opt/gitlab/bin/gitlab-ctl start grafana] action run
gitlab    |     [execute] ok: run: grafana: (pid 962) 6s
gitlab    |     - execute /opt/gitlab/bin/gitlab-ctl start grafana
gitlab    | Recipe: gitlab::database_reindexing_disable
gitlab    |   * crond_job[database-reindexing] action delete
gitlab    |     * file[/var/opt/gitlab/crond/database-reindexing] action delete (up to date)
gitlab    |      (up to date)
gitlab    | Recipe: gitlab::gitlab-rails
......

nginx未启动之前访问不到界面,nginx启动gitlab未配置好会报502,等待容器服务启动即可。

3.3 登录Gitlab

使用root用户登录,默认密码在容器/etc/gitlab/initial_root_password里,文件已映射到本地,可以直接从本地查看。

需要注意的是初始密码文件存在24小时:This file will be automatically deleted in the first reconfigure run after 24 hours.登录后要尽快更改密码。

[root@ansible docker-gitlab]# cat /ajunyu/gitlab/config/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: GvjUhYfp81IJDKQMpEtIJc7AT8mhv80oI+Y9jN0qe34=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

 

更改密码

 

4. 初始化jdk环境

安装jdk

安装包:

https://download.java.net/java/GA/jdk18.0.2.1/db379da656dc47308e138f21b33976fa/1/GPL/openjdk-18.0.2.1_linux-x64_bin.tar.gz

[root@node-67 soft]# ll
total 217728
-rw-r--r-- 1 root root   8676320 Oct 21 22:26 apache-maven-3.8.6-bin.tar.gz
-rw-r--r-- 1 root root 188255745 Oct 21 22:27 openjdk-18.0.2.1_linux-x64_bin.tar.gz
[root@node-67 soft]# tar -zxf openjdk-18.0.2.1_linux-x64_bin.tar.gz -C /usr/local/
[root@node-67 soft]# mv /usr/local/jdk-18.0.2.1 /usr/local/jdk
[root@node-67 soft]# chmod +x /usr/local/jdk/bin/*
[root@node-67 soft]# chown -R ajunyu:ajunyu /usr/local/jdk/

添加环境变量

[root@node-67 soft]# vim /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib

验证

[root@node-67 soft]# source /etc/profile
[root@node-67 soft]# java -version
openjdk version "18.0.2.1" 2022-08-18
OpenJDK Runtime Environment (build 18.0.2.1+1-1)
OpenJDK 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)

5. 初始化maven环境

安装maven

安装包:

https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz

[root@node-67 soft]# tar -zxf apache-maven-3.8.6-bin.tar.gz /usr/local/
[root@node-67 soft]# mv /usr/local/apache-maven-3.8.6 /usr/local/maven
[root@node-67 soft]# chmod +x /usr/local/maven/bin/*
[root@node-67 soft]# chown -R ajunyu:ajunyu /usr/local/maven/

添加环境变量

[root@node-67 soft]# vim /etc/profile
export PATH=/usr/local/maven/bin/:$PATH

修改maven仓库地址

[root@node-67 soft]# vim  /usr/local/maven/conf/settings.xml
..........
232     <profiles>
233         <profile>
234             <id>jdk-1.8</id>
235             <activation>
236                 <activeByDefault>true</activeByDefault>
237                 <jdk>1.8</jdk>
238             </activation>
239
240             <properties>
241                 <maven.compiler.source>1.8</maven.compiler.source>
242                 <maven.compiler.target>1.8</maven.compiler.target>
243                 <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
244             </properties>
245         </profile>
246     </profiles>
247   <!-- activeProfiles -->
248   <activeProfiles>
249     <activeProfile>jdk-1.8</activeProfile>
250   </activeProfiles>
..........

验证

[root@node-67 soft]# source /etc/profile
[root@node-67 soft]# mvn -v
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /usr/local/maven
Java version: 18.0.2.1, vendor: Oracle Corporation, runtime: /usr/local/jdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.76.1.el7.x86_64", arch: "amd64", family: "unix
本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到