【Linux】配置服务和服务器

服务

 【安装 Nginx 服务】

Nginx服务装在另一台linux上,不要和tomcat装在同一台机子上

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

1、安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make

2、创建运行用户
useradd -M -s /sbin/nologin nginx

3、编译安装
cd /opt
tar zxvf nginx-1.22.0.tar.gz -C /opt/

cd nginx-1.22.0/
./configure --with-stream
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module

make -j 4 && make install

4、优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

5、添加 Nginx 系统服务
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target


chmod 777 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
——
cd /usr/local/nginx/conf/
#先备份nginx.conf文件
cp nginx.conf nginx.conf.20230811.bak

vim nginx.conf
在--28行-- #tcp_nopush下插入
upstream ky30 {
    server 192.168.220.112:8080 weight=1;
    server 192.168.220.112:8081 weight=1;
    server 192.168.220.114:8080 weight=2;
}

然后到--47行--#access_log下插入
location ~ .*\.jsp$ {
    proxy_pass http://ky30;
    proxy_set_header HOST $host;
    #将真实的IP地址传给后端服务器
    proxy_set_header X-Real-IP $remote_addr;
    #记录代理服务器地址
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*\.(gif|jpg|png)$ {
    root html;
    index index.html index.htm;
}
检查配置文件并重启
nginx -t

systemctl restart nginx.service

服务器

【 配置NFS共享服务器】

[root@test4 ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.67.14  netmask 255.255.255.0  broadcast 192.168.67.255
        ether 00:0c:29:40:11:62  txqueuelen 1000  (Ethernet)
        RX packets 4376  bytes 324286 (316.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1166  bytes 90636 (88.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

#查看路由表,看网关
[root@test4 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.67.2    0.0.0.0         UG    100    0        0 ens33
192.168.67.0    0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
#查看nfs是否安装
[root@test4 ~]# rpm -q nfs-utils 
nfs-utils-1.3.0-0.48.el7.x86_64
#查看rpcbind是否安装
[root@test4 ~]# rpm -q rpcbind 
rpcbind-0.2.0-42.el7.x86_64
#重装一下
[root@test4 ~]# yum -y install nfs-utils
[root@test4 ~]# rpm -q nfs-utils 
nfs-utils-1.3.0-0.68.el7.2.x86_64

设置共享目录,并发布
#创建web1和web2目录
[root@test4 ~]# mkdir /opt/web1 /opt/web2
[root@test4 ~]# ls /opt
rh  web1  web2

vim /etc/exports
#注意,ip与授权的"()"之间不能有空格
  1 /opt/web1 192.168.67.0/24(rw,sync)
  2 /opt/web2 192.168.67.0/24(rw,sync)
#保存退出,重启配置文件
[root@test4 ~]# systemctl restart nfs
[root@test4 ~]# systemctl restart rpcbind

#查看共享目录
[root@test4 ~]# showmount -e
Export list for test4:
/opt/web2 192.168.67.0/24
/opt/web1 192.168.67.0/24

#发布共享目录
[root@test4 ~]# exportfs -vr
exporting 192.168.67.0/24:/opt/web2
exporting 192.168.67.0/24:/opt/web1
制作测试网页
[root@test4 ~]# vim /opt/web1/index.html
<html>
<title>This is Web1</title>
<body><h1>Is Web1</h1></body>
</html>

[root@test4 ~]# vim /opt/web1/index.html
<html>
<title>This is Web1</title>
<body><h1>Is Web1</h1></body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值