尚硅谷谷粒商城之环境搭建

目录

virtualbox的安装(windows)

vagrant的下载(windows)

使用vagrant在virtualbox中安装centos7

配置虚拟机的ip地址

在linux当中安装docker

配置docker阿里云的镜像加速

Docker中安装mysql

Docker中安装redis

配置Maven的镜像和使用jdk1.8版本进行编译

lombok和mybatisx插件的安装:

VSCode安装: 

git安装与配置

项目结构创建和代码提交码云:


virtualbox的安装(windows)

下载地址:Downloads – Oracle VM VirtualBox

 下载windows版本,然后傻瓜式安装就行了,安装成功后,出现如下页面

如果我们要使用centos7的话还要去下载内核,比较麻烦,建议使用vagrant从仓库中拉取镜像

vagrant的下载(windows)

下载官网:Vagrant by HashiCorp

 vagrant安装也是一个傻瓜式的安装

安装完成后:输入vagrant命令出现如下信息则安装成功:

vagrant镜像的地址:Discover Vagrant Boxes - Vagrant Cloud

使用vagrant在virtualbox中安装centos7

①初始化centos7文件

vagrant init centos/7

 

此命令执行完,在对应的C:\WINDOWS\system32下可以找到Vagrantfile文件 ,这是一个centos7的配置文件,vagrant就是根据此文件启动centos7

②从仓库中拉取镜像

vagrant up

③连接虚拟机

vagrant ssh

 默认是使用账户vagrant登录

配置虚拟机的ip地址

如果不固定虚拟机的ip涉及到一个网络地址转换-端口换发

以管理员身份打开cmd,输入ipconfig

 找到图上内容 

使用Notepad++打开位于C:\WINDOWS\system32文件夹下的vagrantfile

  找到第35行: # config.vm.network "private_network", ip: "192.168.33.10"

修改并保存:

重启vagrant

vagrant reload

出现了以下问题:

解决方案: 

解决Failed to open/create the internal network HostInterfaceNetworking-VirtualBox Host-Only Ethernet A_沐小肥的博客-CSDN博客

vagrant up时还出现如下问题:

There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.
 
Host path: /cygdrive/c/Windows/System32/
Guest path: /vagrant
Command: "rsync" "--verbose" "--archive" "--delete" "-z" "--copy-links" "--chmod=ugo=rwX" "--no-perms" "--no-owner" "--no-group" "--rsync-path" "sudo rsync" "-e" "ssh -p 2222 -o LogLevel=FATAL    -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i 'C:/WINDOWS/System32/.vagrant/machines/default/virtualbox/private_key'" "--exclude" ".vagrant/" "/cygdrive/c/Windows/System32/" "vagrant@127.0.0.1:/vagrant"
Error: rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/BBI": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/BBI.LOG1": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/BBI.LOG2": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/DEFAULT": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/DEFAULT.LOG1": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/DEFAULT.LOG2": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SAM": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SAM.LOG1": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SAM.LOG2": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SECURITY": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SECURITY.LOG1": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SECURITY.LOG2": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SOFTWARE": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SOFTWARE.LOG1": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SOFTWARE.LOG2": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SYSTEM": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SYSTEM.LOG1": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/SYSTEM.LOG2": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/systemprofile/AppData/Local/Microsoft/Windows/Notifications/WPNPRMRY.tmp": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/systemprofile/AppData/Local/Microsoft/Windows/WebCache/V01.log": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/systemprofile/AppData/Local/Microsoft/Windows/WebCache/WebCacheV01.dat": Device or resource busy (16)
rsync: [sender] send_files failed to open "/cygdrive/c/Windows/System32/config/systemprofile/AppData/Local/Microsoft/Windows/WebCache/WebCacheV01.jfm": Device or resource busy (16)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender=3.2.3]

 出现问题原因分析:

使用vagrant创建虚拟机时,默认会将vagrantfile同级下的所有文件和目录都复制到创建的centos7的vagrant目录下,导致虚拟机的硬盘爆满

 解决方案:

①打卡C:\WINDOWS\system32中的vagrantfile文件

②在vagrantfile同级目录中创建centos7文件夹

③修改vagrantfile文件中的配置

