人的知识就好比一个圆圈,圆圈里面是已知的,圆圈外面是未知的。你知道得越多,圆圈也就越大,你不知道的也就越多。

0%

悠悠商城--环境搭建

network

1
docker network create op_net

mysql

linux:

1
2
3
4
5
6
7
sudo docker run -d \
--network op_net \
--hostname op_mysql \
--name mysql \
-e MYSQL_ROOT_PASSWORD=admin123 \
-p 3306:3306 \
mysql:8.0.18

windows:

1
2
3
4
5
6
7
docker run -d `
--network op_net `
--hostname mysql `
--name mysql `
-e MYSQL_ROOT_PASSWORD=admin123 `
-p 3306:3306 `
mysql

rabbitmq

linux:

1
2
3
4
5
6
7
sudo docker run -d \
--network op_net \
--hostname op_rabbitmq \
--name rabbitmq \
--restart=always \
-p 5672:5672 -p 15672:15672 \
rabbitmq:3-management

windows:

1
2
3
4
5
6
7
docker run -d `
--network op_net `
--hostname op_rabbitmq `
--name rabbitmq `
--restart=always `
-p 5672:5672 -p 15672:15672 `
rabbitmq:3-management

redis

linux:

1
2
3
4
5
6
7
8
9
sudo docker run -d \
--network op_net \
--hostname op_redis \
--name redis \
--restart=always \
--privileged=true \
-v /srv/redis/conf:/usr/local/etc/redis/redis.conf \
-p 6379:6379 \
redis redis-server /usr/local/etc/redis/redis.conf

windows:

1
2
3
4
5
6
7
8
9
docker run -d `
--network op_net `
--hostname op_redis `
--name redis `
--restart=always `
--privileged=true `
-v /d/Development/Workspace/Hyper-V/volumes/redis/conf:/usr/local/etc/redis/redis.conf `
-p 6379:6379 `
redis redis-server /usr/local/etc/redis/redis.conf

访问redis

linux:
sudo docker run -it --network op_net --rm redis redis-cli -h redis
windows:
docker run -it --network op_net --rm redis redis-cli -h redis

opnezipkin

linux:

1
2
3
4
5
6
7
8
sudo docker run -d \
--network op_net \
--hostname op_zipkin \
--name zipkin \
--restart=always \
-e RABBIT_ADDRESSES=rabbitmq:5672 \
-p 9411:9411 \
openzipkin/zipkin

windows:

