1 查找进程

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。

ps -ef | grep java   查看所有关于java的进程

root     17540     1  0  2009 ?        01:42:27 /usr/java/jdk1.5.0_15/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -server -Xms800m -Xmx800m -XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128m -Djava.awt.headless=true -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms256m -Xmx1024m -Djava.endorsed.dirs=/usr/local/tomcat/common/endorsed -classpath :/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/commons-logging-api.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start 
root     19979     1  0 Jan05 ?        00:00:51 /usr/java/latest/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/usr/local/apache-tomcat-6.0.16/conf/logging.properties -Xms256m -Xmx1024m -Djava.endorsed.dirs=/usr/local/apache-tomcat-6.0.16/endorsed -classpath :/usr/local/apache-tomcat-6.0.16/bin/bootstrap.jar -Dcatalina.base=/usr/local/apache-tomcat-6.0.16 -Dcatalina.home=/usr/local/apache-tomcat-6.0.16 -Djava.io.tmpdir=/usr/local/apache-tomcat-6.0.16/temp org.apache.catalina.startup.Bootstrap start 
root     27120 27015  0 13:23 pts/4    00:00:00 grep java

通过如下命令查看所有关于java的进程:

ps -ef | grep java 

终止线程

在得到相关进程时,将某线程终止时用

kill -9 XXXXX 

XXXXX 为上述查出的序号  如: 19979线程终止为: kill -9 19979

kill一个线程时需注意不要误停止了不应该停止的线程造成不必要的麻烦。 
在相当确信时才可用此方法停止线程。

输入以下命令可以查看关于tomcat的进程:

ps -ef | grep tomcat
回到顶部

2 查看当前服务器用户数量

w和who命令最为简单。

作为系统管理员,你可能经常会(在某个时候)需要查看系统中有哪些用户正在活动。有些时候,你甚至需要知道他(她)们正在做什么。本文为我们总结了4种查看系统用户信息(通过编号(ID))的方法。

2.1 使用w命令查看登录用户正在使用的进程信息

w命令用于显示已经登录系统的用户的名称,以及他们正在做的事。该命令所使用的信息来源于/var/run/utmp文件。w命令输出的信息包括:
用户名称
用户的机器名称或tty号
远程主机地址
用户登录系统的时间
空闲时间(作用不大)
附加到tty(终端)的进程所用的时间(JCPU时间)
当前进程所用时间(PCPU时间)
用户当前正在使用的命令
w命令还可以使用以下选项
-h忽略头文件信息
-u显示结果的加载时间
-s不显示JCPU, PCPU, 登录时间

2.2 使用who命令查看(登录)用户名称及所启动的进程

who命令用于列举出当前已登录系统的用户名称。其输出为:用户名、tty号、时间日期、主机地址。

输入以下命令,可以查看当前linux服务器在线用户数量:

who | wc -l

2.3 使用whoami命令查看你所使用的登录名称

whoami命令用于显示登入的用户名。

2.4 随时查看系统的历史信息(曾经使用过系统的用户信息)

last命令可用于显示特定用户登录系统的历史记录。如果没有指定任何参数,则显示所有用户的历史信息。在默认情况下,这些信息(所显示的信息)将来源于/var/log/wtmp文件。该命令的输出结果包含以下几列信息:
用户名称
tty设备号
历史登录时间日期
登出时间日期
总工作时间

可以在命令行输入“last”进行尝试。

$ last jason jason   pts/0        dev-db-server   Fri Mar 27 22:57   still logged in
jason   pts/0        dev-db-server   Fri Mar 27 22:09 - 22:54  (00:45)
jason   pts/0        dev-db-server   Wed Mar 25 19:58 - 22:26  (02:28)
jason   pts/1        dev-db-server   Mon Mar 16 20:10 - 21:44  (01:33)
jason   pts/0        192.168.201.11  Fri Mar 13 08:35 - 16:46  (08:11)
jason   pts/1        192.168.201.12  Thu Mar 12 09:03 - 09:19  (00:15)
jason   pts/0        dev-db-server   Wed Mar 11 20:11 - 20:50  (00:39)
回到顶部

