师说部署

在vm虚拟网络编辑器 配置vmnet1与wmnet8

9061880d0b57b94d3cc11d6e86f298b7.png

电脑端IP192.168.x.1 掩码24 无需网关配置

4e86fab37f0d252d314c09bfddc1cf1d.png

17f36056a36e48c2b1a6d6530a3f7850.png

 

添加第二个网卡

26c5d55d3c00c64af17244d3d000556e.png

删除网卡
nmcli connection show
nmcli connection delete ens160

添加网卡
nmcli connection add type ethernet ifname eth0 con-name eth0
nmcli connection add type ethernet ifname eth1 con-name eth1
修改IP地址
nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.8.3/24 autoconnect yes nmcli connection up eth0
nmcli connection modify eth1 ipv4.method manual ipv4.addresses 192.168.9.3/24 ipv4.gateway 192.168.9.2 autoconnect yes nmcli connection up eth1
配置dns
echo "nameserver 192.168.9.2" >> /etc/resolv.conf
测试
ping baidu.com
4698bf01041dad795406f7b5bf10d5e6.png

使用脚本修改IP地址和主机名

~]# vim /usr/bin/sethost #!/bin/bash nmcli connection modify eth1 ipv4.method manual ipv4.addresses 192.168.99.$1/24 ipv4.gateway 192.168.99.2 autoconnect yes nmcli connection up eth1 nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.88.$1/24 autoconnect yes nmcli connection up eth0 hostnamectl set-hostname $2 echo "nameserver 192.168.99.2" >> /etc/resolv.conf ~]# chmod +x /usr/bin/sethost
通过执行sethost把当前模板机的IP改为192.168.8.3和192.168.9.3
~]# sethost 3 a
8028ada35fa8d865b61e01777e0c0f0c.png
查看网卡配置信息
cat /etc/sysconfig/network-scripts/ifcfg-eth0
cat /etc/sysconfig/network-scripts/ifcfg-eth1
关闭selinux,卸载防火墙

1
2
3
~]# vim /etc/selinux/config
SELINUX=permissive
~]# yum -y remove firewalld

克隆三台虚拟机
192.168.8.10 nginx
192.168.8.11 tomcat
192.168.8.12 dns
sethost 10 nginx
sethost 11 tomcat
sethost 12 dns
885a683328157e18e4abc9d79fd4ea79.png

配置tomcat

从课件材料中把tomcat上传到tomcat01机器上 apache-tomcat-8.0.30.tar.gz (tmp路径下)

1
2
3
4
5
6
7
8
9
10
yum -y install java-1.8.0-openjdk   \\安装jdk
tar -xf /tmp/apache-tomcat-8.0.30.tar.gz
tree apache-tomcat-8.0.30/ \\默认解压到当前路径
tree apache-tomcat-8.0.30/ \\查看列表
cd /root/apache-tomcat-8.0.30/bin \\进入tomcat文件目录
./startup.sh \\执行tomcat
ss -tunlpa | grep 8080 \\检查端口是否正常
http://192.168.8.11:8080/ \\访问服务是否启动


2d61b5b8f6f4020e5c6ab2066e9c24c7.png

 
把资料中的apache-maven-3.6.3-bin.tar.gz上传到tomcat机器上

1
2
3
~]# tar -xf apache-maven-3.6.3-bin.tar.gz
~]# mv apache-maven-3.6.3 /usr/local/maven

安装Java依赖
~]# yum -y install java-devel
修改镜像地址,在第158行下添加

1
2
3
4
5
6
7
~]# vim /usr/local/maven/conf/settings.xml  
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

50ba793a8ad5613018c383f2d71ded03.png
检查maven版本

1
2
 ~]# /usr/local/maven/bin/mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

tomcat部署师说CMS项目
把资料中的cms.tar.gz上传到tomcat机器上
解压cms.tar.gz

1
2
3
4
 ~]# tar -xf cms.tar.gz
~]# cd CMS/
CMS]# ls
doc LICENSE pom.xml README.md shishuocms.properties sql src webdefault.xml

通过maven把CMS编译打包

1
2
3
4
5
6
7
8
9
10
~]# cd CMS/
CMS]# /usr/local/maven/bin/mvn clean package
最终出现如下代表打包成功
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:20 min
[INFO] Finished at: 2025-02-25T22:17:03-05:00
[INFO] ------------------------------------------------------------------------

检查是否生成目录:target

1
2
3
4
5
CMS]# ls
dist doc LICENSE pom.xml README.md shishuocms.properties sql src target webdefault.xml
CMS]# cd target/
target]# ls
antrun classes generated-sources maven-archiver maven-status shishuocms-2.0.1 shishuocms-2.0.1.war

将shishuocms-2.0.1.war拷贝到tomcat的webapps目录中

1
2
3
4
5
#停掉tomcat
target]# /root/apache-tomcat-8.0.30/bin/shutdown.sh
#删除tomcat下的webapps中的ROOT
target]# rm -rf /root/apache-tomcat-8.0.30/webapps/ROOT
target]# cp shishuocms-2.0.1.war /root/apache-tomcat-8.0.30/webapps/ROOT.war

启动tomcat

1
target]# /root/apache-tomcat-8.0.30/bin/startup.sh

验证tomcat启动是否成功

1
2
3
target]# ss -antlup | grep 8080
tcp LISTEN 0 100 *:8080 *:* users:(("java",pid=25168,fd=50))

查看CMS中的数据库配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
 CMS]# vim src/main/resources/shishuocms.properties
