在vm虚拟网络编辑器 配置vmnet1与wmnet8
电脑端IP192.168.x.1 掩码24 无需网关配置
添加第二个网卡
删除网卡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
配置dnsecho "nameserver 192.168.9.2" >> /etc/resolv.conf
测试ping baidu.com
使用脚本修改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
查看网卡配置信息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 dnssethost 10 nginx
sethost 11 tomcat
sethost 12 dns
配置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/ \\访问服务是否启动
把资料中的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 ~]<mirror> <id> nexus-aliyun</id> <mirrorOf> * </mirrorOf> <name> Nexus aliyun</name> <url> http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
检查maven版本
1 2 ~]# /usr/local/maven/bin/mvn -v Apache Maven 3 .6 .3
tomcat部署师说CMS项目 把资料中的cms.tar.gz上传到tomcat机器上 解压cms.tar.gz
1 2 3 4 ~] ~] CMS] 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] dist doc LICENSE pom.xml README .md shishuocms.properties sql src target webdefault.xml CMS ] target] 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 target ]# /root/apache-tomcat-8 .0 .30 /bin/shutdown.shtarget ]# rm -rf /root/apache-tomcat-8 .0 .30 /webapps/ROOTtarget ]# 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 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] 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去登录
部署nginx (192.168.8.10) 上传nginx-1.22.1.tar.gz源码 解压nginx包,安装源码编译环境
1 2 3 4 5 6 7 8 [root@nginx ~] [root@nginx ~] [root@nginx ~] [root@nginx nginx-1.22 .1 ] [root@nginx nginx-1.22 .1 ] [root@nginx nginx-1.22 .1 ] [root@nginx nginx-1.22 .1 ] 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] [root@nginx ~] http { upstream tomcats { server 192.168 .8.11 :8080 ; } server { listen 80 ; server_name tomcats; location / { proxy_pass http:// tomcats; } } } [root@nginx nginx]
修改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" }
建立地址库文件
1 2 3 4 5 6 7 8 9 10 11 $TTL 1 D @ IN SOA @ rname.invalid. ( 0 1 D 1 H 1 W 3 H ) NS server server A 192.168.8.12 www A 192.168.8.10 @ A 192.168.8.10
启动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
在windows中添加dns配置
浏览器访问 (http协议) shishuocms.com