1
2
3
4
5
6
7
8
docker run -d `
--network op_net `
--hostname op_zipkin `
--name zipkin `
--restart=always `
-e RABBIT_ADDRESSES=rabbitmq:5672 `
-p 9411:9411 `
openzipkin/zipkin

zookeeper

linux:

1
2
3
4
5
6
7
8
9
sudo docker run -d \
--network op_net \
--hostname op_zookeeper \
--name zookeeper \
--restart=always \
-p 2181:2181 \
-v /srv/zookeeper/conf:/conf \
-e ZOO_LOG4J_PROP="INFO,ROLLINGFILE" \
zookeeper

windows:

1
2
3
4
5
6
7
8
9
docker run -d `
--network op_net `
--hostname op_zookeeper `
--name zookeeper `
--restart=always `
-p 2181:2181 `
-v /d/Development/Workspace/Hyper-V/volumes/zookeeper/conf:/conf `
-e ZOO_LOG4J_PROP="INFO,ROLLINGFILE" `
zookeeper

访问zookeeper

linux:
sudo docker run -it --network op_net --rm zookeeper zkCli.sh -server zookeeper
windows:
docker run -it --network op_net --rm zookeeper zkCli.sh -server zookeeper

kafka

linux:

1
2
3
4
5
6
7
8
9
10
11
sudo docker run -d \
--network op_net \
--hostname op_kafka \
--name kafka \
--restart=always \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.107:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
-p 9092:9092 \
wurstmeister/kafka

windows:

1
2
3
4
5
6
7
8
9
10
11
docker run -d `
--network op_net `
--hostname op_kafka `
--name kafka `
--restart=always `
-e KAFKA_BROKER_ID=0 `
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 `
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.107:9092 `
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 `
-p 9092:9092 `
wurstmeister/kafka

创建主题

  1. 进入容器:sudo docker exec -it kafka /bin/bash
  2. 创建主题:/opt/kafka/bin/kafka-topics.sh --create --replication-factor 1 --partitions 1 --zookeeper zookeeper:2181 --topic yoyo-mall-log
  3. 查询主题:/opt/kafka/bin/kafka-topics.sh --list --zookeeper zookeeper:2181

配置logstash

  1. 执行sudo docker exec -it elk /bin/bash进入容器
  2. 打开文件:vi /etc/logstash/conf.d/02-beats-input.conf
  3. 修改后配置:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    input {
    tcp {
    port => 5044
    codec => json_lines
    }

    kafka {
    bootstrap_servers => "192.168.0.107:9092"
    topics => ["yoyo-mall-log"]
    }
    }

    output{
    elasticsearch {
    hosts => ["localhost:9200"]
    index => "yoyo-mall-log"
    }
    }

kafka-manager

1
2
3
4
5
sudo docker run -d \
-e ZK_HOSTS="192.168.0.107:2181" \
-p 9000:9000 \
hlebalbau/kafka-manager:stable \
-Dpidfile.path=/dev/null

elk

linux:

1
2
3
4
5
6
7
sudo docker run -d \
--network op_net \
--hostname op_elk \
--name elk \
--restart=always \
-p 5601:5601 -p 9200:9200 -p 5044:5044 \
sebp/elk:670

windows:

1
2
3
4
5
6
7
docker run -d `
--network op_net `
--hostname op_elk `
--name elk `
--restart=always `
-p 5601:5601 -p 9200:9200 -p 5044:5044 `
sebp/elk:670

修改配置

linux下运行elk镜像,要求vm.max_map_count至少为262144,否则启动会报错:![step42](/images/VMWare install/step42.png)。
在“/etc/sysctl.conf”文件末行添加:vm.max_map_count=262144,然后执行sudo /sbin/sysctl -p使配置立即生效。

配置logstash

  1. 执行sudo docker exec -it elk /bin/bash进入容器
  2. 打开文件:vi /etc/logstash/conf.d/02-beats-input.conf
  3. 修改配置:
    原配置:
    1
    2
    3
    4
    5
    6
    7
    8
    input {
    beats {
    port => 5044
    ssl => true
    ssl_certificate => "/etc/pki/tls/certs/logstash-beats.crt"
    ssl_key => "/etc/pki/tls/private/logstash-beats.key"
    }
    }
    修改后配置:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    input {
    tcp {
    port => 5044
    codec => json_lines
    }
    }

    output{
    elasticsearch {
    hosts => ["localhost:9200"]
    }
    }
  4. 重启容器:`sudo docker restart elk

nexus

linux:

1
2
3
4
5
6
7
8
sudo docker run -d \
--hostname op_nexus \
--name nexus \
--restart=always \
--privileged=true \
-v /srv/nexus-data:/nexus-data \
-p 18081:8081 \
sonatype/nexus3

windows:

1
2
3
4
5
6
7
8
docker run -d `
--hostname op_nexus `
--name nexus `
--restart=always `
--privileged=true `
-v /d/Development\Workspace\Hyper-V\volumes\nexus-data:/nexus-data `
-p 18081:8081 `
sonatype/nexus3

更改权限

如果启动时报错:
![step30](/images/VMWare install/step30.png)
执行命令:sudo chmod 777 /srv/nexus-data

gitlab

参考:https://docs.gitlab.com/omnibus/docker/

linux:

1
2
3
4
5
6
7
8
9
10
sudo docker run --detach \
--hostname op_gitlab \
--name gitlab \
--restart always \
--privileged=true \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
--publish 10443:443 --publish 10080:10080 --publish 10022:22 \
gitlab/gitlab-ce:latest

windows:

1
2
3
4
5
6
7
8
9
10
docker run --detach `
--hostname op_gitlab `
--name gitlab `
--restart always `
--privileged=true `
--volume /d/Development\Workspace\Hyper-V\volumes\gitlab\config:/etc/gitlab `
--volume /d/Development\Workspace\Hyper-V\volumes\gitlab\logs:/var/log/gitlab `
--volume /d/Development\Workspace\Hyper-V\volumes\gitlab\data:/var/opt/gitlab `
--publish 10443:443 --publish 10080:10080 --publish 10022:22 `
gitlab/gitlab-ce:latest