config.vm.base_mac = "5254004d77d3"
config.vm.synced_folder "./centos7 ", "/vagrant", type: "rsync"

 ④执行vagrant init centos/7 命令

vagrant init centos/7

 ⑤执行vagrant reload命令

vagrant reload

 参考文章:window 10 使用vagrant 在virtualbox中安装centos7_zh452647457的博客-CSDN博客

 再次执行固定虚拟机ip步骤,然后再相互ping,看是否ping通:

在linux当中安装docker

首先什么是docker?例如我们在linux中安装mysql、redis等应用程序需要先下载安装包,再解压安装包、编译和安装非常的麻烦,一旦linux操作系统出现什么问题,我们这些步骤需要重新再来一次。docker是一种虚拟化容器技术,Docker是基于镜像,可以秒级启动各种容器。每一种容器都是一个完整运行的环境,容器之间相互隔离。

docker下载地址: Empowering App Development for Developers | Docker

点击Developers->Docs

点击install on CentOS

里面有安装文档,可以跟着安装文档走

不推荐使用这个下载,下面有使用aliyun的镜像下载,下载更快

①卸载旧版本的docker,如果之前没安装过此步骤可以跳过

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

  

②设置存储仓库

sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

③安装docker引擎

sudo yum install docker-ce docker-ce-cli containerd.io

由于镜像在国外所以安装的速度非常慢,可以使用aliyun的镜像进行一个安装(推荐使用这个安装)

①卸载之前的版本

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

②设置存储库

sudo yum install -y yum-utils device-mapper-persistent-data lvm2 //下载安装所需要的的依赖
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo //修改镜像拉取的地址

③安装dokcer

sudo yum install docker-ce docker-ce-cli containerd.io

④启动docker

sudo systemctl start docker

⑤查看本地已下载的镜像

sudo docker images

⑥配置docker开机自启动

sudo systemctl enbale docker

 重启虚拟机之后查看确实开机自启动了

docker镜像仓库的地址:Docker Hub

docker拉取镜像都是从docker hub中拉取镜像的,这是个国外网站拉取镜像的速度会比较慢。因此,需要配置阿里云的镜像加速

配置docker阿里云的镜像加速

阿里云地址:阿里云-上云就上阿里云

①登录(说明:没有注册过的需要先注册一下)

②点击右上角控制台

③ 点击左上角橙色图标

④在产品与服务中找到容器服务,点击容器服务中的容器镜像服务 

⑤点击镜像工具中的镜像加速器 ,点击centOS

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://k92cvpes.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

⑥执行上述命令

Docker中安装mysql

①在docker hub中搜寻mysql镜像,点击标签(tags中有mysql的各个版本,我们下载5.7的版本)

②下载mysql镜像文件

sudo docker pull  mysql:5.7

③ 创建实例并启动

docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7

参数说明: 

docker首先需要从仓库中拉取镜像,然后以容器的方式运行镜像,容器其实就是一个小的linux。因此,为了访问和配置的方便,需要将端口号和配置文件进行一个映射。

映射都是从后往前映射,前是linux中的,后是容器

-p 3306:3306 :将容器中的mysql端口号映射到linux中的端口号,这样我们可以直接通过linux的端口访问

-v /mydata/mysql/log:/var/log/mysql :将容器中的日志文件映射到linux中,访问/mydata/mysql/log就相当于访问容器中的:/var/log/mysql
-v /mydata/mysql/data:/var/lib/mysql :将容器中的日志文件映射到linux中,访问/mydata/mysql/data相当于访问容器中的/var/lib/mysql
-v /mydata/mysql/conf:/etc/mysql :将容器中的日志文件映射到linux中,访问/mydata/mysql/conf相当于访问/etc/mysql
-e MYSQL_ROOT_PASSWORD=root :初始化root用户的密码
-d mysql:5.7 :以mysql:5.7版本镜像启动

 进入容器的bash界面:

docker exec -it 容器名/id /bin/bash

 

可以看出容器确实就是像一个小linux一样,我们可以使用数据库管理工具进行一个连接测试

④修改mysql的配置文件

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

 ⑤重启docker中的mysql容器

