7.31 虚拟主机与vue项目、samba磁盘映射、nfs共享

(1)tomcat服务器需要jdk环境

配置系统变量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
(2)创建vue项目
 [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测试:点击此电脑-----计算机-------映射网络驱动器

输入映射路径 \ \10.0.0.10\eleme_web点击完成,输入用户名与密码点击确认

映射成功

(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">

  • 21
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值