yum安装jdk yum install java-1.8.0-openjdk-devel java-1.8.0-openjdk -y 查看软件版本 java -version yum安装tomcat yum install tomcat-lib tomcat tomcat-admin-webapps tomcat-dosc-webapp tomcat-webapps -y 启动tomcat 命令: systemctl start tomcat.service 查看端口: ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 100 :::8009 :::* LISTEN 0 100 :::8080 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* 其中8009,8080,8005都是tomcat的启动端口,访问端口是8080 在浏览器里面输入: http://10.0.0.7:8080/ 根据你自己的IP地址在后面加上:8080回车就可以访问 关闭tomcat systemctl stop tomcat.service 开机自启动tomcat systemctl enable tomcat.service rpm安装jdk 首先去官方下载一个jdk rpm文件 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 下载好以后可以用rpm -ivh 软件包名 rpm -ivh jdk-8u231-linux-x64.rpm 添加环境变量 vim /etc/profile.d/java.sh 写入以下内容 export JAVA_HOME=/usr/java/latest export PATH=$JAVA_HOME/bin:$PATH 让这条命令生效 . /etc/profile.d/java.sh 查看结果 echo $JAVA_HOME 返回结果 /usr/java/latest 查看版本 java -version 安装tomcat 下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/ 解压toomcat包 tar -xf apache-tomcat-9.0.30.tar.gz -C /usr/local/ 创建软连接方便调用 ln -s /usr/local/apache-tomcat-9.0.30/ /usr/local/tomcat 启动: /usr/local/tomcat/bin/startup.sh 返回结果: Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/java/latest Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. 关闭: /usr/local/tomcat/bin/shutdown.sh 返回结果 Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/java/latest Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar 查看进程方法 命令:ps -ef |grep java 这里会遇到端口没有了但是进程还在我们可以把进程pkill掉,这样就彻底关闭掉了 命令:pkill java 设置tomcat开机自启动 echo /usr/local/tomcat/bin/startup.sh >> /etc/rc.local 二进制安添加权限装jdk和tomcat ##jdk chmod +x /etc/rc.local #各种版本:https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/ 解压二进制jdk包 tar -xf jdk-8u60-linux-x64.tar.gz -C /usr/local/ 创建软连接方便调用 ln -s /usr/local/jdk1.8.0_60/ /usr/local/jdk 添加jdk环境变量 cat >>/etc/profile<<'EOF' export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar export TOMCAT_HOME=/usr/local/tomcat EOF 或者用vim也是可以。把这些内容添加到最后一行即可 vim /etc/profile export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar export TOMCAT_HOME=/usr/local/tomcat 然后再让这条命令生效一下 . /etc/profile 查看版本,验证一下这条变量是否生效 java -version 安装tomcat 首先解压apache-tomcat包 tar -xf apache-tomcat-8.0.27.tar.gz -C /usr/local/ 创建软连接方便调用 ln -s /usr/local/apache-tomcat-8.0.27/ /usr/local/tomcat 添加tomcat变量 vim /etc/profile.d/tomcat.sh export CATALINA_BASE=/usr/local/tomcat export PATH=$CATALINA_BASE/bin:$PATH 让这条变量生效 . /etc/profile.d/tomcat.sh 查看tomcat软件详细命令如下 /usr/local/tomcat/bin/version.sh 返回结果 Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Server version: Apache Tomcat/8.0.27 Server built: Sep 28 2015 08:17:25 UTC Server number: 8.0.27.0 OS Name: Linux OS Version: 3.10.0-957.el7.x86_64 Architecture: amd64 JVM Version: 1.8.0_60-b27 JVM Vendor: Oracle Corporation 启动tomcat 命令:/usr/local/tomcat/bin/startup.sh 返回结果: Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. 利用命令查看服务是否启动,查看端口是否存在,如果有8009和8080还有8005说明服务已经启动了 命令:ss -ntl 返回结果: LISTEN 0 100 :::8009 :::* LISTEN 0 100 :::8080 :::* LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* 关闭tomcat 命令:/usr/local/tomcat/bin/shutdown.sh 返回结果: Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar 查看进程方法 命令:ps -ef |grep java 这里会遇到端口没有了但是进程还在我们可以把进程pkill掉,这样就彻底关闭掉了 命令:pkill java 设置tomcat开机自启动 echo /usr/local/tomcat/bin/startup.sh >> /etc/rc.local 添加权限 chmod +x /etc/rc.local tomcat文件目录结构: bin: 脚本,及启动时用到的类 conf: 配置文件目录 lib: 库文件,java类库,jar logs: 日志文件目录 temp: 临时文件目录 webapps: webapp的网站默认目录 work: 进程工作目录 搭建zrlog博客 添加新的域名配置文件 vim /usr/local/tomcat/conf/server.xml 新增加配置文件 <Host name="zrlog.9527edu.org" appBase="/html" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> Host name="zrlog.9527edu.org" 网站域名,每个网站的域名要不一样 appBase="/html" 网站存放目录路径 unpackWARs="true" 是否自定解压war包,默认为自动 autoDeploy="true" 是否自定部署。默认为自动 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="zrlog_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> 日志格式,建议每个网站的日志前缀不要一样 prefix="zrlog_access_log" suffix=".txt" 日志前缀和文件类型为txt pattern="%h %l %u %t "%r" %s %b" 日志格式 编辑好配置文件,保存 创建一个目录 mkdir /html 下载一个zrlog的war包 wget http://dl.zrlog.com/release/zrlog-2.1.7-768d7a6-release.war?attname=ROOT.war 修改名称,默认的名称后缀会很长,所以需要给他修改成ROOT.war前面的名字一定要大写的 mv zrlog-2.1.7-768d7a6-release.war\?attname\=ROOT.war ROOT.war 把war包复制到/html cp ROOT.war /html 先来停止tomcat。如果在运行的状态下需要停止再启动 /usr/local/tomcat/bin/shutdown.sh 启动命令: /usr/local/tomcat/bin/startup.sh 安装数据库,用yum安装或者二进制安装 yum install mariadb-server -y 启动数据库 systemctl start mariadb 开机自启动mariadb systemctl enable mariadb 进入数据库 mysql 进入之后创建数据库 create database zrlog defaule charset=utf8; 授权数据库,并设置一个密码密码是123456 grant all on zrlog.* to 'zrlog'@'%' identified by '123456'; 退出数据库 quit 打开浏览器访问 zrlog.9527edu.org:8080 打开网址以后,IP输入 127.0.0.1 或者你服务器的真实IP地址 数据库服务器: 127.0.0.1 或者你服务器的真实IP地址 数据库名:zrlog 数据库用户名:zrlog 数据库密码:123456