3 日志搜索

3.1 命令行查看日志

  • 首先定位要查找日志的位置
lfcp@lfcp6:~> grep -n '<TxId>1919</TxId>' *.log
GW0001.log:1094194:      <TxId>1919</TxId>
lfcp@lfcp6:~> 

可以参考:Linux命令grep

  • 再根据定位的文件和行号查看相应的日志

这里是用vi或者vim命令去查看

vim GW0001.log#设置行号
:set nu#根据查到的行号跳到指定的行即可

之后就可以上下移动来查看我们要搜寻的日志了。

3.2 grep命令补充

find . -name "*.log" | xargs grep "^12405"
grep "<TxId>12426</TxId>" *.log

Linux查找文件内容的常用命令方法。 
从文件内容查找匹配指定字符串的行:
$ grep "被查找的字符串" 文件名
例子:在当前目录里第一级文件夹中寻找包含指定字符串的.in文件

grep "thermcontact" */*.in

从文件内容查找与正则表达式匹配的行:

$ grep –e “正则表达式” 文件名

查找时不区分大小写:

$ grep –i "被查找的字符串" 文件名

查找匹配的行数:

$ grep -c "被查找的字符串" 文件名

从文件内容查找不匹配指定字符串的行:

$ grep –v "被查找的字符串" 文件名

从根目录开始查找所有扩展名为.log的文本文件,并找出包含”ERROR”的行

find / -type f -name "*.log" | xargs grep "ERROR"

例子:从当前目录开始查找所有扩展名为.in的文本文件,并找出包含”thermcontact”的行

find . -name "*.in" | xargs grep "thermcontact"
回到顶部

4 linux项目部署汇总

部署步骤:

  1. 下载jdk,tomcat
  2. 配置tomcat中的java环境变量,主要是bin目录中catalina.sh文件

export JAVA_HOME=/home/simu/jdk1.7.0_67
export JRE_HOME=/home/simu/jdk1.7.0_67/jre

3.修改tomcat中conf目录下的server.xml文件

<?xml version='1.0' encoding='utf-8'?>
<!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.  See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may notdefine subcomponents such as "Valves" at this level.Documentation at /docs/config/server.html-->
<Server port="11005" shutdown="SHUTDOWN"><Listener className="org.apache.catalina.startup.VersionLoggerListener" /><!-- Security listener. Documentation at /docs/config/listeners.html<Listener className="org.apache.catalina.security.SecurityListener" />--><!--APR library loader. Documentation at /docs/apr.html --><Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /><!-- Prevent memory leaks due to use of particular java/javax APIs--><Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /><Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /><Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /><!-- Global JNDI resourcesDocumentation at /docs/jndi-resources-howto.html--><GlobalNamingResources><!-- Editable user database that can also be used byUserDatabaseRealm to authenticate users--><Resource name="UserDatabase" auth="Container"type="org.apache.catalina.UserDatabase"description="User database that can be updated and saved"factory="org.apache.catalina.users.MemoryUserDatabaseFactory"pathname="conf/tomcat-users.xml" /></GlobalNamingResources><!-- A "Service" is a collection of one or more "Connectors" that sharea single "Container" Note:  A "Service" is not itself a "Container",so you may not define subcomponents such as "Valves" at this level.Documentation at /docs/config/service.html--><Service name="Catalina"><!--The connectors can use a shared executor, you can define one or more named thread pools--><!--<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"maxThreads="150" minSpareThreads="4"/>--><!-- A "Connector" represents an endpoint by which requests are receivedand responses are returned. Documentation at :Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)Java AJP  Connector: /docs/config/ajp.htmlAPR (HTTP/AJP) Connector: /docs/apr.htmlDefine a non-SSL/TLS HTTP/1.1 Connector on port 8080--><Connector port="8090" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="11443" /><!-- A "Connector" using the shared thread pool--><!--<Connector executor="tomcatThreadPool"port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />--><!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443This connector uses the NIO implementation that requires the JSSEstyle configuration. When using the APR/native implementation, theOpenSSL style configuration is required as described in the APR/nativedocumentation --><!--<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"maxThreads="150" SSLEnabled="true" scheme="https" secure="true"clientAuth="false" sslProtocol="TLS" />--><!-- Define an AJP 1.3 Connector on port 8009 --><Connector port="11007" protocol="AJP/1.3" redirectPort="11443" /><!-- An Engine represents the entry point (within Catalina) that processesevery request.  The Engine implementation for Tomcat stand aloneanalyzes the HTTP headers included with the request, and passes themon to the appropriate Host (virtual host).Documentation at /docs/config/engine.html --><!-- You should set jvmRoute to support load-balancing via AJP ie :<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">--><Engine name="Catalina" defaultHost="localhost"><!--For clustering, please take a look at documentation at:/docs/cluster-howto.html  (simple how to)/docs/config/cluster.html (reference documentation) --><!--<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>--><!-- Use the LockOutRealm to prevent attempts to guess user passwordsvia a brute-force attack --><Realm className="org.apache.catalina.realm.LockOutRealm"><!-- This Realm uses the UserDatabase configured in the global JNDIresources under the key "UserDatabase".  Any editsthat are performed against this UserDatabase are immediatelyavailable for use by the Realm.  --><Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/></Realm><Host name="localhost"  appBase="webapps"unpackWARs="true" autoDeploy="true"><Context path="simuflcpweb" debug="0" docBase="/home/simu/service" reloadable="true"></Context><!-- SingleSignOn valve, share authentication between web applicationsDocumentation at: /docs/config/valve.html --><!--<Valve className="org.apache.catalina.authenticator.SingleSignOn" />--><!-- Access log processes all example.Documentation at: /docs/config/valve.htmlNote: The pattern used is equivalent to using pattern="common" --><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"prefix="localhost_access_log" suffix=".txt"pattern="%h %l %u %t &quot;%r&quot; %s %b" /></Host></Engine></Service>
</Server>

4.1 跨用户复制文件

前言

考虑如下情景:foo用户home目录下有一文件file.txt,要将其copy至bar用户的home目录。Linux对用户home目录有严格的权限限制,非owner用户或者同group用户无权限读写,除非是root(至高无上的root)。如果没有root权限,有什么办法把file.txt 复制到bar用户的home目录下呢?

想到两个办法

第一个办法,先用foo用户登录,把文件copy到系统临时目录/tmp,然后切换到bar用户,再从系统临时目录/tmp把文件copy到自己的home目录。这里为什么用cp不用mv?因为复制到/tmp的文件owner还是foo,默认情况下其他用户自有读权限,没有写权限(自然没有移动权限)。即使通过修改文件权限,让bar可写,移动到bar的home目录下owner还是foo,而且非得root才能改成bar。这个办法有点曲折,弊端也很明显,文件需要复制两次,花两倍的时间。

# cp file.txt /tmp/
# su - bar
# cp /tmp/file.txt ~/
# exit
# rm /tmp/file.txt

第二个办法,使用scp命令。原本scp是用来在不同主机上通过网络copy文件,用在这里刚好。用bar用户登录

# scp foo@localhost:/home/foo/file.txt ./

输入foo用户密码,开始文件传输。

也可以用foo用户登录,

# scp file.txt bar@localhost:/home/bar/ 
输入bar用户密码,过程一样。
实际中使用哪一种方法,看个人喜好了。如果要copy的文件不大,第一种方法也不失为一种选择。

下面采用第二种方法操作一遍:

simu@LFCP-6:~> ll
总用量 32
-rw------- 1 simu mqm 4546  2月  7 17:42 application.properties
-rw------- 1 simu mqm 2032  2月  7 17:42 autoDeploy.sh
drwxr-xr-x 2 simu mqm 4096 12月 16 21:23 bin
drwx------ 2 simu mqm 4096  2月  7 17:42 key
-rw------- 1 simu mqm   57  2月  7 17:42 log.sh
-rw------- 1 simu mqm   49  2月  7 17:42 startup.sh
-rw------- 1 simu mqm   61  2月  7 17:42 stop.sh
simu@LFCP-6:~> scp lfcp@localhost:/home/lfcp/simu/jdk1.7.0_67.tar ./
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is 0c:99:38:31:34:80:c3:51:ea:9d:97:b7:3d:8c:48:ad [MD5].
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Password:
jdk1.7.0_67.tar                                                                                                                   100%  282MB  93.9MB/s   00:03
simu@LFCP-6:~> ll
总用量 288672
-rw------- 1 simu mqm      4546  2月  7 17:42 application.properties
-rw------- 1 simu mqm      2032  2月  7 17:42 autoDeploy.sh
drwxr-xr-x 2 simu mqm      4096 12月 16 21:23 bin
-rw------- 1 simu mqm 295270400  2月  7 17:51 jdk1.7.0_67.tar
drwx------ 2 simu mqm      4096  2月  7 17:42 key
-rw------- 1 simu mqm        57  2月  7 17:42 log.sh
-rw------- 1 simu mqm        49  2月  7 17:42 startup.sh
-rw------- 1 simu mqm        61  2月  7 17:42 stop.sh
simu@LFCP-6:~> 
回到顶部

5 项目部署问题

5.1 基本问题

  • 问题 ——编辑配置文件,出现隐藏文件提示

在编辑tomcat的配置文件catalina.sh 时候提示发现配置文件。

这是因为,在用vim打开一个文件时,其会产生一个filename.swap文件,用于保存数据,当文件非正常关闭时,可用此文件来恢复,当正常关闭时,此文件会被删除,非正常关闭时,不会被删除,所以提示存在.swap文件,此时你可以恢复文件:
恢复以后把.swap文件删掉,在打开时就不会用提示良,注意.swap文件是个隐藏文件。可用:la查看。以.开头的是隐藏文件。
在linux下隐藏文件是以“.”开头的,单纯的使用ls命令是看不到的,加上“-a”参数才可以。删除则可以使用命令:rm -fr .*(删除当前目录下的所有隐藏文件), rm -f .tmp(删除tmp文件),rm -fr .tmp(删除tmp目录或者文件)
  • 问题——打印日志提示权限不够

这里的tomcat和jdk都直接解压而来,在输出catalina.out 日志时候,提示没有权限,实际测试时候发现相应的进程也没有启动。

使用以下方式给jdk整个目录授权

chmod -R 777 /home/simu/jdk1.7.0_67

可以通过查看进程的方式查看tomcat是否启动:

ps -ef | grep simu(进程的名字)

如果还不能够启动tomcat,尝试删除tomcat中的原有日志catalina.out.

原文见:

https://www.cnblogs.com/lixuwu/p/5854985.html

linux中项目部署和日志查看相关推荐

  1. linux tail日志命令,linux tail命令及其它日志查看命令的用法

    当日志文件存储日志很大时,我们就不能用vi直接进去查看日志,需要Linux的命令去完成我们的查看任务. Log位置: /var/log/message 系统启动后的信息和错误日志,是Red Hat L ...

  2. Linux系统之部署Rsyslog 日志服务器

    Linux系统之部署Rsyslog 日志服务器 一.检查服务器系统版本 二.在master节点上配置 1.修改/etc/rsyslog.conf 2.开启日志服务 3.查看日志服务状态 4.关闭防火墙 ...

  3. 【Linux】Linux中的文件搜索和查看

    Linux中的文件搜索和查看 Linux中的文件搜索和查看 cat head tail more less grep sed vim Linux中的文件搜索和查看 cat cat 命令用于连接文件并打 ...

  4. 查看eclipse中项目部署位置

    一.问题描述 在eclipse中开发web项目,会使用tomcat部署,如何查看项目部署位置呢 二.操作 红框为项目部署的位置 2.1 查看当前项目工作区(workspace) 路径1+路径2为项目部 ...

  5. centos7 如何安装部署k8s_架构运维篇(五):Centos7/Linux中安装部署RocketMQ

    上一篇 架构运维篇(四):Centos7/Linux中Tomcat安装SSL证书实践 这一篇讲一下在Centos7/Linux安装RocketMQ,MQ的具体应用场景和使用就不再啰嗦了.我在没有使用过 ...

  6. Linux中shell的分类以及查看当前的shell

    DOS/Windows 与 Linux 的最重要的区别之一是 Linux 的命令 shell 是与操作系统相分离的一层. 目前流行的shell有ash.bash.ksh.csh.zsh,如下介绍: b ...

  7. linux鉴于它没有文件拓展名,linux中的文件类型以及查看文件类型的方法

    Linux文件类型和文件的文件名所代表的意义是两个不同的概念,在linux中文件类型与文件扩展名没有关系.它不像Windows那样是依靠文件后缀名来区分文件类型的,在linux中文件名只是为了方便操作 ...

  8. 【阿里云 Linux 服务器】购买 Linux 到项目部署过程中遇到的问题,部署 SpringBoot 项目到服务器上,在手机上安装 Android 程序进行测试

    文章目录 一.购买好服务器之后要重置密码 二.利用 putty 程序登录访问你的服务器 三.配置安全组开放端口 四.部署项目前期准备工作 4.1 安装 Java 4.2 安装 mysql 4.3 安装 ...

  9. linux中tomcat部署项目步骤以及命令

    一.先把项目从本地打包,放到linux服务器上面 用maven install 之后,我放的是文件夹不是war包,因为如果后期代码修改不大,像修改某一个class文件或者某一个配置文件的话,可以直接在 ...

最新文章

  1. oracle ORA-00119和ORA-00132解决方法
  2. FreeMarker 语法 include 引用模板
  3. 第一段冲刺_个人总结_5.10
  4. 密码学系列之:加密货币中的scrypt算法
  5. 【人脸对齐-Landmarks】人脸对齐算法常用评价标准
  6. 蘑菇街2019校招题目总结
  7. java判断long 大于0_JAVA的一道习题:找出五个大于Long.MAX_VALUE的素数
  8. Matlab相关工具箱下载地址汇总
  9. 手机进程多了,有的进程就无法联网?
  10. 云栖回顾|龙蜥论坛圆桌环节都有哪些精彩观点?
  11. 外卖侠4.24源码全插件cps使用教程【干货】
  12. 材料表征技术书籍-7本
  13. [转载]自动化行业信讯_史蒂文森sun_新浪博客
  14. MySQL 清除表空间碎片
  15. 2009年最值得注意炒作题材
  16. 旋度的散度恒为0(公式推导)
  17. 浏览器页签icon图标的设置和获取
  18. 如何利用无线技术有效预化工厂防爆炸事故?
  19. 2021 年最值得推荐的 5 门人工智能编程语言
  20. 对梯度幅值进行非极大值抑制

热门文章

  1. c语言中指数优化,西藏东财中证医药卫生指数C净值下跌1.96% 请保持关注
  2. python数据库实例_Python操作MySQL数据库9个实用实例
  3. python输出星号_Python的星号(*、**)的作用
  4. python3中format函数列表_Python3之字符串格式化format函数详解(上)
  5. 【Python学习】 - sklearn学习 - 数据集分割方法 - 随机划分与K折交叉划分与StratifiedKFold与StratifiedShuffleSplit
  6. 【CodeForces - 789D】Weird journey(思维,图的性质,tricks,有坑)
  7. 【POJ - 3723】Conscription (最大生成树,最小生成树MST变形)
  8. 【POJ - 2349】【UVA - 10369】 Arctic Network(最小生成树求权值第k大的边)(内附两种算法)
  9. Apollo进阶课程㊲丨Apollo自动驾驶架构介绍
  10. mysql innodb id_MySQL InnoDB row_id边界溢出验证的方法步骤