#超级管理员
shishuocms.admin=shishuocms
#师说存储方式(server | ace)
shishuocms.storage=ace
#数据库配置
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/shishuocms?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
jdbc.username=root
jdbc.password=12345678
jdbc.initialPoolSize=2
jdbc.minPoolSize=2
jdbc.maxPoolSize=5

安装数据库

1
2
3
~]# yum install -y mariadb-server
~]# systemctl start mariadb
~]# systemctl enable mariadb

把CMS中sql目录的install.sql导入到数据库中

1
CMS]# mysql < sql/install.sql

给root账号设置密码:12345678

1
2
3
CMS]# mysqladmin password    #修改数据库密码
New password: #接下来输入12345678
Confirm new password: #在输入一次12345678

进入数据库中去查看CMS系统的登录密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
CMS]# mysql -p12345678
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| shishuocms |
+--------------------+
MariaDB [(none)]> use shishuocms;
MariaDB [shishuocms]> show tables;
+----------------------+
| Tables_in_shishuocms |
+----------------------+
| admin |
| admin_folder |
| article |
| comment |
| config |
| folder |
| guestbook |
| headline |
| media |
| user |
+----------------------+
MariaDB [shishuocms]> select * from admin;
+---------+------------+----------------------------------+---------------------+
| adminId | name | password | createTime |
+---------+------------+----------------------------------+---------------------+
| 1 | shishuocms | 6158f875bf826e15923779855b6eef2e | 2012-08-08 00:00:00 |
+---------+------------+----------------------------------+---------------------+

使用123456明文加密后的密码去修改密码

1
2
3
4
5
6
7
8
 [shishuocms]> update admin set password='e10adc3949ba59abbe56e057f20f883e' where adminId=1;
MariaDB [shishuocms]> select * from admin;
+---------+------------+----------------------------------+---------------------+
| adminId | name | password | createTime |
+---------+------------+----------------------------------+---------------------+
| 1 | shishuocms | e10adc3949ba59abbe56e057f20f883e | 2012-08-08 00:00:00 |
+---------+------------+----------------------------------+---------------------+

使用123456去登录
f259c799daf231b1bc8bfd6eafd3e306.png
a351dfbaff240f271a904dcd1f800069.png

部署nginx (192.168.8.10)
上传nginx-1.22.1.tar.gz源码
解压nginx包,安装源码编译环境

1
2
3
4
5
6
7
8
[root@nginx ~]# tar -xf nginx-1.22.1.tar.gz
[root@nginx ~]# yum -y install gcc make pcre-devel
[root@nginx ~]# cd nginx-1.22.1/
[root@nginx nginx-1.22.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --without-http_gzip_module
[root@nginx nginx-1.22.1]# make
[root@nginx nginx-1.22.1]# make install
[root@nginx nginx-1.22.1]# ls /usr/local/nginx/
conf html logs sbin

启动nginx和验证安装是否成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@nginx sbin]# /usr/local/nginx/sbin/nginx
nginx: [emerg] getpwnam("nginx") failed
发现启动失败,因为没有nginx用户,需要创建用
[root@nginx sbin]# useradd nginx
[root@nginx sbin]# /usr/local/nginx/sbin/nginx
[root@nginx sbin]# curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
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>

配置nginx反向代理到tomcat

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@nginx ~]# vim  /usr/local/nginx/conf/nginx.conf
http {
upstream tomcats {
server 192.168.88.11:8080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://tomcats;
}
}
}

重新加载nginx配置
[root@nginx nginx]# /usr/local/nginx/sbin/nginx -s reload
修改nginx的配置添加一个服务名为tomcat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@nginx nginx]# vim conf/nginx.conf
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
http {
upstream tomcats {
server 192.168.8.11:8080;
}
server {
listen 80;
server_name tomcats; #修改点
location / {
proxy_pass http://tomcats;
}
}
}
[root@nginx nginx]# sbin/nginx -s reload

修改Windows hosts文件
修改我们自己的windows中的hosts文件
192.168.88.10 tomcats

DNS服务器搭建(192.168.8.12)
克隆一台机器,修改IP和主机名
~]# sethost 40 dns
安装dns相关软件包
[root@nds ~]# yum -y install bind bind-chroot
修改主配置文件

1
2
3
4
5
6
7
8
options {
directory "/var/named";
};
zone "shishuocms.com" IN {
type master;
file "shishuocms.com.zone";
};

dea1f3cbd63a1c2ea6410bdb96b8b33d.png
建立地址库文件

1
2
3
4
5
6
7
8
9
10
11
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS server
server A 192.168.8.12
www A 192.168.8.10
@ A 192.168.8.10

7aac764c06c659f093042c298e744bca.png
启动dns

1
2
systemctl start named
systemctl enable named

nginx配置修改(192.168.8.10)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@nginx ~]# vim  /usr/local/nginx/conf/nginx.conf

http {
include mime.types;
default_type application/octet-stream;

upstream tomcats {
server 192.168.8.11:8080;
}
server {
listen 80;
server_name shishuocms.com;
location / {
proxy_pass http://tomcats;
}
}

[root@nginx ~]# /usr/local/nginx/sbin/nginx -s reload

bc34a8a1770e2ef9b3d02033f2883af1.png

在windows中添加dns配置
95a288525beab5b055cdc62f4e9417e6.png
a6f7fcd99588abf1957ee1ca5d66cc3a.png

浏览器访问 (http协议)
shishuocms.com
d94d10a15a38e3a3c43eb35777b40e37.png


师说部署
http://example.com/2025/05/18/db52a846c595461e971b972fa4697300/
作者
John Doe
发布于
2025年5月18日
许可协议