写点什么

极客时间运维进阶训练营第三周作业

作者:9527
  • 2022-11-12
    美国
  • 本文字数:4732 字

    阅读完需:约 16 分钟

Docker Compose

Install Docker compose

  • Download from github

$ wget https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64100%[===========================================================================================================================>] 44,949,504  --.-K/s   in 0.09s
2022-11-06 16:21:25 (470 MB/s) - ‘docker-compose-linux-x86_64’ saved [44949504/44949504]
复制代码
  • Move it to "/usr/local/bin"

$ mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose$ chmod +x /usr/local/bin/docker-compose$ docker-compose versionDocker Compose version v2.12.2
复制代码

Prepare docker-compose YAML file

  • Create application folder

$ mkdir myapp$ cd myapp
复制代码
  • Create docker-compose.yml file

version: '3.8'services:  nginx-server:    image: nginx:1.22.0-alpine    container_name: nginx_web1    expose:      - 80      - 443    ports:      - "80:80"      - "443:443"    networks:      - front   # eth0      - backend # eth1    links:  # Depends on tomcat server service      - tomcat-server    tomcat-server:    # image: tomca:7.0.93-alpine    image: registry.cn-hangzhou.aliyuncs.com/zhangshijie/tomcat-myapp:v1    container_name: tomcat-app1    networks:      - backend    links:  # Depends on mysql server service      - mysql-server    mysql-server:    image: mysql:5.6.48    container_name: mysql-app1    volumes:      - /data/mysql/conf/my.cnf:/etc/my.cnf:ro    environment:      - "MYSQL_ROOT_PASSWORD=12345678"      - "TZ=America/NewYork"    expose:      - 3306    ports:      - "3306:3306"    networks:      - backend
networks: front: driver: bridge backend: driver: bridge default: external: name: bridge
复制代码
  • Run docker-compose up -d command:

$ docker-compose pullWARN[0000] network default: network.external.name is deprecated in favor of network.name[+] Running 34/34 ⠿ nginx-server Pulled ... ⠿ tomcat-server Pulled ... ⠿ mysql-server Pulled  $ docker-compose up -dWARN[0000] network default: network.external.name is deprecated in favor of network.name[+] Running 5/5 ⠿ Network 202211-06_front    Created                                                                                                                           0.0s ⠿ Network 202211-06_backend  Created                                                                                                                           0.0s ⠿ Container mysql-app1       Started                                                                                                                           3.6s ⠿ Container tomcat-app1      Started                                                                                                                           1.8s ⠿ Container nginx_web1       Started  $ docker network lsNETWORK ID     NAME                DRIVER    SCOPE8a2813e542f0   202211-06_backend   bridge    local3e9ed32531de   202211-06_front     bridge    local61c7149b00ec   bridge              bridge    locald7ed9cc4b808   host                host      local1f8da3a09945   none                null      local
复制代码


  • Check nginx network devices:

$ docker exec -it 5066a5495165 sh -c "ip addr"1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00    inet 127.0.0.1/8 scope host lo       valid_lft forever preferred_lft forever10: eth1@if11: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP    link/ether 02:42:ac:12:00:02 brd ff:ff:ff:ff:ff:ff    inet 172.18.0.2/16 brd 172.18.255.255 scope global eth1       valid_lft forever preferred_lft forever12: eth0@if13: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP    link/ether 02:42:ac:13:00:04 brd ff:ff:ff:ff:ff:ff    inet 172.19.0.4/16 brd 172.19.255.255 scope global eth0       valid_lft forever preferred_lft forever       $ docker exec -it 5066a5495165 sh/ # ping tomcat-serverPING tomcat-server (172.19.0.3): 56 data bytes64 bytes from 172.19.0.3: seq=0 ttl=255 time=0.071 ms^C--- tomcat-server ping statistics ---1 packets transmitted, 1 packets received, 0% packet lossround-trip min/avg/max = 0.071/0.071/0.071 ms
$ / # curl tomcat-server:8080/myapp/index.jsp
<br />host: 2e8b8c1c935f
<br />remoteAddr: 172.19.0.4<br />remoteHost: 172.19.0.4<br />sessionId: 63DCDCA80C6F7E268FFFBAC1E39757E9<br />serverName:tomcat-server<br />scheme:http<br />
host : tomcat-server:8080<br />user-agent : curl/7.83.1<br />accept : */*<br />
复制代码


Gitlab

  • Download Gitlab rpm file

$ wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/amazon/2/gitlab-ce-15.3.5-ce.0.amazon2.x86_64.rpm/download.rpm...HTTP request sent, awaiting response... 302 Found...Saving to: ‘gitlab-ce-15.3.5-ce.0.amazon2.x86_64.rpm’
100%[==============================>] 1,107,025,750 204MB/s in 5.3s
2022-11-07 02:04:57 (200 MB/s) - ‘gitlab-ce-15.3.5-ce.0.amazon2.x86_64.rpm’ saved [1107025750/1107025750]
$ ls -lhtotal 1.1G-rw-r--r-- 1 root root 1.1G Nov 2 13:21 gitlab-ce-15.3.5-ce.0.amazon2.x86_64.rpm
复制代码
  • Install Gitlab

$ rpm -i gitlab-ce-15.3.5-ce.0.amazon2.x86_64.rpmwarning: gitlab-ce-15.3.5-ce.0.amazon2.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEYIt looks like GitLab has not been configured yet; skipping the upgrade script.
*. *. *** *** ***** ***** .****** ******* ******** ******** ,,,,,,,,,***********,,,,,,,,, ,,,,,,,,,,,*********,,,,,,,,,,, .,,,,,,,,,,,*******,,,,,,,,,,,, ,,,,,,,,,*****,,,,,,,,,. ,,,,,,,****,,,,,, .,,,***,,,, ,*,.


_______ __ __ __ / ____(_) /_/ / ____ _/ /_ / / __/ / __/ / / __ `/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/

Thank you for installing GitLab!GitLab was unable to detect a valid hostname for your instance.Please configure a URL for your GitLab instance by setting `external_url`configuration in /etc/gitlab/gitlab.rb file.Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure
For a comprehensive list of configuration options please see the Omnibus GitLab readmehttps://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
Help us improve the installation experience, let us know how we did with a 1 minute survey:https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=15-3
复制代码
  • Config Gitlab

$ gitlab-ctl reconfigure...Notes:Default admin account has been configured with following details:Username: rootPassword: You didn't opt-in to print initial root password to STDOUT.Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
gitlab Reconfigured!
复制代码
  • Visit Gitlab UI:

  • Log into Gitlab

$ cat /etc/gitlab/initial_root_password
复制代码
  • UI


  • Disable sign-up


  • Create user, group and project


  • Update external url

update the external_url param in /etc/gitlab/gitlab.rbsudo gitlab-ctl reconfiguresudo gitlab-ctl restartsudo gitlab-rake cache:clear
复制代码

Git command

  • Clone code


  • Add file and push

$ lsREADME.md$ echo 'print ("This is a test")' > test.py$ git branch -M main$ git add .$ git commit -m "Initial commit"$ git push origin main
复制代码

Gitlab backup and restore

  • Important Git commands:

$ git clone$ git push/pull$ git add$ git commit -m "msg"$ git satus$ git reset --hard HEAD^^ => Revert to last two versions$ git reflog => Get commit ID$ git reset --hard 5ae4b06 => Revert to given commit ID$ git config --global user.name "NAME"$ git config --global user.email xxx@yy.com$ git config --global --list$ git branch$ git checkout -b branch_name$ git checkout branch_name$ git log
复制代码
  • Important Gitlab directories

  • /etc/gitlab => Configure files

  • /run/gitlab => Run pid

  • /opt/gitlab => Install directory

  • /var/opt/gitlab => Data directory

  • /var/log/gitlab => Logs directory

  • Important operations

  • gitlab-rake => Data back and restore

  • gitlab-ctl stop/start/restart => Stop, start and restart Gitlab process

  • gitlab-ctl status => Check Gitlab components status

  • gitlab-ctl tail nginx => Check nginx component logs

  • Backup

$ cd /var/opt/gitlab/backups$ gitlab-ctl stop unicorn sidekiq$ gitlab-rake gitlab:backup:create # Backup current Gitlab data
# Make a copy of following/var/opt/gitlab/nginx/conf/etc/gitlab/gitlab.rb # Gitlab config file/etc/gitlab/gitlab-secrets.json # Key file
$ gitlab-ctl start unicorn sidekiq
复制代码
  • Restore

$ cd /var/opt/gitlab/backups$ gitlab-ctl stop unicorn sidekiq$ gitlab-rake gitlab:backup:restore BACKUP=1667727016_2022_11_06_15.4.3$ gitlab-ctl start unicorn sidekiq
复制代码

Jenkins Install and Config

  • Download and install Jenkins

$ sudo wget -O /etc/yum.repos.d/jenkins.repo \    https://pkg.jenkins.io/redhat-stable/jenkins.repo$ sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key$ sudo yum upgrade# Add required dependencies for the jenkins package$ sudo yum install java-11-openjdk$ sudo yum install jenkins$ sudo systemctl daemon-reload
复制代码
  • Start Jenkins

$ systemctl enable jenkins$ systemctl start jenkins
复制代码
  • Log into Jenkins

  • Logged as admin

  • Integrate with Gitlab

  • Create freestyle test jobs

  • Pipeline job


发布于: 刚刚阅读数: 3
用户头像

9527

关注

还未添加个人签名 2020-04-22 加入

还未添加个人简介

评论

发布
暂无评论
极客时间运维进阶训练营第三周作业_9527_InfoQ写作社区