极客时间运维进阶训练营第三周作业
- 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_64
100%[===========================================================================================================================>] 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 version
Docker 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 pull
WARN[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 -d
WARN[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 ls
NETWORK ID NAME DRIVER SCOPE
8a2813e542f0 202211-06_backend bridge local
3e9ed32531de 202211-06_front bridge local
61c7149b00ec bridge bridge local
d7ed9cc4b808 host host local
1f8da3a09945 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 forever
10: 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 forever
12: 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-server
PING tomcat-server (172.19.0.3): 56 data bytes
64 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 loss
round-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 -lh
total 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.rpm
warning: gitlab-ce-15.3.5-ce.0.amazon2.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
It 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 readme
https://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: root
Password: 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.rb
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo gitlab-rake cache:clear
Git command
Clone code
Add file and push
$ ls
README.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
版权声明: 本文为 InfoQ 作者【9527】的原创文章。
原文链接:【http://xie.infoq.cn/article/da9a544415116a43b9a89f086】。文章转载请联系作者。
9527
还未添加个人签名 2020-04-22 加入
还未添加个人简介
评论