Linux系统——web服务拓展练习

目录

一、实验环境搭建

1. Centos 7-5——Client

2. Centos 7-1——网关服务器

3. Centos 7-2——Web1

4. Centos 7-3——Web2

5. Centos 7-4——Nginx

二、在Nginx服务器上搭建LNMP服务,并且能够对外提供Discuz论坛服务;在Web1、Web2服务器上搭建Tomcat 服务。

1.Nginx服务器——编译安装Nginx

2.Nginx服务器——搭建PHP

3.Nginx服务器——编译安装搭建Mysql

4.配置数据库

5.配置PHP测试页

6.安装论坛

7.Web1——搭建Tomcat

7.1安装Oracle JDK

7.2安装Tomcat

8.Web2——搭建Tomcat

8.1安装Oracle JDK

8.2安装Tomcat

三、为nginx服务配置虚拟主机,新增两个域名 www.kgc.com 和 www.benet.com,使用http://www.kgc.com/index.php可访问上一题的Discuz论坛页面。使用http://www.benet.com则访问/var/www/html目录中的index.html文件的内容,内容自定义。

1.Nginx服务器配置

2.客户端配置

3.测试 

四、对基于www.benet.com域名的虚拟机主机的nginx服务调优:隐藏nginx版本号,缓存静态图片网页时间为1天,设置防盗链功能。

1.Nginx配置

2.测试

五、网关服务器搭建NFS服务,提供的文件系统使用LVM类型,共享目录名称为/mnt/nfs;要求根据日期对Discuz论坛服务的访问日志进行日志分割,要求每天生成一份日志文件,保存到NFS服务共享的目录内。

1.网关服务器配置——搭建NFS服务

2.Nginx服务器——共享目录 

3.日志分割

六、要求配置location匹配请求地址http://www.kgc.com/test/XXXX,使用户访问该路径下的文件时返回/var/share/nginx/html/目录下的文件内容。

要求使用rewrite将使用域名www.benet.com 请求以 .php 结尾的访问都跳转到域名www.kgc.com上,而且后面的参数保持不变,比如访问http://www.benet.com/bbs/index.php跳转到http://www.kgc.com/bbs/index.php。

1.Nginx服务器配置

2.测试

七、在Nginx服务器上对基于www.benet.com域名的虚拟机主机设置动静分离由nginx提供静态页面服务,将对 .jsp文件的动态页面请求转发到Tomcat 服务器处理,并实现负载均衡

1.Nginx服务配置

2.Tomcat1服务器配置

3.Tomcat2服务器配置

4.测试

八、在网关服务器上设置SNAT/DNAT,使client使用网关服务器的ens36接口的IP地址访问也可实现上一题的效果。

1.代理服务器配置 

2.测试


 服务器IP地址规划:client:12.0.0.12/24,网关服务器:ens36:12.0.0.1/24、ens33:192.168.241.11/24,Web1:192.168.241.22/24,Web2:192.168.241.23/24,Nginx:192.168.241.24/24。

一、实验环境搭建

Centos7-5作为Client(12.0.0.12/24);Centos7-1作为网关服务器(搭配两块网卡ens33 192.168.241.11/24,ens36 12.0.0.1/24);Centos7-2作为Web1(192.168.241.22/24 提供web1服务);Centos7-3作为Web2(192.168.241.23/24 提供web2服务);Centos7-4作为Nginx服务器(192.168.241.24/24)

1. Centos 7-5——Client

2. Centos 7-1——网关服务器

[root@localhost ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens33

[root@localhost ~]#cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens36
[root@localhost ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens36

[root@localhost ~]#systemctl restart network
[root@localhost ~]#ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.241.11  netmask 255.255.255.0  broadcast 192.168.241.255inet6 fe80::de6f:32c8:5a64:a6b2  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:51:4b:b5  txqueuelen 1000  (Ethernet)RX packets 2457  bytes 231114 (225.6 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 1289  bytes 162490 (158.6 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 12.0.0.1  netmask 255.255.255.0  broadcast 12.0.0.255inet6 fe80::8cb:b13b:40ac:6df1  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:51:4b:bf  txqueuelen 1000  (Ethernet)RX packets 557  bytes 36406 (35.5 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 345  bytes 60396 (58.9 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 111  bytes 9742 (9.5 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 111  bytes 9742 (9.5 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:53:c1:45  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

3. Centos 7-2——Web1

[root@node2 ~]#ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.241.22  netmask 255.255.255.0  broadcast 192.168.241.255inet6 fe80::d9cd:6857:3bdc:7454  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:3e:a0:08  txqueuelen 1000  (Ethernet)RX packets 1702  bytes 169840 (165.8 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 674  bytes 72150 (70.4 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 64  bytes 5568 (5.4 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 64  bytes 5568 (5.4 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:fe:22:f2  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

4. Centos 7-3——Web2

[root@node3 ~]#ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.241.23  netmask 255.255.255.0  broadcast 192.168.241.255inet6 fe80::f11e:5019:be57:47b8  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:6b:71:15  txqueuelen 1000  (Ethernet)RX packets 1174  bytes 121065 (118.2 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 246  bytes 25828 (25.2 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 36  bytes 4212 (4.1 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 36  bytes 4212 (4.1 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:9d:e9:ac  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

5. Centos 7-4——Nginx

[root@G ~]#ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.241.24  netmask 255.255.255.0  broadcast 192.168.241.255inet6 fe80::871f:7f65:7279:5914  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:8c:91:84  txqueuelen 1000  (Ethernet)RX packets 1407  bytes 140138 (136.8 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 481  bytes 45344 (44.2 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 64  bytes 5248 (5.1 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 64  bytes 5248 (5.1 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:d2:18:b8  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

二、在Nginx服务器上搭建LNMP服务,并且能够对外提供Discuz论坛服务;在Web1、Web2服务器上搭建Tomcat 服务。

Nginx搭建LNMP架构

1.Nginx服务器——编译安装Nginx

[root@G ~]#yum -y install pcre-devel zlib-devel gcc gcc-c++ make
#安装依赖环境
[root@G ~]#useradd -M -s /sbin/nologin nginx
#创建程序管理用户Nginx
[root@G opt]#cd /opt
[root@G opt]#wget http://nginx.org/download/nginx-1.18.0.tar.gz
#下载压缩文件
[root@G opt]#ls
nginx-1.18.0.tar.gz
[root@G opt]#tar xf nginx-1.18.0.tar.gz 
[root@G opt]#cd nginx-1.18.0/
[root@G nginx-1.18.0]#./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module
[root@G nginx-1.18.0]#make -j2
[root@G nginx-1.18.0]#make install
[root@G nginx-1.18.0]#ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@G nginx-1.18.0]#vim /lib/systemd/system/nginx.service
[root@G nginx-1.18.0]#cat /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 -1 $MAINPID
ExecStop=/bin/kill -3 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@G nginx-1.18.0]#systemctl daemon-reload
[root@G nginx-1.18.0]#systemctl enable --now nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@G nginx-1.18.0]#systemctl status nginx.service 
● nginx.service - nginxLoaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)Active: active (running) since 六 2024-03-09 12:37:29 CST; 4s agoProcess: 39778 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)Main PID: 39779 (nginx)CGroup: /system.slice/nginx.service├─39779 nginx: master process /usr/local/nginx/sbin/nginx└─39780 nginx: worker process3月 09 12:37:29 G.D systemd[1]: Starting nginx...
3月 09 12:37:29 G.D systemd[1]: Started nginx.
[root@G nginx-1.18.0]#chown -R nginx:nginx /usr/local/nginx/

