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 - 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/        dev-db-server   Fri Mar  :   still logged in
jason pts/ dev-db-server Fri Mar : - : (:)
jason pts/ dev-db-server Wed Mar : - : (:)
jason pts/ dev-db-server Mon Mar : - : (:)
jason pts/ 192.168.201.11 Fri Mar : - : (:)
jason pts/ 192.168.201.12 Thu Mar : - : (:)
jason pts/ dev-db-server Wed Mar : - : (:)

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 more
contributor license agreements. See the NOTICE file distributed with
this 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 with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed 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 and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define 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 resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm 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 share
a 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 received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
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="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 8443
This connector uses the NIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<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 processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on 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 passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available 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 applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
--> <!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: 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-:~> ll
总用量
-rw------- simu mqm 2月 : application.properties
-rw------- simu mqm 2月 : autoDeploy.sh
drwxr-xr-x simu mqm 12月 : bin
drwx------ simu mqm 2月 : key
-rw------- simu mqm 2月 : log.sh
-rw------- simu mqm 2月 : startup.sh
-rw------- simu mqm 2月 : stop.sh
simu@LFCP-:~> 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::::::c3::ea:9d::b7:3d:8c::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..0_67.tar % 282MB .9MB/s :
simu@LFCP-:~> ll
总用量
-rw------- simu mqm 2月 : application.properties
-rw------- simu mqm 2月 : autoDeploy.sh
drwxr-xr-x simu mqm 12月 : bin
-rw------- simu mqm 2月 : jdk1..0_67.tar
drwx------ simu mqm 2月 : key
-rw------- simu mqm 2月 : log.sh
-rw------- simu mqm 2月 : startup.sh
-rw------- simu mqm 2月 : stop.sh
simu@LFCP-:~>

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  /home/simu/jdk1..0_67

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

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

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

w

(转)linux中项目部署和日志查看的更多相关文章

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

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

  2. [转帖]Linux教程(8)-Linux中的进程和日志㐇、

    Linux教程(8)-Linux中的进程和日志 2018-08-20 23:42:23 钱婷婷 阅读数 3554更多 分类专栏: Linux教程与操作 Linux教程与使用   版权声明:本文为博主原 ...

  3. SPARK在linux中的部署,以及SPARK中聚类算法的使用

    眼下,SPARK在大数据处理领域十分流行.尤其是对于大规模数据集上的机器学习算法.SPARK更具有优势.一下初步介绍SPARK在linux中的部署与使用,以及当中聚类算法的实现. 在官网http:// ...

  4. Linux Django项目部署

    步骤 .数据库的处理 1.1 上传bbs.sql 1.2 在mysql中创建bbs库,并导入数据库SQL脚本 mysql> create database bbs charset utf8mb4 ...

  5. linux服务器项目部署【完整版】

    之前总玩v8虚拟机,最近看到腾讯云学生套餐很实惠就租了个linux服务器搭一个项目,做下这个项目部署全记录,即为了方便以后查看,同时也分享下自己的经验,不足之处还请多多指教,废话不多说,直接开始!!! ...

  6. 2016.6.21 将Eclipse中项目部署到tomcat下

    新建的web项目,各种都配置好,选择run on server之后,发现运行失败,并不能访问需要的网址.而脱离eclipse,将生成的war文件直接放到tomcat的webapp下时,可以正常访问.所 ...

  7. linux --- 6. 项目部署

    一.负载均衡 .准备三台机器,准备3台虚拟机,或者和俩同桌交流一下 192.168.226.128 是nginx资源服务器,返回页面的 192.168.226.129 用作nginx负载均衡服务器 1 ...

  8. linux中的文件类型以及查看文件类型的方法

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

  9. k8s中pod的容器日志查看命令

    如果容器已经崩溃停止,您可以仍然使用 kubectl logs --previous 获取该容器的日志,只不过需要添加参数 --previous. 如果 Pod 中包含多个容器,而您想要看其中某一个容 ...

随机推荐

  1. Java代码编写规范(不是标准规范,自行整理,无须纠结)

    最近回过头来给以前的项目增加功能,发现之前写的注释非常不全,代码也非常的不整洁,有些地方写的''窝七八烂的,看着很不舒服:又恰好经理最近也经常跟我提起代码规范,我们就讨论了一下代码规范的重要性和必要性 ...

  2. [附录]Discuz X2.5 模板目录结构注释说明

    /template/default/common  公共模板目录全局加载 block_forumtree.htm  DIY论坛树形列表模块 block_thread.htm  DIY帖子模块调用文件 ...

  3. Spring+SpringMVC+MyBatis深入学习及搭建(十二)——SpringMVC入门程序(一)

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6999743.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十一)——S ...

  4. HTTP协议 URL

    http(超文本传输协议)是一个基于请求与响应模式的.无状态的.应用层的协议,常基于TCP的连接方式,HTTP1.1版本中给出一种持续连接的机制,绝大多数的Web开发,都是构建在HTTP协议之上的We ...

  5. 移动端车牌识别、行驶证识别OCR为共享汽车APP增添技术色彩

    本文主题:移动端车牌识别.行驶证识别OCR为共享汽车APP增添技术色彩 本文关键词:车牌识别,证件识别,移动端车牌识别,行驶证识别,手机车牌识别,驾驶证识别 近两年,随着共享单车以及共享电车的兴起,有 ...

  6. javascript所有的节点和方法

    属性: 1.Attributes 存储节点的属性列表(只读) 2.childNodes 存储节点的子节点列表(只读) 3.dataType 返回此节点的数据类型 4.Definition 以DTD或X ...

  7. mysql update 批量更新

    UPDATE cntheater SET title = (SELECT title FROM cntheater_copy WHERE cntheater.id = cntheater_copy.i ...

  8. php中的XML转数组

    /** * 最简单的XML转数组 * @param string $xmlstring XML字符串 * @return array XML数组 */ function simplest_xml_to ...

  9. angularjs directive (自定义标签解析)

    angularjs directive (自定义标签解析) 定义tpl <!-- 注意要有根标签 --> <div class="list list-inset" ...

  10. Idea调试显示切换数据源的设置

    使用IDEA调试时,如果遇到相同方法会在编辑器上提示切换到哪个项目,因为手滑点了Disable,所以导致后来就不提示了,记录下设置方法.