【无标题】

第四周 周三

上午
1 、复习
1 tomcat 服务器需要 jdk 环境
版本对应
tomcat9== jdk1.8
tomcat10== jdk17
配置系统变量 JAVA_HOME
sed -i '$a export JAVA_HOME=/usr/local/jdk22/' /etc/profile
sed -i '$a export PATH=JAVA_HOME/bin:$PATH' /etc/profile
source /etc/profile
java -version
spring-boot3 ==> jdk17 以上的版本
2 nginx 平滑升级,不停服升级 nginx 服务 1.26.1==> 1.27.0
1 、下载新的 nginx 源码包
2 、解压
3 、配置 (要求 prefix 指定的安装路径和以前的 nginx 安装位置一样)
4 make && make install sbin 出现两个可执行文件 nginx nginx.old
5 、查看旧的 nginx 进程,包含一个 master work 进程的 id
6 kill -USR2 旧的 nginx master 进程 id ,开辟了一个复制的线程
7 kill -WINCH 优雅停用旧的 nginx 的子进程
8 kill -QUIT 优雅退出旧的 nginx master 进程
3 )负载均衡 使用 nginx 管理后端服务器,分配后端服务器压力
1 upstream 服务器组名 {
ip_hash/url_hash/less_conn;
server ip/ 域名:端口号 状态 weight
}
location / {
proxy_pass http:// 服务器组名;
}
http{
server{
upstream server_group_name {
server 10 .0.0.20:80;
server 10 .0.0.30:80;
server 10 .0.0.40:80;
}
location / {
proxy_pass http://server_group_name
}
}
}
/usr/local/nginx/sbin/nginx -s reload
2 、虚拟主机搭建环境准备
将原有的 nginx.conf 文件备份
[root@server ~] # cp /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.bak
[root@server ~] # grep -Ev "#|^$" /usr/local/nginx/conf/nginx.conf
[root@server ~] # grep -Ev "#|^$" /usr/local/nginx/conf/nginx.conf.bak >
/usr/local/nginx/conf/nginx.conf
原则上一个配置文件拥有一个 http 区块,并且只有一个
一个 http 可以有多个 server 区块
一个 server 区块成为一个虚拟主机
一个虚拟主机对应一个项目
一个 server 区块可以有多个 location 区块
每个 location 就是一个 url 链接的匹配规则
3 、基于域名的虚拟主机
[root@server ~] # vim /usr/local/nginx/conf/nginx.conf
server {
listen 80 ;
server_name localhost;
root html; // 目录定位
location / {
index index.html;
}
[root@server ~] # mkdir /baibai // 创建一个页面根目录
[root@server ~] # echo "hello,i am baibai" > /baibai/index.html // 创建一个
首页
[root@server ~] # cat /baibai/index.html
hello,i am baibai
在主配置文件中新创建一个七层模块 server
[root@server ~] # vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65 ;
server {
listen 80 ;
server_name www.baibai.com;
root /baibai; // 目录定位
location / {
index index.html;
}
}
主机解释 ip (本机自行进行域名解析)
[root@server ~] # vim /etc/hosts //windows 路径:
c:/windown/system32/drivers/etc/host/
......
10 .0.0.10 www.baibai.com
[root@server ~] # curl www.baibai.com
hello,i am baibai
一个服务器上同时部署多个项目 , 为了方便维护,可以将 server 模块单独抽离出来创建 conf 文件,然
后在主配置文件中使用 include 添加外部配置,这样让操作更加模块化。
将两个 server 分开到两个配置文件中
[root@server ~] # mkdir /usr/local/nginx/conf.d/ // 创建新的配置文件目录
[root@server ~] # sed -n '11,18p' /usr/local/nginx/conf/nginx.conf
server {
listen 80 ;
server_name www.baibai.com;
root /baibai;
location / {
index index.html;
}
}
[root@server ~] # sed -n '11,18p' /usr/local/nginx/conf/nginx.conf >
/usr/local/nginx/conf.d/baibai.conf // 创建新的配置文件
[root@server ~] # cat /usr/local/nginx/conf.d/baibai.conf
server {
listen 80 ;
server_name www.baibai.com;
root /baibai;
location / {
index index.html;
}
}
[root@server ~] # sed -i '11,18d' /usr/local/nginx/conf/nginx.conf // 原配置
文件中删除该 server
[root@server ~] # vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65 ;
include ../conf.d/*.conf; // 包含(引入)位于上级目录中的 conf.d 文件夹下的
所有以 .conf 为扩展名的配置文件
[root@server ~] # /usr/local/nginx/sbin/nginx -s reload
4 、基于不同 ip 地址的虚拟主机
[root@server ~] # ifconfig ens33:1 10.0.0.11 // 加一张网卡
[root@server ~] # ifconfig
ens33: flags = 4163 <UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10 .0.0.10 netmask 255 .255.255.0 broadcast 10 .0.0.255
ens33:1: flags = 4163 <UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10 .0.0.11 netmask 255 .0.0.0 broadcast 10 .255.255.255
ether 00 :0c:29:b1:2d:68 txqueuelen 1000 (Ethernet)
[root@server ~] # vim /usr/local/nginx/conf/nginx.conf
server {
listen 80 ;
server_name 10 .0.0.10; // 修改为 10.0.0.10
root html; // 目录定位
location / {
index index.html;
}
[root@server ~] # vim /usr/local/nginx/conf.d/baibai.conf
server {
listen 80 ;
server_name 10 .0.0.11; // 修改为 10.0.0.11
root /baibai; // 目录定位
location / {
index index.html;
}
}
[root@server ~] # /usr/local/nginx/sbin/nginx -s reload
5 、基于不同端口的虚拟主机
设置两个 server 都基于相同的 ip 地址
[root@server ~] # vim /usr/local/nginx/conf.d/baibai.conf
server {
listen 80 ;
server_name 10 .0.0.10;
root /baibai;
location / {
index index.html;
}
}
[root@server ~] # /usr/local/nginx/sbin/nginx -s reload
nginx: [warn] conflicting server name "10.0.0.10" on 0 .0.0.0:80, ignored
// 报错,产生冲突
[root@server ~] # vim /usr/local/nginx/conf.d/baibai.conf
server {
listen 8080 ; // 修改端口
server_name 10 .0.0.10;
root /baibai;
location / {
index index.html;
}
}
[root@server ~] # /usr/local/nginx/sbin/nginx -s reload
下午
1 、上线商城系统
上线一个静态的前端系统
安装 npm 添加 vue 模块 使用 vue 创建 vue3 项目,构建静态资源 将静态资源添加到 nginx 项目
在安装 nodejs 之前,需要检查是否安装了 epel
1 )项目创建的环境准备
[root@server ~] # yum list install | grep epel // 检查 epel 环境
[root@server ~] # yum list | grep nodejs // 查询 nodejs 软件包
[root@server ~] # yum -y install nodejs // 安装 nodejs
[root@server ~] # node -v // 查看 nodejs 版本
v16.20.2
[root@server ~] # yum -y install npm // 安装 npm nodejs 的包管理器, rpm 是红帽的包
管理器)
[root@server ~] # npm -v // 查看 npm 版本
8 .19.4
默认 npm 下载文件的链接在国家域外,下载很慢,所以使用淘宝的镜像
[root@server ~] # npm config set registry https://registry.npmmirror.com
// 下载国内的包(而不是下载国外的包)
[root@server ~] # npm install @vue/cli // 使用 nmp 安装 vue
[root@server ~] # vue
-bash : vue: 未找到命令
[root@server ~] # find / -name "vue" // 查找 vue 文件
/root/node_modules/vue
/root/node_modules/.bin/vue
[root@server ~] # ls -l /root/node_modules/.bin/vue // 可执行文件
lrwxrwxrwx. 1 root root 22 7 31 14 :40 /root/node_modules/.bin/vue - >
../@vue/cli/bin/vue.js
[root@server ~] # /root/node_modules/.bin/vue -V // 查看 vue 版本
@vue/cli 5 .0.8
[root@server ~] # ln -s /root/node_modules/.bin/vue /usr/bin/ // 创建软链接
[root@server ~] # vue -V
@vue/cli 5 .0.8
[root@server ~] # vue create eleme_web (空格选择,回车下一步) // 创建名为
eleme_web 的项目
选择 Manually select features 按回车
选择 Router Vuex 按空格后 按回车
最后 一直回车
项目创建完成,按照提示信息进行下一步操作
[root@server ~] # cd eleme_web/
[root@server eleme_web] # npm run serve // 运行服务
浏览器访问: 10.0.0.10:8080
[root@server eleme_web] # nohup npm run serve& // 将服务放到后台执行
[1] 3024
[root@server eleme_web] # nohup: 忽略输入并把输出追加到 "nohup.out"
[root@server eleme_web] # fg // 将进程杀死
nohup npm run serve
^C
[root@server eleme_web] # fg
-bash : fg: 当前 : 无此任务
3 )配置 samba linux 系统与 windows 系统磁盘映射实现文件共享)
1 、安装 samab
[root@server eleme_web] # yum -y install samba
2 、编辑配置文件
[root@server eleme_web] # vim /etc/samba/smb.conf
[eleme_web]
comment = eleme_web
path = /root/eleme_web // 指定了共享的实际路径
guest ok = no // 不允许访客(未经过认证的用户)访问这个共享
writable = yes // 允许对这个共享进行写入操作
3 、创建用户
[root@server eleme_web] # useradd vueediter
[root@server eleme_web] # smbpasswd -a vueediter
New SMB password:123 (没有回显)
Retype new SMB password:123 (没有回显)
Added user vueediter.
4 、为该用户在文件夹中添加读写权限
[root@server eleme_web] # setfacl -m u:vueediter:rwx /root/eleme_web/
5 、启动服务
[root@server eleme_web] # systemctl start nmb
[root@server eleme_web] # systemctl start smb
windows 测试:点击此电脑 ----- 计算机 ------- 映射网络驱动器
4 )创建 nfs 服务环境
[root@server eleme_web] # ls
babel.config.js node_modules package.json public src
jsconfig.json nohup.out package-lock.json README.md vue.config.js
public // 存放静态资源
[root@server eleme_web] # ls -l public/
总用量 12
-rw-r--r-- . 1 root root 4286 7 31 15 :04 favicon.ico
-rw-r--r-- . 1 root root 611 7 31 15 :04 index.html
[root@server eleme_web] # mkdir public/img
[root@server eleme_web] # mkdir public/video
[root@server eleme_web] # mkdir public/music
[root@server eleme_web] # tree public/
public/
├── favicon.ico
├── img
├── index.html
├── music
└── video
3 directories, 2 files
5 )部署一台 nfs 服务器
[root@elemestatic ~] # yum -y install nfs-utils.x86_64 rpcbind.x86_64 // 下载
nfs 软件与 rpcbind 依赖软件
[root@elemestatic ~] # vim /etc/exports // 编写暴露文件
/static/img/ *(rw,sync) // 共享 /static/img/ 目录 所有人可以访问 拥有读写
权限和同步功能
[root@elemestatic ~] # mkdir -p /static/img // 创建共享目录
[root@elemestatic ~] # systemctl start nfs // 启动 nfs 服务
[root@elemestatic ~] # systemctl start rpcbind // 启动 rpcbind 服务
[root@elemestatic ~] # netstat -lntup | grep rpc //rpc 111 端口
[root@server eleme_web] # yum -y install nfs-utils.x86_64 //nfs 客户端也要下载
nfs 软件
[root@server eleme_web] # mount -t nfs 10.0.0.50:/static/img/ ./public/img/
// nfs 服务器共享的目录挂载到 /root/eleme_web/public/img/
将图片拖拽到 nfs 服务器主机的共享目录中
[root@elemestatic img] # ls
月亮 .jpg
[root@server img] # ls //nfs 客户端中可以查看图片
月亮 .jpg
6 )修改 vue 页面
[root@server eleme_web] # cd src/views/
[root@server views] # ls
AboutView.vue HomeView.vue
[root@server views] # vim HomeView.vue
<img alt = "Vue logo" src = "img/ 月亮 .jpg" >
  • 10
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值