2.Nginx服务器——搭建PHP

[root@G ~]#cd /opt
[root@G ~]#yum -y install gd \
> libjpeg libjpeg-devel \
> libpng libpng-devel \
> freetype freetype-devel \
> libxml2 libxml2-devel \
> zlib zlib-devel \
> curl curl-devel \
> openssl openssl-devel
[root@G opt]#rz -E
rz waiting to receive.
[root@G opt]#ls
nginx-1.18.0  nginx-1.18.0.tar.gz  php-7.1.10.tar.bz2
[root@G opt]#tar xf php-7.1.10.tar.bz2 
[root@G opt]#cd php-7.1.10/
[root@G php-7.1.10]#./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
[root@G php-7.1.10]#make -j2
[root@G php-7.1.10]#make install
[root@G php-7.1.10]#ln -s /usr/local/php/bin/* /usr/local/bin/
[root@G php-7.1.10]#ln -s /usr/local/php/sbin/* /usr/local/sbin/
#优化路径#调整进程服务配置文件
[root@G php-7.1.10]#cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
[root@G php-7.1.10]#vim /usr/local/php/lib/php.ini-1170G-  mysqli.default_socket =  /usr/local/mysql/mysql.sock-939G-   date.timezone = Asia/Shangha[root@G php-7.1.10]#sed -n '939p;1170p' /usr/local/php/lib/php.ini 
date.timezone = Asia/Shanghai
mysqli.default_socket =  /usr/local/mysql/mysql.sock
[root@G php-7.1.10]#cd /usr/local/php/etc/
[root@G etc]#cp  php-fpm.conf.default php-fpm.conf
[root@G etc]#vim php-fpm.conf
[root@G etc]#sed -n '17p' php-fpm.conf
pid = run/php-fpm.pid#调整扩展配置文件
[root@G etc]#cd /usr/local/php/etc/php-fpm.d/
[root@G php-fpm.d]#cp www.conf.default www.conf
[root@G php-fpm.d]#ls
www.conf  www.conf.default#启动PHP
[root@G php-fpm.d]#cp /opt/php-7.1.10/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
[root@G php-fpm.d]#systemctl restart php-fpm.service 
[root@G php-fpm.d]#systemctl status php-fpm.service 
● php-fpm.service - The PHP FastCGI Process ManagerLoaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)Active: active (running) since 六 2024-03-09 13:01:36 CST; 5s agoMain PID: 47397 (php-fpm)CGroup: /system.slice/php-fpm.service├─47397 php-fpm: master process (/usr/local/php/etc/php-fpm.con...├─47400 php-fpm: pool www└─47401 php-fpm: pool www3月 09 13:01:36 G.D systemd[1]: Started The PHP FastCGI Process Manager.
3月 09 13:01:36 G.D systemd[1]: Starting The PHP FastCGI Process Manager...
Hint: Some lines were ellipsized, use -l to show in full.

3.Nginx服务器——编译安装搭建Mysql

[root@G opt]#yum -y install \
> ncurses \
> ncurses-devel \
> bison \
> cmake
#环境依赖包
[root@G opt]#yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel   ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
#安装依赖环境
[root@G opt]#useradd -M -s /sbin/nologin  mysql
#创建运行用户
[root@G opt]#rz -E
rz waiting to receive.
[root@G opt]#ls
mysql-boost-5.7.20.tar.gz  nginx-1.18.0.tar.gz  php-7.1.10.tar.bz2
nginx-1.18.0               php-7.1.10
[root@G opt]#tar xf mysql-boost-5.7.20.tar.gz 
[root@G opt]#cd mysql-5.7.20/
[root@G mysql-5.7.20]#cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DSYSCONFDIR=/etc \
> -DSYSTEMD_PID_DIR=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8  \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS=all \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_BOOST=boost \
> -DWITH_SYSTEMD=1
[root@G mysql-5.7.20]#make -j4
[root@G mysql-5.7.20]#make install
[root@G mysql-5.7.20]#vim /etc/my.cnf
#修改mysql配置文件
[root@G mysql-5.7.20]#cat /etc/my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
[root@G mysql-5.7.20]#chown -R mysql:mysql /usr/local/mysql/
[root@G mysql-5.7.20]#chown mysql:mysql /etc/my.cnf
#更改mysql安装目录和配置文件的属主属组[root@G mysql-5.7.20]#echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
#设置路径环境变量
[root@G mysql-5.7.20]#echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@G mysql-5.7.20]#source /etc/profile
[root@G mysql-5.7.20]#echo $PATH
/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin[root@G mysql-5.7.20]#cd /usr/local/mysql/bin/
[root@G bin]#./mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
#初始化数据库[root@G bin]#cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service 
/usr/lib/systemd/system/
#添加mysqld系统服务
[root@G bin]#systemctl daemon-reload
[root@G bin]#systemctl start mysqld.service
[root@G bin]#systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@G bin]#systemctl status mysqld.service
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since 六 2024-03-09 13:46:17 CST; 8s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlMain PID: 66268 (mysqld)CGroup: /system.slice/mysqld.service└─66268 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr...3月 09 13:46:17 G.D mysqld[66265]: 2024-03-09T05:46:17.637646Z 0 [Warni...e.
3月 09 13:46:17 G.D mysqld[66265]: 2024-03-09T05:46:17.637658Z 0 [Warni...e.
3月 09 13:46:17 G.D mysqld[66265]: 2024-03-09T05:46:17.637661Z 0 [Warni...e.
3月 09 13:46:17 G.D mysqld[66265]: 2024-03-09T05:46:17.637667Z 0 [Warni...e.
3月 09 13:46:17 G.D mysqld[66265]: 2024-03-09T05:46:17.638510Z 0 [Warni...e.
3月 09 13:46:17 G.D mysqld[66265]: 2024-03-09T05:46:17.638519Z 0 [Warni...e.
3月 09 13:46:17 G.D mysqld[66265]: 2024-03-09T05:46:17.642575Z 0 [Note]...ts
3月 09 13:46:17 G.D mysqld[66265]: 2024-03-09T05:46:17.642946Z 0 [Note]...s.
3月 09 13:46:17 G.D mysqld[66265]: Version: '5.7.20'  socket: '/usr/loc...on
3月 09 13:46:17 G.D systemd[1]: Started MySQL Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@G ~]#mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.20 Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> ^DBye

4.配置数据库

[root@G ~]#mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.20 Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> CREATE DATABASE bbs;
Query OK, 1 row affected (0.00 sec)mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 2 warnings (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> ^DBye

5.配置PHP测试页

[root@G ~]#vim /usr/local/nginx/conf/nginx.conf
[root@G ~]#sed -n '65,71p' /usr/local/nginx/conf/nginx.conflocation ~ \.php$ {root           html;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;include        fastcgi_params;}
[root@G ~]#systemctl restart nginx
[root@G ~]#systemctl status nginx.service
● nginx.service - nginxLoaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)Active: active (running) since 六 2024-03-09 13:53:04 CST; 5s agoProcess: 1844 ExecStop=/bin/kill -3 $MAINPID (code=exited, status=0/SUCCESS)Process: 1849 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)Main PID: 1851 (nginx)CGroup: /system.slice/nginx.service├─1851 nginx: master process /usr/local/nginx/sbin/nginx└─1852 nginx: worker process3月 09 13:53:04 G.D systemd[1]: Starting nginx...
3月 09 13:53:04 G.D systemd[1]: Started nginx.
[root@G ~]#vim /usr/local/nginx/html/index.php
[root@G ~]#cat /usr/local/nginx/html/index.php 
<?php
$link=mysqli_connect('192.168.241.24','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
[root@G ~]#systemctl restart nginx

6.安装论坛

[root@G ~]#cd /opt
[root@G opt]#unzip Discuz_X3.4_SC_UTF8.zip
[root@G opt]#ls
dir_SC_UTF8              mysql-boost-5.7.20.tar.gz  php-7.1.10
Discuz_X3.4_SC_UTF8.zip  nginx-1.18.0               php-7.1.10.tar.bz2
mysql-5.7.20             nginx-1.18.0.tar.gz        说明.htm
[root@G opt]#cd dir_SC_UTF8/
[root@G dir_SC_UTF8]#cp -r upload/ /usr/local/nginx/html/bbs
[root@G dir_SC_UTF8]#cd /usr/local/nginx/html/bbs/
[root@G bbs]#ls
admin.php  connect.php      group.php  member.php  search.php  uc_server
api        crossdomain.xml  home.php   misc.php    source
api.php    data             index.php  plugin.php  static
archiver   favicon.ico      install    portal.php  template
config     forum.php        m          robots.txt  uc_client
[root@G bbs]#chown -R nginx.nginx ./config/
[root@G bbs]#chown -R nginx.nginx ./data/
[root@G bbs]#chown -R nginx.nginx ./uc_client/
[root@G bbs]#chown -R nginx.nginx ./uc_server/
[root@G bbs]#chmod -R 777 ./config/
[root@G bbs]#chmod -R 777 ./data/
[root@G bbs]#chmod -R 777 ./uc_client/
[root@G bbs]#chmod -R 777 ./uc_server/
[root@G bbs]#vim /usr/local/nginx/conf/nginx.conf
[root@G bbs]#sed -n '43,46p' /usr/local/nginx/conf/nginx.conflocation / {root   html;index  index.html index.htm index.php;}

7.Web1——搭建Tomcat

7.1安装Oracle JDK

[root@node2 ~]#cd /opt
[root@node2 opt]#rm -rf *
[root@node2 opt]#ls
[root@node2 opt]#rz -E
rz waiting to receive.
[root@node2 opt]#ls
jdk-8u291-linux-x64.tar.gz
[root@node2 opt]#tar xf jdk-8u291-linux-x64.tar.gz -C /usr/local/
[root@node2 opt]#cd /usr/local/
[root@node2 local]#ls
bin  games    jdk1.8.0_291  lib64    sbin   src
etc  include  lib           libexec  share
[root@node2 local]#ln -s jdk1.8.0_291/ jdk
[root@node2 local]#ls
bin  games    jdk           lib    libexec  share
etc  include  jdk1.8.0_291  lib64  sbin     src
[root@node2 local]#vim /etc/profile.d/jdk.sh
[root@node2 local]#cat /etc/profile.d/jdk.sh 
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib/:$JRE_HOME/lib/
[root@node2 local]#. /etc/profile.d/jdk.sh 
[root@node2 local]#java -version
java version "1.8.0_291"
Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)

7.2安装Tomcat

[root@node2 local]#cd /opt
[root@node2 opt]#ls
jdk-8u291-linux-x64.tar.gz
[root@node2 opt]#rz -E
rz waiting to receive.
[root@node2 opt]#ls
apache-tomcat-9.0.16.tar.gz  jdk-8u291-linux-x64.tar.gz
[root@node2 opt]#tar xf apache-tomcat-9.0.16.tar.gz -C /usr/local/
[root@node2 opt]#cd /usr/local/
[root@node2 local]#ls
apache-tomcat-9.0.16  etc    include  jdk1.8.0_291  lib64    sbin   src
bin                   games  jdk      lib           libexec  share
[root@node2 local]#mv apache-tomcat-9.0.16/ tomcat
[root@node2 local]#ls
bin  games    jdk           lib    libexec  share  tomcat
etc  include  jdk1.8.0_291  lib64  sbin     src
[root@node2 local]#cd tomcat/
[root@node2 tomcat]#ls
bin           CONTRIBUTING.md  logs       RELEASE-NOTES  webapps
BUILDING.txt  lib              NOTICE     RUNNING.txt    work
conf          LICENSE          README.md  temp
[root@node2 tomcat]#useradd -M -s /sbin/nologin tomcat
[root@node2 tomcat]#cat > /usr/lib/systemd/system/tomcat.service <<EOF
> [Unit]
> Description=Tomcat
> After=syslog.target network.target
> 
> [Service]
> Type=forking
> ExecStart=/usr/local/tomcat/bin/startup.sh
> ExecStop=/usr/local/tomcat/bin/shutdown.sh
> RestartSec=3
> PrivateTmp=true
> User=tomcat
> Group=tomcat
> 
> [Install]
> WantedBy=multi-user.target
> 
> EOF
[root@node2 tomcat]#cat /usr/lib/systemd/system/tomcat.service 
[Unit]
Description=Tomcat
After=syslog.target network.target[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat[Install]
WantedBy=multi-user.target
[root@node2 tomcat]#chown -R tomcat:tomcat ../tomcat
[root@node2 tomcat]#systemctl daemon-reload
[root@node2 tomcat]#systemctl start tomcat
[root@node2 tomcat]#systemctl status tomcat
● tomcat.service - TomcatLoaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)Active: active (running) since Sat 2024-03-09 00:16:33 EST; 4s agoProcess: 4938 ExecStart=/usr/local/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)Main PID: 4954 (catalina.sh)CGroup: /system.slice/tomcat.service├─4954 /bin/sh /usr/local/tomcat/bin/catalina.sh start└─4955 /usr/bin/java -Djava.util.logging.config.file=/usr/local...Mar 09 00:16:33 node2.localdomain systemd[1]: Starting Tomcat...
Mar 09 00:16:33 node2.localdomain systemd[1]: Started Tomcat.

8.Web2——搭建Tomcat

8.1安装Oracle JDK

[root@node3 ~]#cd /opt
[root@node3 opt]#rm -rf *
[root@node3 opt]#ls
[root@node3 opt]#rz -E
rz waiting to receive.
[root@node3 opt]#rz -E
rz waiting to receive.
[root@node3 opt]#ls
apache-tomcat-9.0.16.tar.gz  jdk-8u291-linux-x64.tar.gz
[root@node3 opt]#tar xf jdk-8u291-linux-x64.tar.gz -C /usr/local/
[root@node3 opt]#cd /usr/local/
[root@node3 local]#ls
bin  games    jdk1.8.0_291  lib64    sbin   src
etc  include  lib           libexec  share
[root@node3 local]#ln -s jdk1.8.0_291/ jdk
[root@node3 local]#ls
bin  games    jdk           lib    libexec  share
etc  include  jdk1.8.0_291  lib64  sbin     src
[root@node3 local]#vim /etc/profile.d/jdk.sh
[root@node3 local]#cat /etc/profile.d/jdk.sh 
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib/:$JRE_HOME/lib/
[root@node3 local]#. /etc/profile.d/jdk.sh 
[root@node3 local]#java -version
java version "1.8.0_291"
Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)

8.2安装Tomcat

[root@node3 local]#cd /opt
[root@node3 opt]#ls
apache-tomcat-9.0.16.tar.gz  jdk-8u291-linux-x64.tar.gz
[root@node3 opt]#tar xf apache-tomcat-9.0.16.tar.gz -C /usr/local/
[root@node3 opt]#ls
apache-tomcat-9.0.16.tar.gz  jdk-8u291-linux-x64.tar.gz
[root@node3 opt]#cd /usr/local/
[root@node3 local]#ls
apache-tomcat-9.0.16  etc    include  jdk1.8.0_291  lib64    sbin   src
bin                   games  jdk      lib           libexec  share
[root@node3 local]#mv apache-tomcat-9.0.16/ tomcat
[root@node3 local]#ls
bin  games    jdk           lib    libexec  share  tomcat
etc  include  jdk1.8.0_291  lib64  sbin     src
[root@node3 local]#cd tomcat/
[root@node3 tomcat]#ls
bin           CONTRIBUTING.md  logs       RELEASE-NOTES  webapps
BUILDING.txt  lib              NOTICE     RUNNING.txt    work
conf          LICENSE          README.md  temp
[root@node3 tomcat]#useradd -M -s /sbin/nologin tomcat
[root@node3 tomcat]#cat > /usr/lib/systemd/system/tomcat.service <<EOF
> [Unit]
> Description=Tomcat
> After=syslog.target network.target
> 
> [Service]
> Type=forking
> ExecStart=/usr/local/tomcat/bin/startup.sh
> ExecStop=/usr/local/tomcat/bin/shutdown.sh
> RestartSec=3
> PrivateTmp=true
> User=tomcat
> Group=tomcat
> 
> [Install]
> WantedBy=multi-user.target
> 
> EOF
[root@node3 tomcat]#cat /usr/lib/systemd/system/tomcat.service 
[Unit]
Description=Tomcat
After=syslog.target network.target[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat[Install]
WantedBy=multi-user.target
[root@node3 tomcat]#chown -R tomcat:tomcat ../tomcat
[root@node3 tomcat]#systemctl daemon-reload
[root@node3 tomcat]#systemctl start tomcat
[root@node3 tomcat]#systemctl status tomcat
● tomcat.service - TomcatLoaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)Active: active (running) since 六 2024-03-09 13:23:13 CST; 3s agoProcess: 37632 ExecStart=/usr/local/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)Main PID: 37647 (catalina.sh)CGroup: /system.slice/tomcat.service├─37647 /bin/sh /usr/local/tomcat/bin/catalina.sh start└─37648 /usr/bin/java -Djava.util.logging.config.file=/usr/loca...3月 09 13:23:13 node3.node3 systemd[1]: Starting Tomcat...
3月 09 13:23:13 node3.node3 startup.sh[37632]: Using CATALINA_BASE:   /us...
3月 09 13:23:13 node3.node3 startup.sh[37632]: Using CATALINA_HOME:   /us...
3月 09 13:23:13 node3.node3 startup.sh[37632]: Using CATALINA_TMPDIR: /us...
3月 09 13:23:13 node3.node3 startup.sh[37632]: Using JRE_HOME:        /usr
3月 09 13:23:13 node3.node3 startup.sh[37632]: Using CLASSPATH:       /us...
3月 09 13:23:13 node3.node3 systemd[1]: Started Tomcat.
Hint: Some lines were ellipsized, use -l to show in full.

三、nginx服务配置虚拟主机,新增两个域名 www.kgc.com 和 www.benet.com,使用http://www.kgc.com/index.php可访问上一题的Discuz论坛页面。使用http://www.benet.com则访问/var/www/html目录中的index.html文件的内容,内容自定义。

1.Nginx服务器配置

[root@G bbs]#vim /usr/local/nginx/conf/nginx.conf
[root@G bbs]#sed -n '35,38p' /usr/local/nginx/conf/nginx.confserver {listen       80;server_name  www.kgc.com;root /usr/local/nginx/html;
[root@G bbs]#vim /usr/local/nginx/conf/nginx.conf
[root@G bbs]#sed -n '80,84p' /usr/local/nginx/conf/nginx.conf
server {listen 80;server_name www.benet.com;root /usr/local/nginx/html;
}
[root@G bbs]#cat /usr/local/nginx/html/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>

2.客户端配置

[root@localhost ~]#vim /etc/hosts
[root@localhost ~]#cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.241.24 www.kgc.com www.benet.com

 C:\Windows\System32\drivers\etc/hosts

3.测试 

[root@localhost ~]#curl www.benet.com
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>

四、对基于www.benet.com域名的虚拟机主机的nginx服务调优:隐藏nginx版本号,缓存静态图片网页时间为1天,设置防盗链功能。

1.Nginx配置

[root@G bbs]#vim /usr/local/nginx/conf/nginx.conf

[root@G bbs]#systemctl restart nginx

2.测试

五、网关服务器搭建NFS服务,提供的文件系统使用LVM类型,共享目录名称为/mnt/nfs;要求根据日期对Discuz论坛服务的访问日志进行日志分割,要求每天生成一份日志文件,保存到NFS服务共享的目录内。

1.网关服务器配置——搭建NFS服务

[root@localhost ~]#alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias scan='echo "- - -" > /sys/class/scsi_host/host0/scan;echo "- - -" > /sys/class/scsi_host/host1/scan;echo "- - -" > /sys/class/scsi_host/host2/scan'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@localhost ~]#
[root@localhost ~]#scan
[root@localhost ~]#lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   60G  0 disk 
├─sda1            8:1    0    5G  0 part /boot
└─sda2            8:2    0   54G  0 part ├─centos-root 253:0    0   50G  0 lvm  /└─centos-swap 253:1    0    4G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk 
sdc               8:32   0   20G  0 disk 
sr0              11:0    1  4.2G  0 rom
[root@localhost ~]#pvcreate /dev/sdb /dev/sdc
#建物理卷Physical volume "/dev/sdb" successfully created.Physical volume "/dev/sdc" successfully created.
[root@localhost ~]#vgcreate vg /dev/sdb /dev/sdc
#建卷组Volume group "vg" successfully created
[root@localhost ~]#lvcreate -n lvm -L 30G /dev/vg
#建逻辑卷  指定名称lvm  指定大小30G  存放在/dev/vg下Logical volume "lvm" created.
[root@localhost ~]#mkfs.xfs /dev/vg/lvm
#文件系统xfs格式
meta-data=/dev/vg/lvm            isize=512    agcount=4, agsize=1966080 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=7864320, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=3840, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]#mount /dev/vg/lvm  /mnt
#挂载
[root@localhost ~]#mkdir /mnt/nfs
[root@localhost ~]#vim /etc/exports
[root@localhost ~]#cat /etc/exports
/mnt/nfs *
[root@localhost ~]#systemctl start nfs
[root@localhost ~]#exportfs -v
/mnt/nfs      	<world>(ro,sync,wdelay,hide,no_subtree_check,sec=sys,secure,root_squash,no_all_squash)

2.Nginx服务器——共享目录 

[root@G bbs]#showmount -e 192.168.241.11
Export list for 192.168.241.11:
/mnt/nfs *
[root@G bbs]#mount 192.168.241.11:/mnt/nfs /mnt/
[root@G bbs]#df
文件系统                   1K-块     已用     可用 已用% 挂载点
/dev/mapper/centos-root 52403200 12697156 39706044   25% /
devtmpfs                  917604        0   917604    0% /dev
tmpfs                     933524        0   933524    0% /dev/shm
tmpfs                     933524     9144   924380    1% /run
tmpfs                     933524        0   933524    0% /sys/fs/cgroup
/dev/sda1                6281216   182368  6098848    3% /boot
tmpfs                     186708        0   186708    0% /run/user/0
tmpfs                     186708       12   186696    1% /run/user/42
192.168.241.11:/mnt/nfs 31441920    32768 31409152    1% /mnt

3.日志分割

[root@G ~]#vim split-log.sh
[root@G ~]#cat split-log.sh 
#!/bin/bash
day=`date "+%Y-%m-%d"`
log="/usr/local/nginx/logs"
pid=`cat /usr/local/nginx/logs/nginx.pid`mv /$(log)/access.log /opt/${day}
kill -USR1 ${pid}
sed -i '/.*bbs.*/!p' /opt/${day}
[root@G ~]#crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@G ~]#crontab -l
59 23 * * * bash ~/split-log.sh

六、要求配置location匹配请求地址http://www.kgc.com/test/XXXX,使用户访问该路径下的文件时返回/var/share/nginx/html/目录下的文件内容。

要求使用rewrite将使用域名www.benet.com 请求以 .php 结尾的访问都跳转到域名www.kgc.com上,而且后面的参数保持不变,比如访问http://www.benet.com/bbs/index.php跳转到http://www.kgc.com/bbs/index.php。

1.Nginx服务器配置

[root@G ~]#vim /usr/local/nginx/conf/nginx.conf

[root@G ~]#mkdir /var/share/nginx/html -p
[root@G ~]#nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@G ~]#nginx -s reload

2.测试

七、在Nginx服务器上对基于www.benet.com域名的虚拟机主机设置动静分离由nginx提供静态页面服务,将对 .jsp文件的动态页面请求转发到Tomcat 服务器处理,并实现负载均衡

1.Nginx服务配置

[root@G html]#vim /usr/local/nginx/conf/nginx.conf

[root@G html]#nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@G html]#nginx -s reload
[root@G php]#cd /usr/local/nginx/html/
[root@G html]#ls
50x.html  bbs  index.html
[root@G html]#mv index.html ..
[root@G html]#ls
50x.html  bbs
[root@G html]#echo Welcome back > index.html
[root@G html]#cat index.html 
Welcome back

2.Tomcat1服务器配置

[root@node2 ROOT]#ls
asf-logo-wide.svg  bg-upper.png       tomcat.css        tomcat.svg
bg-button.png      favicon.ico        tomcat.gif        WEB-INF
bg-middle.png      index.jsp          tomcat.png
bg-nav.png         RELEASE-NOTES.txt  tomcat-power.gif
[root@node2 ROOT]#mv index.jsp ..
[root@node2 ROOT]#ls
asf-logo-wide.svg  bg-upper.png       tomcat.gif        WEB-INF
bg-button.png      favicon.ico        tomcat.png
bg-middle.png      RELEASE-NOTES.txt  tomcat-power.gif
bg-nav.png         tomcat.css         tomcat.svg
[root@node2 ROOT]#echo Tomcat1 > index.jsp
[root@node2 ROOT]#cat index.jsp 
Tomcat1
[root@node2 ROOT]#systemctl start tomcat

3.Tomcat2服务器配置

[root@node3 tomcat]#ls
bin           CONTRIBUTING.md  logs       RELEASE-NOTES  webapps
BUILDING.txt  lib              NOTICE     RUNNING.txt    work
conf          LICENSE          README.md  temp
[root@node3 tomcat]#cd webapps/ROOT/
[root@node3 ROOT]#ls
asf-logo-wide.svg  bg-upper.png       tomcat.css        tomcat.svg
bg-button.png      favicon.ico        tomcat.gif        WEB-INF
bg-middle.png      index.jsp          tomcat.png
bg-nav.png         RELEASE-NOTES.txt  tomcat-power.gif
[root@node3 ROOT]#mv index.jsp ..
[root@node3 ROOT]#ls
asf-logo-wide.svg  bg-upper.png       tomcat.gif        WEB-INF
bg-button.png      favicon.ico        tomcat.png
bg-middle.png      RELEASE-NOTES.txt  tomcat-power.gif
bg-nav.png         tomcat.css         tomcat.svg
[root@node3 ROOT]#echo Tomcat2 > index.jsp
[root@node3 ROOT]#cat index.jsp 
Tomcat2
[root@node3 ROOT]#systemctl start tomct
Failed to start tomct.service: Unit not found.
[root@node3 ROOT]#systemctl start tomcat

4.测试

八、在网关服务器上设置SNAT/DNAT,使client使用网关服务器的ens36接口的IP地址访问也可实现上一题的效果。

1.代理服务器配置 

[root@localhost ~]#vim /etc/sysctl.conf 
[root@localhost ~]#tail -n1 /etc/sysctl.conf 
net.ipv4.ip_forward = 1
[root@localhost ~]#sysctl -p
net.ipv4.ip_forward = 1
[root@localhost ~]#vim /etc/hosts
[root@localhost ~]#cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.241.24 www.kgc.com www.benet.com
[root@localhost ~]#iptables -F
[root@localhost ~]#iptables -t nat -A POSTROUTING -s 192.168.241.11/24 -o ens36 -p tcp --dport 80 -j SNAT --to 12.0.0.1
[root@localhost ~]#iptables -t nat -A PREROUTING -d 12.0.0.1/24 -i ens36 -p tcp --dport 80 -j DNAT --to 192.168.241.11      
[root@localhost ~]#iptables -t nat -vnL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination         0     0 DNAT       tcp  --  ens36  *       0.0.0.0/0            12.0.0.0/24          tcp dpt:80 to:192.168.241.11Chain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination         Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination         Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination         4   260 RETURN     all  --  *      *       192.168.122.0/24     224.0.0.0/24        0     0 RETURN     all  --  *      *       192.168.122.0/24     255.255.255.255     0     0 MASQUERADE  tcp  --  *      *       192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-655350     0 MASQUERADE  udp  --  *      *       192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-655350     0 MASQUERADE  all  --  *      *       192.168.122.0/24    !192.168.122.0/24    0     0 SNAT       tcp  --  *      ens36   192.168.241.0/24     0.0.0.0/0            tcp dpt:80 to:12.0.0.1

2.测试

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/732160.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数据集下载汇总

国家数据网 https://data.stats.gov.cn/ 国家数据是国家统计局发布统计信息的网站&#xff0c;包含了我国经济、民生、农业、工业、运输、旅游、教育、科技、卫生等多个方面的数据&#xff0c;并且在月度、季度、年度都有覆盖&#xff0c;较为全面和权威&#xff0c;对于社会…

【数据库-黑马笔记】基础-函数和约束

本文参考b站黑马数据库视频,总结详细全面的笔记 ,可结合视频观看27~36集 MYSQL 的基础知识框架如下 目录 一、 函数 1、字符串函数 2、数值函数 3、日期函数 4、流程函数 5、小结: 二、约束 1、概述 2、 约束演示 3、外键约束 4、外键删除更新行为 5、小结: …

如何查看自己电脑显卡的内存

ctrlaltdelete 打开任务管理器&#xff0c;然后打开性能页面,你会看到一个GPU内存&#xff0c;这个是自己GPU的内存&#xff0c;也叫专用GPU内存&#xff0c;而那个共享GPU 内存是不够用的时候借用电脑的内存。 下面是专用GPU内存和共享GPU内存的具体区别 专用GPU内存和共享GPU…

HarmonyOS 数据持久化 关系型数据库之 增删改逻辑编写

好 上文 HarmonyOS 数据持久化 关系型数据库之 初始化操作 我们讲了 关系型数据库初始化 那么 本文 我们来编写 增删改 相关代码 打开我们的项目 打开到 我们之前写的这个 relationalClass 类 然后 我们在 initTaskDB 下面再定义一个函数 叫 addTask 的函数 用来执行添加逻辑 …

【论文笔记】Mamba: Linear-Time Sequence Modeling with Selective State Spaces

原文链接&#xff1a;https://arxiv.org/abs/2312.00752 1. 引言 基石模型&#xff08;FM&#xff09;的主干网络通常是序列模型&#xff0c;处理任意的输入序列。但现代FM主要基于Transformer这一序列模型&#xff0c;及其核心的注意力。但是&#xff0c;自注意力仅能在上下…

EVMProxyInspect:一款功能强大的多链EVM代理检测工具

关于EVMProxyInspect EVMProxyInspect是一款针对以太坊EVM代理的检测工具&#xff0c;该工具可以帮助广大研究人员在多链生态中检测EVM代理。 该工具能够展示类似etherscan这样的工具是如何检测代理的&#xff0c;并且允许我们自行进行代理检测。需要注意的是&#xff0c;该工…

Python:在 Ubuntu 上安装 pip的方法

目录 1、检测是否已安装pip 2、更新软件源 3、安装 4、检测是否安装成功 pip和pip3都是Python包管理工具&#xff0c;用于安装和管理Python包。 在Ubuntu上&#xff0c;pip和pip3是分别针对Python2和Python3版本的pip工具。 pip3作用&#xff1a;自动下载安装Python的库文…

Linux(Centos7)安装Docker 教程

目录 1&#xff0c;卸载旧版本2&#xff0c;安装docker软件包3,设置镜像仓库地址4,安装最新版Docker Engine容器5&#xff0c;启动Docker 要安装Docker Engine&#xff0c;您需要CentOS 7或8的维护版本。不支持或未测试存档版本。 1&#xff0c;卸载旧版本 sudo yum remove do…

webUI自动化之元素及浏览器操作

一、元素定位方式 1、元素属性定位&#xff1a; 1 element driver.find_element_by_id(self, id)    该类方法已经过时&#xff0c;新的方法如下&#xff1a; element driver.find_element(By.ID, ID 值)        # 用元素的 ID 属性定位element driver.find_eleme…

一大波你可能不知道的 Linux 网络工具

如果要在你的系统上监控网络&#xff0c;那么使用命令行工具是非常实用的&#xff0c;并且对于 Linux 用户来说&#xff0c;有着许许多多现成的工具可以使用&#xff0c;如&#xff1a;nethogs, ntopng, nload, iftop, iptraf, bmon, slurm, tcptrack, cbm, netwatch, collectl…

idea:springboot项目搭建

目录 一、创建项目 1、File → New → Project 2、Spring Initializr → Next 3、填写信息 → Next 4、web → Spring Web → Next 5、填写信息 → Finish 6、处理配置不合理内容 7、注意事项 7.1 有依赖包&#xff0c;却显示找不到依赖&#xff0c;刷新一下maven 7.…

社交媒体的未来图景:探索Facebook的数字化之旅

随着科技的迅猛发展&#xff0c;数字化社交已经成为了我们日常生活中不可或缺的一部分。在这个数字化时代&#xff0c;社交媒体平台扮演着重要角色&#xff0c;其中Facebook作为社交媒体的先锋&#xff0c;不断探索创新之路&#xff0c;引领着数字化社交的未来发展。本文将深入…

两天学会微服务网关Gateway-Gateway路由规则

锋哥原创的微服务网关Gateway视频教程&#xff1a; Gateway微服务网关视频教程&#xff08;无废话版&#xff09;_哔哩哔哩_bilibiliGateway微服务网关视频教程&#xff08;无废话版&#xff09;共计17条视频&#xff0c;包括&#xff1a;1_Gateway简介、2_Gateway工作原理、3…

和数软件:区块链技术的爆发与冲击

什么是区块链&#xff1f;它是如何发展而来的&#xff1f;应用在哪些领域&#xff1f;将会对我国的社会经济产生哪些重大影响&#xff1f; 什么是区块链 区块链作为一种底层技术&#xff0c;最早的实践是数字货币。根据最早的中本聪定义&#xff0c;区块链实质上是一种基于网…

机器学习--循环神经网络(RNN)4

一、RNN的学习方式 如果要做学习&#xff0c;需要定义一个损失函数&#xff08;loss function&#xff09;来评估模型的好坏&#xff0c;选一个参数要让损失最小。 以槽填充为例&#xff0c;如上图所示&#xff0c;给定一些句子&#xff0c;给定一些标签&#xff0c;告诉机器…

借助Aspose.html控件,在 Java 中将 URL 转换为 PDF

如果您正在寻找一种将实时 URL 中的网页另存为 PDF文档的方法&#xff0c;那么您来对地方了。在这篇博文中&#xff0c;我们将学习如何使用 Java 将 URL 转换为 PDF。从实时 URL转换HTML网页可以像任何其他文档一样保存所需的网页以供离线访问。将网页保存为 PDF 格式可以轻松突…

华为ce12800交换机m-lag(V-STP模式)配置举例

配置## 标题思路 采用如下的思路配置M-LAG双归接入IP网络&#xff1a; 1.在Switch上配置上行接口绑定在一个Eth-Trunk中。 2.分别在SwitchA和SwitchB上配置V-STP、DFS Group、peer-link和M-LAG接口。 3.分别在SwitchA和SwitchB上配置LACP M-LAG的系统优先级、系统ID。 4.分别在…

【STM32+HAL】GY25倾斜度角度模块

一、前言 有关MPU6050模块读取六轴传感器数值的详细内容&#xff0c;详见【STM32HAL】姿态传感器陀螺仪MPU6050模块 二、所用工具 1、芯片&#xff1a;STM32F103C8T6 2、配置软件&#xff1a;CUBEMX 3、编译器&#xff1a;KEIL5 4、产品型号&#xff1a;GY-25 5、使用芯片…

基于SSH框架的鞋业管理系统设计与实现

目 录 摘 要 I Abstract II 引 言 1 1 相关技术 3 1.1 MySQL 3 1.2 SSH框架 3 1.2.1 Struts 3 1.2.2 Spring 4 1.2.3 Hibernate 5 1.3 B/S架构 5 1.4 本章小结 6 2 系统分析 7 2.1 用例分析 7 2.2 功能需求 9 2.3 非功能需求 11 2.4 本章小结 12 3 系统设计 13 3.1 系统概要设…

BigDecimal可以用equals方法做等值比较吗?

结论是不可以&#xff0c;BigDecimal的equals方法不仅会比较值&#xff0c;还会比较精度&#xff0c;比如1.0和1.00虽然值是一样的&#xff0c;我们也倾向于认为是相同的&#xff0c;但是因为精度不同&#xff0c;最终得到的结论是false。 代码如下&#xff1a; Test public v…