$ 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
$ sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
将软件包信息提前在本地缓存一份,用来提高搜索安装软件的速度
yum makecache fast
$ sudo yum install docker-ce docker-ce-cli containerd.io
$ sudo systemctl start docker
docker -v
docker images
systemctl enable docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://aeb49y3h.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
docker update redis --restart=always
docker update mysql --restart=always
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 \(本地和docker关联)
-e MYSQL_ROOT_PASSWORD=123456(自己mysql密码) \
-d mysql:5.7(版本)
进入mysql
docker exec -it mysql /bin/bash
配置 config文件
/mydata/mysql/conf/my.conf
[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
collection-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
docker pull redis
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
vim /mydata/redis/conf/redis.conf
填入:
appendonly yes
官网地址
上传到Linux
cd /usr/local
tar -zxvf apache-maven-3.6.3-bin.tar.gz //注意版本号
vi /etc/profile
export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
刷新变量
source /etc/profile
查看是否安装成功
mvn -v
进入setting.xml文件
alimaven
aliyun maven
http://maven.aliyun.com/nexus/content/groups/public/
central
jdk-1.8
true
1.8
1.8
1.8
1.8
下载地址
git config -global user.name "username"
git config -global user.email "[email protected]"
ssh-keygen -t rsa -C "[email protected]:
三次回车
查看密钥
cat ~/.ssh/id_rsa.pub
进入gitee找到公钥页面,将查看到的密钥填入进去
测试是否成功
ssh -T [email protected]
gitee新建仓库建立以下服务:**
商品服务,仓储服务,订单服务,优惠券服务,用户服务
共同点:
1.导入spring web,openfeign
2.每一个服务的包名:
com.xxx.gulimall.xxx(product/order/ware/coupon/member)
3.模块名:
gulimall-product/order/ware/coupon/member
1.进入Gitee搜索人人开源
2.复制renren-fast(后端)和renren-fast-vue(前端)项目的地址
3.在本地git clone 地址,拉取项目到本地
4.在idea中配置renren-fast项目,在总pom中导入renren-fast的model(删除自带的.git文件)
检查版本
node -v
npm config set registry http://registry.npm.taobao.org/
Auto Close Tag,Auto Rename Tag
Chinese(Simplified) Language
ESLint
HTML CSS Support
HTML Snippets
JavaScript(ES6) code snippets
Live Server
open in browser
TSLint(deprecated)
Vetur
将reneren-fast-vue项目导入到VS Code中
在VS Code的终端输入npm install下载依赖组件
启动前端项目
npm run dev
server:
port: xxxxx
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://xxxxx:3306/gulimall_*ms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-discovery
com.alibaba.cloud
spring-cloud-alibaba-dependencies
2.2.0.RELEASE
pom
import
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://39.99.217.20:3306/gulimall_ums?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
cloud:
nacos:
discovery:
server-addr: ******:8848(nacos地址)
application:
name: gulimall-member(微服务名字)
org.springframework.cloud
spring-cloud-starter-openfeign
@FeignClient("gulimall-coupon")
public interface CouponFeign {
@RequestMapping("/coupon/coupon/test")
public R test();
}
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-config
spring.application.name=nacos-config-example
spring.cloud.nacos.config.server-addr=*****:8848
如果配置中心和当前应用的配置文件中都配置了相同的项,优先调用配置中心的配置。
默认:public(保留空间),默认新增的所有配置都在public空间。
默认:public(保留空间),默认新增的所有配置都在public空间。
在nacos-config中配置后,在项目的bootstrap.properties中加入:
spring.cloud.nacos.config.extension-configs[0].data-id=***
spring.cloud.nacos.config.extension-configs[0].group=***
spring.cloud.nacos.config.extension-configs[0].refresh=true
org.springframework.cloud
spring-cloud-starter-gateway
@EnableDiscoveryClient
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class GulimallGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GulimallGatewayApplication.class, args);
}
}
spring.application.name=gulimall-gateway
spring.cloud.nacos.config.server-addr=****:8848
spring.cloud.nacos.config.namespace=****(nacos的config配置中心的命名空间ID)
spring:
cloud:
gateway:
routes:
- id: test_route
uri: https://www.baidu.com
predicates:
- Query=url,baidu
- id: qq_route
uri: https://www.qq.com
predicates:
- Query=url,qq
com.atguigu.gulimall
gulimall-common
0.0.1-SNAPSHOT
spring:
application:
name: renren-fast
cloud:
nacos:
discovery:
server-addr: ****:8848
修改gulimall-gateway\src\main\resources\application.yml将路由转发至renren-fast微服务
访问地址:http://localhost:8001/#/login
统一配置跨域
---->
创建gulimall-gateway\src\main\java\com\atguigu\gulimall\gateway\config\GulimallCorsConfiguration.java
---->
package com.**.gulimall.gateway.config;
import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.cors.CorsConfiguration;import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;import org.springframework.web.cors.reactive.CorsWebFilter;
@Configurationpublic class GulimallCorsConfiguration {
@Bean
public CorsWebFilter corsWebFilter(){
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.setAllowCredentials(true);
source.registerCorsConfiguration("/**",corsConfiguration);
return new CorsWebFilter(source);
}
}
---->禁用默认跨域
renren-fast\src\main\java\io\renren\config\CorsConfig.java
----> 修改gulimall-gateway\src\main\resources\application.yml将路由转发至gulimall-product微服务
spring:
cloud:
gateway:
routes:
- id: product_route
uri: lb://gulimall-product
predicates:
- Path=/api/product/**
filters:
- RewritePath=/api/(?.*),/$\{segment}
----> 添加配置gulimall-product\src\main\resources\bootstrap.properties
spring.application.name=gulimall-product
spring.cloud.nacos.config.server-addr=***:8848
---->product添加注册发现
server:
port: 10000
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://****:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
cloud:
nacos:
discovery:
server-addr: ****:8848
application:
name: gulimall-product
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
---->启动注册功能
// 添加注册发现功能
@EnableDiscoveryClient
@SpringBootApplication
public class GulimallProductApplication {
public static void main(String[] args) {
SpringApplication.run(GulimallProductApplication.class, args);
}
}