docker update mysql --restart=always

 ⑥docker启动时自动启动mysql容器

docker update mysql --restart=always

Docker中安装redis

①拉取redis镜像

docker pull redis //默认拉取最新的版本

②创建实例并启动

说明:在容器的etc/redis下并没有redis.conf文件,因此,挂载的时候会认为mydata/redis/conf中redis.conf是个文件,所以要先创建mydata/redis/conf中redis.conf文件

mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
 
docker run -p 6379:6379 --name redis \
-v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf

 进入redis的客户端

docker exec -it redis redis-cli

redis默认不持久话,因此重启redis容器时,数据就不在了,进行一个redis的持久化配置

vi mydata/redis/conf/redis.conf
appendonly yes //开启aof持久化

③设置docker启动时启动redis容器

docker update redis --restart=always

配置Maven的镜像和使用jdk1.8版本进行编译

①打开Maven安装路径下的conf文件下的settings.xml

 jar包的存储地址:

<localRepository>D:\MavenRepository</localRepository>

 配置阿里云的镜像仓库:

 <mirrors>
  	<mirror>
		<id>nexus-aliyun</id>
		<mirrorOf>central</mirrorOf>
		<name>Nexus aliyun</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
	</mirror>
 </mirrors>

 配置jdk1.8编译:

<profiles>
    <profile>  
         <id>jdk-1.8</id>  
         <activation>  
             <activeByDefault>true</activeByDefault>  
             <jdk>1.8</jdk>  
          </activation>  
          <properties>  
              <maven.compiler.source>1.8</maven.compiler.source>  
              <maven.compiler.target>1.8</maven.compiler.target>  
              <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
          </properties>  
    </profile>
  </profiles>

 ②在idea中配置Maven

点击file->Settings->Build,Execution,Deployment->Build Tools ->Maven

lombok和mybatisx插件的安装:

file->Settings->Plugins

VSCode安装: 

下载网址:https://code.visualstudio.com/

点击扩展

安装插件:

①Auto Close Tag ②Auto Rename Tag ③Chinese ④ESLint ⑤HTML CSS Support ⑥HTML Snippets ⑦JavaScript(ES6) code snippets ⑧Live Server ⑨Vetur ⑩Vue 2 Snippets ①open in browser

git安装与配置

下载地址:Git

①点击下载

②注册码云

地址:Gitee - 基于 Git 的代码托管和研发协作平台

③配置git,进入git bash(点击鼠标右键)

#配置用户名
git config --global user.name "username"
#配置邮箱
git config --global user.email "邮箱地址"

④配置ssh免密登录

#生成秘钥,连续三次回车
ssh-keygen -t rsa -C "1264331404@qq.com"
#查看秘钥
cat ~/.ssh/id_rsa.pub

⑤登录进入gitee,在设置里面找到SSH KEY将秘钥内容复制进去

⑥测试是否成功 

ssh -T git@gitee.com

 

项目结构创建和代码提交码云:

①新建仓库

②完成一下配置

③点击克隆下载,复制HTTPS的URL 

④idea中下载git插件

⑤设置项目的版本控制,输入复制的URL(父项目的设置)

 

⑥使用spring Initializr创建商品服务、订单服务、会员服务、仓储服务、优惠券服务

        ·微服务项目都需要web依赖,整合springmvc和内嵌servlet

        ·服务与服务之间的调用,设计openfeign依赖

 

 使用的是阿里云的服务路径,spring的在国外会访问不到

https://start.aliyun.com/

​​​​

⑦添加父项目的pom文件,并且在使用Maven管理

<modelVersion>4.0.0</modelVersion>
    <groupId>com.atguigu.gulimall</groupId>
    <artifactId>gulimall</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>gulimall</name>
    <description>聚合服务</description>
    <packaging>pom</packaging>
 
    <modules>
        <module>product</module>
        <module>order</module>
        <module>ware</module>
        <module>member</module>
        <module>coupon</module>
    </modules>

  

⑧ 在父项目中的gitignore文件中忽略不必要的传输文件

**/mvnw
**/mvnw.cmd
**/.mvn
.idea
**/.gitignore
**/target/

⑨ 将项目push到码云仓库中

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值