配置ip&端口

sudo vi /srv/gitlab/config/gitlab.rb
修改以下三行配置:

1
2
3
external_url 'http://172.16.78.80:10080'
gitlab_rails['gitlab_ssh_host'] = 'http://172.16.78.80'
gitlab_rails['gitlab_shell_ssh_port'] = 10022

其中,172.16.78.80为宿主机的ip地址,可以通过ip addr查看;1008010022则分别为8022映射到宿主机的端口。
之后重启:sudo docker restart gitlab

创建ssh key

参考:https://docs.gitlab.com/ee/ssh/README.html#adding-an-ssh-key-to-your-gitlab-account
gitlab启动之后,会提示“You won’t be able to pull or push project code via SSH until you add an SSH key to your profile”。
需要配置ssh key:

  1. 检查是否已有key:cat ~/.ssh/id_rsa.pub
  2. 如果没有,则创建:ssh-keygen -o -t rsa -b 4096 -C "email@example.com",不断回车;
  3. 复制创建的ssh key,然后添加到gitlab中;
    ![step29](/images/VMWare install/step29.png)
  4. 检查:ssh -T git@172.16.78.80(需要前完成步骤4,且之后还提示需要密码,解决办法待研究:https://www.jianshu.com/p/e946acf9f26e)。

安装ssh server

1
2
sudo apt-get install openssh-server
ssh localhost

配置jenkins

linux:

1
2
3
4
5
6
7
8
9
sudo docker run -d \
--hostname op_jenkins \
--name jenkins \
--privileged=true \
-v /srv/jenkins_home:/var/jenkins_home \
-p 18080:8080 -p 50000:50000 \
-p 8761:8761 -p 8180:8180 -p 8181:8181 -p 8182:8182 -p 8183:8183 -p 8184:8184 -p 8185:8185 -p 8186:8186 \
-p 8101:8101 -p 8102:8102 -p 8103:8103 -p 8104:8104 -p 8105:8105 -p 8106:8106 \
jenkins/jenkins

windows:

1
2
3
4
5
6
7
8
9
docker run -d `
--hostname op_jenkins `
--name jenkins `
--privileged=true `
-v /d/Development\Workspace\Hyper-V\volumes\jenkins_home:/var/jenkins_home `
-p 18080:8080 -p 50000:50000 `
-p 8761:8761 -p 8180:8180 -p 8181:8181 -p 8182:8182 -p 8183:8183 -p 8184:8184 -p 8185:8185 -p 8186:8186 `
-p 8101:8101 -p 8102:8102 -p 8103:8103 -p 8104:8104 -p 8105:8105 -p 8106:8106 `
jenkins/jenkins

上面8761及之后的端口都是jenkins中部署的项目所用到的端口。

解锁

第一次进入jenkins,会提示:
![step32](/images/VMWare install/step32.png)
执行命令:sudo docker exec -it jenkins /bin/bash进入docker容器,再执行命令cat /var/jenkins_home/secrets/initialAdminPassword查看密码,然后将密码拷贝到界面继续。

安装插件

选择“安装推荐的插件”

配置jdk/git/maven

进入管理界面:
![step33](/images/VMWare install/step33.png)
![step34](/images/VMWare install/step34.png)
ps: JAVA_HOME地址可以通过命令echo $JAVA_HOME查询
![step35](/images/VMWare install/step35.png)
![step36](/images/VMWare install/step36.png)

  1. 安装maven插件
    ![step37](/images/VMWare install/step37.png)
    ![step38](/images/VMWare install/step38.png)

  2. 新建任务
    ![step39](/images/VMWare install/step39.png)
    ![step40](/images/VMWare install/step40.png)
    ![step41](/images/VMWare install/step41.png)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
SERVER_NAME=yoyo-mall-basic-registry-server
JAR_NAME=yoyo-mall-basic-registry-server-1.0-SNAPSHOT
JAR_PATH=/var/jenkins_home/workspace/yoyo-mall-basic-registry-server/target/
JAR_WORK_PATH=/var/jenkins_home/workspace/yoyo-mall-basic-registry-server/target/

PID=`ps -ef | grep "$SERVER_NAME" | awk '{print $2}'`
for id in $PID
do
kill -9 $id
echo "killed $id"
done

cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH
cd $JAR_WORK_PATH
chmod 755 $JAR_NAME.jar


BUILD_ID=dontKillMe nohup java -jar $JAR_NAME.jar &

安装VMWare

  1. 下载
    https://my.vmware.com/cn/web/vmware/info/slug/desktop_end_user_computing/vmware_workstation_pro/15_0
    需要登录,没有账号需要注册
  2. 输入许可证
  • YG5H2-ANZ0H-M8ERY-TXZZZ-YKRV8
  • UG5J2-0ME12-M89WY-NPWXX-WQH88
  • UA5DR-2ZD4H-089FY-6YQ5T-YPRX6
  • GA590-86Y05-4806Y-X4PEE-ZV8E0
  • ZF582-0NW5N-H8D2P-0XZEE-Z22VA
  • YA18K-0WY8P-H85DY-L4NZG-X7RAD
  1. 安装

创建虚拟机

  1. 下载
    https://ubuntu.com/download/desktop
    按需选择桌面版或服务器版
  2. 创建虚拟机(Ubuntu Desktop)
    ![step01](/images/VMWare install/step01.png)
    ![step02](/images/VMWare install/step02.png)
    ![step03](/images/VMWare install/step03.png)
    ![step04](/images/VMWare install/step04.png)
    ![step05](/images/VMWare install/step05.png)
    ![step06](/images/VMWare install/step06.png)
    ![step07](/images/VMWare install/step07.png)
    ![step08](/images/VMWare install/step08.png)
    nat模式:无需额外配置,虚拟机即可联网
    ![step09](/images/VMWare install/step09.png)
    ![step10](/images/VMWare install/step10.png)
    ![step11](/images/VMWare install/step11.png)
    ![step12](/images/VMWare install/step12.png)
    ![step13](/images/VMWare install/step13.png)
    ![step14](/images/VMWare install/step14.png)
    ![step15](/images/VMWare install/step15.png)
    ![step16](/images/VMWare install/step16.png)

桥接模式

![step25](/images/VMWare install/step25.png)
![step26](/images/VMWare install/step26.png)
![step27](/images/VMWare install/step27.png)
桥接到的地址选择能联网的网卡:
![step27(2)](/images/VMWare install/step27(2).png)
![step28](/images/VMWare install/step28.png)

启动虚拟机

如果提示:
![step01](/images/VMWare install/step01.png)
去控制面板中停掉Hyper-V
![step02](/images/VMWare install/step02.png)

![step17](/images/VMWare install/step17.png)
![step18](/images/VMWare install/step18.png)
![step19](/images/VMWare install/step19.png)
![step20](/images/VMWare install/step20.png)
![step21](/images/VMWare install/step21.png)
![step22](/images/VMWare install/step22.png)
![step23](/images/VMWare install/step23.png)
![step24](/images/VMWare install/step24.png)

更新&升级

1
2
sudo apt-get update
sudo apt-get upgrade

安装Tools

sudo apt-get install open-vm-tools-desktop
安装之后需重启生效

安装Docker

参考:https://docs.docker.com/install/linux/docker-ce/ubuntu/

  1. sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  2. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  3. sudo apt-key fingerprint 0EBFCD88
  4. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  5. sudo apt-get update
  6. sudo apt-get install docker-ce docker-ce-cli containerd.io
  7. sudo docker run hello-world
小礼物走一走,来 Github 关注我