作为后台开发,需要部署你的项目,通常的项目部署环境都是centOS,因此要学习一定的Linux命令,本文整理后台开发常用的一些linux命令,并不全面深入学习linux,以后深入钻研后再整理全面。
一、Linux的简介
1.Linux的概述
Linux是基于Unix的开源免费的操作系统,由于系统的稳定性和安全性几乎成为程序代码运行的最佳系统环境。Linux是由Linus Torvalds(林纳斯·托瓦兹)起初开发的,由于源代码的开放性,现在已经衍生出了千上百种不同的Linux系统。
Linux系统的应用非常广泛,不仅可以长时间的运行我们编写的程序代码,还可以安装在各种计算机硬件设备中,比如手机、平板电脑、路由器等。尤其在这里提及一下,我们熟知是Android程序最底层就是运行在linux系统上的。
2.Linux的分类
(1)Linux根据市场需求不同,基本分为两个方向:
1)图形化界面版:注重用户体验,类似window操作系统,但目前成熟度不够
2)服务器版:没有好看的界面,是以在控制台窗口中输入命令操作系统的,类似 于DOS,是我们假设服务器的最佳选择
(2)Linux根据原生程度,又分为两种:
1)内核版本:在Linus领导下的内核小组开发维护的系统内核的版本号
2)发行版本:一些组织或公司在内核版基础上进行二次开发而重新发行的版本
(3)Linux发行版本不同,又可以分为n多种:
其中,服务器常用的是CentOS,安装过程百度有很多,可以安装在VMWare等虚拟机中,或者购阿里云、腾讯云等服务器,可以选择系统,选择CentOS后会自动帮你安装好。安装好后可以使用Xshell等远程工具,方便高效。可以下载破解版,附一个别人的下载路径http://www.pc6.com/softview/SoftView_14993.html,来连接使用
二、Linux的基本命令
安装好Linux,登录成功后会提示如下信息
Last failed login: Thu May 30 15:03:41 CST 2019 from 40.73.39.211 on ssh:notty
There were 10 failed login attempts since the last successful login.
Last login: Thu May 30 10:20:58 2019 from 222.95.223.120
[root@VM_0_16_centos ~]#
如果出现此代码说明登录成功,然后就可以开始操作Linux了。
此时我们处在用户主目录文件夹root下,可以通过pwd
来查看我们的文件路径
[root@VM_0_16_centos ~]# pwd
/root
[root@VM_0_16_centos ~]#
通过ls
可以查看当前文件夹下的所有文件
Tab键是快速补齐键,具体怎么用百度。
1.目录切换命令
window中通过图形化界面和鼠标可以任意切换需要进入的目录,但Linux必须通过cd命令切换目录。但在学习cd命令之前,我们有必要分清Linux的目录结构
cd usr 切换到该目录下usr目录
cd ../ 切换到上一层目录
cd / 切换到系统根目录
cd ~ 切换到用户主目录
cd - 切换到上一个所在目录
注意: /表示根目录, ./表示当前目录, …/表示上一层目录, …/…/表示上两层目录,同理。。。
[root@VM_0_16_centos bin]# cd /
[root@VM_0_16_centos /]# ls
bin data etc lib logs media opt root sbin sys usr
boot dev home lib64 lost+found mnt proc run srv tmp var
[root@VM_0_16_centos /]# cd dev
[root@VM_0_16_centos dev]#
第一步转到根目录下,ls查询当前路径下所有的文件,cd切换到dev文件夹下
2.目录的操作命令(增删改查)
(1)增加目录操作(增)
命令:mkdir 目录名称
示例:在根目录 / 下 mkdir test,就会在根目录 / 下产生一个test目录
[root@VM_0_16_centos /]# mkdir test
[root@VM_0_16_centos /]# ls
bin data etc lib logs media opt root sbin sys tmp var
boot dev home lib64 lost+found mnt proc run srv test usr
[root@VM_0_16_centos /]#
从上面可以看到已经创建了一个名叫test的文件夹
(2)查看目录(查)
命令:ls [-al] 父目录
示例:在根目录 / 下使用ls,可以看到该目录下的所有的目录和文件
示例:在根目录 / 下使用ls -a,可以看到该目录下的所有文件和目录,包括隐藏的
[root@VM_0_16_centos /]# ls -a
. bin data etc lib logs media opt root sbin sys tmp var
.. boot dev home lib64 lost+found mnt proc run srv test usr
[root@VM_0_16_centos /]#
. 和 … 表示隐藏的文件
示例:在根目录 / 下使用ls -l,可以看到该目录下的所有目录和文件的详细信息
[root@VM_0_16_centos /]# ls -l
total 72
lrwxrwxrwx. 1 root root 7 Aug 8 2018 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 Dec 12 09:16 boot
drwxr-xr-x 4 root root 4096 Nov 24 2018 data
drwxr-xr-x 19 root root 2980 Dec 12 09:47 dev
drwxr-xr-x. 85 root root 4096 Dec 12 17:03 etc
drwxr-xr-x. 2 root root 4096 Nov 24 2018 home
lrwxrwxrwx. 1 root root 7 Aug 8 2018 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Aug 8 2018 lib64 -> usr/lib64
drwxr-x--- 2 root root 4096 Dec 12 17:32 logs
drwx------. 2 root root 16384 Aug 8 2018 lost+found
drwxr-xr-x. 2 root root 4096 Apr 11 2018 media
drwxr-xr-x. 2 root root 4096 Apr 11 2018 mnt
drwxr-xr-x. 3 root root 4096 Aug 8 2018 opt
dr-xr-xr-x 92 root root 0 Dec 12 09:47 proc
dr-xr-x---. 7 root root 4096 May 29 21:18 root
drwxr-xr-x 23 root root 840 May 29 22:41 run
lrwxrwxrwx. 1 root root 8 Aug 8 2018 sbin -> usr/sbin
drwxr-xr-x. 2 root root 4096 Apr 11 2018 srv
dr-xr-xr-x 13 root root 0 May 29 16:58 sys
drwxr-xr-x 2 root root 4096 May 30 15:57 test
drwxrwxrwt. 9 root root 4096 May 30 15:56 tmp
drwxr-xr-x. 13 root root 4096 Aug 8 2018 usr
drwxr-xr-x. 19 root root 4096 Aug 13 2018 var
[root@VM_0_16_centos /]#
注意:ls -l 可以缩写成ll
(3)寻找目录(查)
命令:find 目录 参数
示例:查找/etc 下的与test相关的目录(文件) find /root -name ‘test*’
[root@VM_0_16_centos /]# find /etc -name '*test*'
/etc/yum/pluginconf.d/fastestmirror.conf
[root@VM_0_16_centos /]#
查找根目录下的etc 目录下 名字包含test的文件, *表示任意字符
(4)修改目录的名称(改)
命令:mv 目录名称 新目录名称
示例:根目录下的test改为newtest,使用mv test newtest命令修改
[root@VM_0_16_centos /]# mv test newtest
[root@VM_0_16_centos /]# ls
bin data etc lib logs media newtest proc run srv tmp var
boot dev home lib64 lost+found mnt opt root sbin sys usr
[root@VM_0_16_centos /]#
注意:mv的语法不仅可以对目录进行重命名而且也可以对各种文件,压缩包等进行 重命名的操作
(5)移动目录的位置—剪切(改)
命令:mv 目录名称 目录的新位置
示例:在根目录下将newtest目录剪切到 /test下面,使用mv newtest /test
[root@VM_0_16_centos /]# mkdir test
[root@VM_0_16_centos /]# mv newtest /test
[root@VM_0_16_centos /]# ls
bin data etc lib logs media opt root sbin sys tmp var
boot dev home lib64 lost+found mnt proc run srv test usr
[root@VM_0_16_centos /]# cd test
[root@VM_0_16_centos test]# ls
newtest
[root@VM_0_16_centos test]#
先重新创建一个test,然后再把newtest移动到test中
注意:mv语法不仅可以对目录进行剪切操作,对文件和压缩包等都可执行剪切操作
(6)拷贝目录(改)
命令:cp -r 目录名称 目录拷贝的目标位置 -----r代表递归拷贝
示例:将/test下的newtest拷贝到根目录下,使用 cp -r newtest /
[root@VM_0_16_centos test]# cp -r newtest /
[root@VM_0_16_centos test]# ls
newtest
[root@VM_0_16_centos test]# cd /
[root@VM_0_16_centos /]# ls
bin data etc lib logs media newtest proc run srv test usr
boot dev home lib64 lost+found mnt opt root sbin sys tmp var
[root@VM_0_16_centos /]#
可以看到test和根目录下都有newtest目录
(7)删除目录(删)
命令:rm [-rf] 目录
示例:删除newtest,进入/usr下使用rm -r newtest
[root@VM_0_16_centos /]# rm -r newtest
rm: descend into directory ‘newtest’? y
rm: remove regular empty file ‘newtest/asd.txt’? y
rm: remove directory ‘newtest/aaa’? y
rm: remove directory ‘newtest’? y
[root@VM_0_16_centos /]# ls
bin data etc lib logs media opt root sbin sys tmp var
boot dev home lib64 lost+found mnt proc run srv test usr
[root@VM_0_16_centos /]#
因为我的newtest下创建了asd.txt和aaa两个文件,因此使用rm -r删除的时候会一一询问是否要删除齐下的子文件,如果要删除也输入 y 然后回车即可。
示例:删除/test下的newtest而不需要询问强制删除,在/test下使用rm -rf newtest
[root@VM_0_16_centos /]# cd test/
[root@VM_0_16_centos test]# ls
newtest
[root@VM_0_16_centos test]# rm -rf newtest
[root@VM_0_16_centos test]# ls
[root@VM_0_16_centos test]#
直接删除,没有任何询问和提示。
注意:rm不仅可以删除目录,也可以删除其他文件或压缩包,为了增强大家的记忆, 无论删除任何目录或文件,都直接使用rm -rf 目录/文件/压缩包
3.文件的操作命令(增删改查)
Linux系统并没有文件扩展名一说,之所以创建文件带扩展名是为了方便用户查看。
(1)文件的创建(增)
命令:touch 文件名称 ----- 空文件
示例:先把etc下的sudo.conf文件
[root@VM_0_16_centos test]# touch asd.txt
[root@VM_0_16_centos test]# ls
asd.txt
[root@VM_0_16_centos test]#
(2)文件的查看(查)
命令:cat/more/less/tail 文件
示例:先把根目录下的etc里的sudo.conf 文件拷贝一份到/test下,然后使用cat查看
[root@VM_0_16_centos etc]# cp sudo.conf /test/
[root@VM_0_16_centos etc]# cd /test
[root@VM_0_16_centos test]# ls
asd.txt sudo.conf
[root@VM_0_16_centos test]# cat sudo.conf
#
# Default /etc/sudo.conf file
#
# Format:
# Plugin plugin_name plugin_path plugin_options ...
# Path askpass /path/to/askpass
# Path noexec /path/to/sudo_noexec.so
# Debug sudo /var/log/sudo_debug all@warn
# Set disable_coredump true
#
# Sudo plugins:
#
# The plugin_path is relative to ${prefix}/libexec unless fully qualified.
# The plugin_name corresponds to a global symbol in the plugin
# that contains the plugin interface structure.
# The plugin_options are optional.
#
# The sudoers plugin is used by default if no Plugin lines are present.
Plugin sudoers_policy sudoers.so
Plugin sudoers_io sudoers.so
#
# Sudo askpass:
#
# An askpass helper program may be specified to provide a graphical
# password prompt for "sudo -A" support. Sudo does not ship with its
# own passpass program but can use the OpenSSH askpass.
#
# Use the OpenSSH askpass
#Path askpass /usr/X11R6/bin/ssh-askpass
#
# Use the Gnome OpenSSH askpass
#Path askpass /usr/libexec/openssh/gnome-ssh-askpass
#
# Sudo noexec:
#
# Path to a shared library containing dummy versions of the execv(),
# execve() and fexecve() library functions that just return an error.
# This is used to implement the "noexec" functionality on systems that
# support C or its equivalent.
# The compiled-in value is usually sufficient and should only be changed
# if you rename or move the sudo_noexec.so file.
#
#Path noexec /usr/libexec/sudo_noexec.so
#
# Core dumps:
#
# By default, sudo disables core dumps while it is executing (they
# are re-enabled for the command that is run).
# To aid in debugging sudo problems, you may wish to enable core
# dumps by setting "disable_coredump" to false.
#
# Set to false here so as not to interfere with /proc/sys/fs/suid_dumpable
#
Set disable_coredump false
[root@VM_0_16_centos test]#
示例:使用more查看sudo.conf文件,可以显示百分比,回车可以向下一行,空格可以向下一页,q可以退出查看
[root@VM_0_16_centos test]# more sudo.conf
#
# Default /etc/sudo.conf file
#
# Format:
# Plugin plugin_name plugin_path plugin_options ...
# Path askpass /path/to/askpass
# Path noexec /path/to/sudo_noexec.so
# Debug sudo /var/log/sudo_debug all@warn
# Set disable_coredump true
#
# Sudo plugins:
#
# The plugin_path is relative to ${prefix}/libexec unless fully qualified.
# The plugin_name corresponds to a global symbol in the plugin
# that contains the plugin interface structure.
# The plugin_options are optional.
#
# The sudoers plugin is used by default if no Plugin lines are present.
Plugin sudoers_policy sudoers.so
Plugin sudoers_io sudoers.so
#
# Sudo askpass:
#
# An askpass helper program may be specified to provide a graphical
# password prompt for "sudo -A" support. Sudo does not ship with its
# own passpass program but can use the OpenSSH askpass.
#
# Use the OpenSSH askpass
#Path askpass /usr/X11R6/bin/ssh-askpass
#
# Use the Gnome OpenSSH askpass
--More--(52%)
示例:使用less查看sudo.conf文件,可以使用键盘上的PgUp和PgDn向上和向下翻页,q结束查看
[root@VM_0_16_centos test]# less sudo.conf
#
# Default /etc/sudo.conf file
#
# Format:
# Plugin plugin_name plugin_path plugin_options ...
# Path askpass /path/to/askpass
# Path noexec /path/to/sudo_noexec.so
# Debug sudo /var/log/sudo_debug all@warn
# Set disable_coredump true
#
# Sudo plugins:
#
# The plugin_path is relative to ${prefix}/libexec unless fully qualified.
# The plugin_name corresponds to a global symbol in the plugin
# that contains the plugin interface structure.
# The plugin_options are optional.
#
# The sudoers plugin is used by default if no Plugin lines are present.
Plugin sudoers_policy sudoers.so
Plugin sudoers_io sudoers.so
#
# Sudo askpass:
#
# An askpass helper program may be specified to provide a graphical
# password prompt for "sudo -A" support. Sudo does not ship with its
# own passpass program but can use the OpenSSH askpass.
#
# Use the OpenSSH askpass
#Path askpass /usr/X11R6/bin/ssh-askpass
#
sudo.conf
示例:使用tail -10 查看sudo.conf文件的后10行,Ctrl+C结束
[root@VM_0_16_centos test]# tail -10 sudo.conf
# Core dumps:
#
# By default, sudo disables core dumps while it is executing (they
# are re-enabled for the command that is run).
# To aid in debugging sudo problems, you may wish to enable core
# dumps by setting "disable_coredump" to false.
#
# Set to false here so as not to interfere with /proc/sys/fs/suid_dumpable
#
Set disable_coredump false
[root@VM_0_16_centos test]#
注意:命令 tail -f 文件 可以对某个文件进行动态监控,例如tomcat的日志文件,会随着程序的运行,日志会变化,可以使用tail -f catalina-2016-11-11.log 监控文件的变化
通常使用cat查看文件,tail -n来查看tomcat日志文件。
(3)修改文件的内容(改)
命令:vim 文件
示例:编辑/test下的asd.txt文件,使用vim asd.txt;但此时并不能编辑,因为此时处于命令模式,点击键盘i/a/o进入编辑模式,可以编辑文件,编辑完成后,按下Esc,退回命令模式;此时文件虽然已经编辑完成,但是没有保存,需输入 冒号: 进入底行模式,在底行模式下输入wq代表写入内容并退出,即保存;输入**q!**代表强制退出不保存。
[root@VM_0_16_centos test]# vim asd.txt
进入vim编辑器,然后按下i进入编辑模式,编辑完成后按 ESC 退出编辑模式,按:进入底行模式,然后输入wq回车,即可保存并退出,然后查看该文件就可以发现已经编辑了内容
[root@VM_0_16_centos test]# cat asd.txt
this is asd, use vim to edit it !
[root@VM_0_16_centos test]#
总结:
vim编辑器是Linux中的强大组件,是vi编辑器的加强版,vim编辑器的命令和快捷方式有很多,但此处不一一阐述,等写完这篇会再加两篇vi使用方法详细介绍和vim命令合集。
关于vim使用过程:
在实际开发中,使用vim编辑器主要作用就是修改配置文件
vim 文件------>进入文件----->命令模式------>按i进入编辑模式----->编辑文件 ------->按Esc进入底行模式----->输入:wq/q!
(4)删除文件(删)
同目录删除:熟记 rm -rf 文件 即可
4.压缩文件的操作命令
(1)打包并压缩文件
Linux中的打包文件一般是以.tar结尾的,压缩的命令一般是以.gz结尾的。
而一般情况下打包和压缩是一起进行的,打包并压缩后的文件的后缀名一般**.tar.gz**
命令:tar -zcvf 打包压缩后的文件名 要打包压缩的文件
其中:z:调用gzip压缩命令进行压缩
c:打包文件
v:显示运行过程
f:指定文件名
示例:打包并压缩/test下的所有文件 压缩后的压缩包指定名称为test.tar.gz
tar -zcvf test.tar.gz asd.txt sudo.conf
或:(如果就是在test当前目录下的操作) tar -zcvf testXX.tar.gz ./*
或:(如果是在根目录下的操作)tar -zcvf testXX.tar.gz /test/*
[root@VM_0_16_centos test]# tar -zcvf test.tar.gz asd.txt sudo.conf
asd.txt
sudo.conf
[root@VM_0_16_centos test]# ls
asd.txt sudo.conf test.tar.gz
[root@VM_0_16_centos test]#
[root@VM_0_16_centos test]# tar -zcvf testXX.tar.gz ./*
./asd.txt
./sudo.conf
./test.tar.gz
[root@VM_0_16_centos test]# ls
asd.txt sudo.conf test.tar.gz testXX.tar.gz
[root@VM_0_16_centos test]#
(2)解压压缩包(重点)
命令:tar [-xvf] 压缩文件
其中:x:代表解压
示例:将/test下的test.tar.gz解压到当前目录下
tar -xvf test.tar.gz
[root@VM_0_16_centos test]# tar -xvf test.tar.gz
asd.txt
sudo.conf
[root@VM_0_16_centos test]# ls
asd.txt sudo.conf test.tar.gz testXX.tar.gz
[root@VM_0_16_centos test]#
示例:将/test下的test.tar.gz解压到根目录/test/aaa下
tar -xvf test.tar.gz -C ./aaa------C代表指定解压的位置 (注意是大写的C)
[root@VM_0_16_centos test]# mkdir aaa
[root@VM_0_16_centos test]# ls
aaa asd.txt sudo.conf test.tar.gz testXX.tar.gz
[root@VM_0_16_centos test]# tar -xvf test.tar.gz -C ./aaa
asd.txt
sudo.conf
[root@VM_0_16_centos test]# cd aaa
[root@VM_0_16_centos aaa]# ls
asd.txt sudo.conf
[root@VM_0_16_centos aaa]#
5.其他命令
(1)显示当前所在位置 pwd
[root@VM_0_16_centos aaa]# pwd
/test/aaa
[root@VM_0_16_centos aaa]#
(2)搜索命令
命令:grep 要搜索的字符串 要搜索的文件
示例:搜索/test/sudu.conf文件中包含字符串to的行
[root@VM_0_16_centos aaa]# cd ../
[root@VM_0_16_centos test]# grep to sudo.conf
# Path askpass /path/to/askpass
# Path noexec /path/to/sudo_noexec.so
# The plugin_path is relative to ${prefix}/libexec unless fully qualified.
# The plugin_name corresponds to a global symbol in the plugin
# An askpass helper program may be specified to provide a graphical
# Path to a shared library containing dummy versions of the execv(),
# This is used to implement the "noexec" functionality on systems that
# To aid in debugging sudo problems, you may wish to enable core
# dumps by setting "disable_coredump" to false.
# Set to false here so as not to interfere with /proc/sys/fs/suid_dumpable
[root@VM_0_16_centos test]#
示例:搜索/test/sudu.conf文件中包含字符串to的行 to要高亮显示 grep to sudo.conf --color
(3)查看进程
命令:ps -ef
示例:查看当前系统中运行的进程
[root@VM_0_16_centos test]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 2018 ? 00:13:29 /usr/lib/systemd/systemd --switched
root 2 0 0 2018 ? 00:00:00 [kthreadd]
root 3 2 0 2018 ? 00:02:16 [ksoftirqd/0]
root 5 2 0 2018 ? 00:00:00 [kworker/0:0H]
root 7 2 0 2018 ? 00:00:00 [migration/0]
root 8 2 0 2018 ? 00:00:00 [rcu_bh]
root 9 2 0 2018 ? 00:13:05 [rcu_sched]
root 10 2 0 2018 ? 00:00:00 [lru-add-drain]
root 11 2 0 2018 ? 00:01:16 [watchdog/0]
root 13 2 0 2018 ? 00:00:00 [kdevtmpfs]
root 14 2 0 2018 ? 00:00:00 [netns]
root 15 2 0 2018 ? 00:00:05 [khungtaskd]
root 16 2 0 2018 ? 00:00:00 [writeback]
root 17 2 0 2018 ? 00:00:00 [kintegrityd]
root 18 2 0 2018 ? 00:00:00 [bioset]
root 19 2 0 2018 ? 00:00:00 [bioset]
root 20 2 0 2018 ? 00:00:00 [bioset]
root 21 2 0 2018 ? 00:00:00 [kblockd]
root 22 2 0 2018 ? 00:00:00 [md]
root 23 2 0 2018 ? 00:00:00 [edac-poller]
root 29 2 0 2018 ? 00:00:46 [kswapd0]
root 30 2 0 2018 ? 00:00:00 [ksmd]
root 31 2 0 2018 ? 00:00:21 [khugepaged]
root 32 2 0 2018 ? 00:00:00 [crypto]
root 40 2 0 2018 ? 00:00:00 [kthrotld]
root 42 2 0 2018 ? 00:00:00 [kmpath_rdacd]
root 43 2 0 2018 ? 00:00:00 [kaluad]
root 44 2 0 2018 ? 00:00:00 [kpsmoused]
root 45 2 0 2018 ? 00:00:00 [ipv6_addrconf]
root 58 2 0 2018 ? 00:00:00 [deferwq]
root 95 2 0 2018 ? 00:00:35 [kauditd]
root 221 2 0 2018 ? 00:02:36 [kworker/0:1H]
root 226 2 0 2018 ? 00:00:00 [ata_sff]
root 230 2 0 2018 ? 00:00:00 [scsi_eh_0]
root 232 2 0 2018 ? 00:00:00 [scsi_tmf_0]
root 233 2 0 2018 ? 00:00:00 [scsi_eh_1]
root 234 2 0 2018 ? 00:00:00 [scsi_tmf_1]
root 241 2 0 2018 ? 00:00:00 [ttm_swap]
root 253 2 0 2018 ? 00:05:35 [jbd2/vda1-8]
root 254 2 0 2018 ? 00:00:00 [ext4-rsv-conver]
root 328 1 0 2018 ? 00:22:28 /usr/lib/systemd/systemd-journald
root 353 1 0 2018 ? 00:00:00 /usr/sbin/lvmetad -f
root 356 1 0 2018 ? 00:00:00 /usr/lib/systemd/systemd-udevd
root 484 1 0 2018 ? 00:04:07 /sbin/auditd
libstor+ 508 1 0 2018 ? 00:00:30 /usr/bin/lsmd -d
polkitd 509 1 0 2018 ? 00:04:27 /usr/lib/polkit-1/polkitd --no-debu
root 512 1 0 2018 ? 00:06:23 /usr/lib/systemd/systemd-logind
dbus 514 1 0 2018 ? 00:14:41 /usr/bin/dbus-daemon --system --add
root 516 1 0 2018 ? 00:00:00 /usr/sbin/acpid
ntp 518 1 0 2018 ? 00:00:12 /usr/sbin/ntpd -u ntp:ntp -g
root 741 1 0 2018 ? 00:00:00 /usr/sbin/atd -f
root 742 1 0 2018 ? 00:01:34 /usr/sbin/crond -n
root 806 1 0 2018 ? 00:00:00 /sbin/dhclient -q -lf /var/lib/dhcl
root 883 1 0 2018 ? 00:28:02 /usr/bin/python -Es /usr/sbin/tuned
root 885 1 0 2018 ? 00:22:13 /usr/sbin/rsyslogd -n
root 908 1 0 2018 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld
root 1062 1 0 2018 ttyS0 00:00:00 /sbin/agetty --keep-baud 115200 384
mysql 1123 908 0 2018 ? 01:35:20 /usr/local/mysql/bin/mysqld --based
root 1463 1 0 2018 ? 00:01:59 /usr/local/qcloud/stargate/sgagent
root 1518 1 0 2018 ? 00:36:42 /usr/local/qcloud/YunJing/YDLive/YD
root 4636 7196 0 15:36 ? 00:00:00 sshd: root@pts/0
root 4643 4636 0 15:36 pts/0 00:00:00 -bash
root 7196 1 0 2018 ? 00:04:31 /usr/sbin/sshd -D
root 7285 2 0 May29 ? 00:00:00 [kworker/u2:0]
root 10532 1 0 2018 ? 05:53:35 /usr/local/java/jdk1.8.0_191/bin/ja
root 11076 1 0 2018 ? 00:00:00 login -- root
root 11089 11076 0 2018 tty1 00:00:00 -bash
root 12115 1 0 2018 tty3 00:00:00 /sbin/agetty --noclear tty3 linux
root 12122 1 0 2018 tty4 00:00:00 /sbin/agetty --noclear tty4 linux
root 12123 1 0 2018 ? 00:00:00 login -- root
root 12139 12123 0 2018 tty5 00:00:00 -bash
root 14873 2 0 May28 ? 00:00:05 [kworker/u2:2]
root 16053 2 0 17:03 ? 00:00:00 [kworker/0:2]
root 16721 2 0 17:08 ? 00:00:00 [kworker/0:0]
root 17375 2 0 17:13 ? 00:00:00 [kworker/0:1]
root 17523 4643 0 17:14 pts/0 00:00:00 ps -ef
root 24044 1 0 Jan21 ? 03:24:34 /usr/local/java/jdk1.8.0_191/bin/ja
root 29241 1 0 May04 ? 01:19:06 /usr/local/qcloud/YunJing/YDEyes/YD
root 32514 1 0 May29 ? 00:00:01 barad_agent
root 32520 32514 0 May29 ? 00:00:41 barad_agent
root 32521 32514 0 May29 ? 00:03:54 barad_agent
(4)杀死进程(请勿轻易尝试,否则系统出现问题概不负责!!!!)
命令:kill -9 进程的pid
示例:杀死上面pid为32521的进程,kill -9 32521
9表示传递给进程的信号是9,即强制、尽快终止进程。
请勿轻易尝试,否则系统出现问题概不负责!!!!
(5)管道命令
命令:| 将前一个命令的输出作为本次目录的输入,通常和搜索命令相结合使用,把|前的命令得到的数据,再通过管道来筛选,最后筛选出想要的数据。
示例:查看当前系统中所有的进程中包括system字符串的进程
[root@VM_0_16_centos test]# ps -ef |grep system
root 1 0 0 2018 ? 00:13:30 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 328 1 0 2018 ? 00:22:28 /usr/lib/systemd/systemd-journald
root 356 1 0 2018 ? 00:00:00 /usr/lib/systemd/systemd-udevd
root 512 1 0 2018 ? 00:06:23 /usr/lib/systemd/systemd-logind
dbus 514 1 0 2018 ? 00:14:41 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 19150 4643 0 17:26 pts/0 00:00:00 grep --color=auto system
[root@VM_0_16_centos test]#
(6)网络通信命令
1)查看当前系统的网卡信息:ifconfig (注意,不是ipconfig,windows中是ipconfig,而linux是ifconfig)
[root@VM_0_16_centos test]# ifconfig
eth0: flags=4163 mtu 1500
inet 172.21.0.16 netmask 255.255.240.0 broadcast 172.21.15.255
ether 52:54:00:5e:f7:67 txqueuelen 1000 (Ethernet)
RX packets 58738086 bytes 5160484858 (4.8 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 64516187 bytes 8071733343 (7.5 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 10354 bytes 946986 (924.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10354 bytes 946986 (924.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@VM_0_16_centos test]#
2)查看与某台机器的连接情况:ping
查看与百度IP地址的连接情况:ping 14.215.177.39 (注:时间可能有点长,可以不试)
3)查看当前系统的端口使用:netstat -an
[root@VM_0_16_centos test]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 1 172.21.0.16:47860 192.168.1.199:6379 SYN_SENT
tcp 0 0 172.21.0.16:54302 169.254.0.55:8080 TIME_WAIT
tcp 0 0 172.21.0.16:40514 169.254.0.55:5574 ESTABLISHED
tcp 0 52 172.21.0.16:22 222.95.223.120:24562 ESTABLISHED
tcp 0 0 172.21.0.16:22 188.2.61.41:42029 ESTABLISHED
tcp6 0 0 :::3306 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 172.21.0.16:123 0.0.0.0:*
udp 0 0 127.0.0.1:123 0.0.0.0:*
udp 0 0 0.0.0.0:123 0.0.0.0:*
udp6 0 0 :::123 :::*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 71984501 /usr/local/yd.socket.server
unix 2 [ ACC ] STREAM LISTENING 12839 /var/run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 12867 /var/run/lsm/ipc/simc
unix 2 [ ACC ] STREAM LISTENING 12877 /var/run/lsm/ipc/sim
unix 2 [ ACC ] STREAM LISTENING 10329 /run/lvm/lvmetad.socket
unix 2 [ ACC ] SEQPACKET LISTENING 10093 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 15803 /tmp/mysql.sock
unix 2 [ ACC ] STREAM LISTENING 10384 /run/lvm/lvmpolld.socket
unix 3 [ ] STREAM CONNECTED 71984508 /usr/local/yd.socket.client
unix 2 [ ] DGRAM 10421 /run/systemd/shutdownd
unix 3 [ ] DGRAM 7114 /run/systemd/notify
unix 2 [ ] DGRAM 7116 /run/systemd/cgroups-agent
unix 2 [ ACC ] STREAM LISTENING 9939 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 7134 /run/systemd/journal/stdout
unix 5 [ ] DGRAM 7137 /run/systemd/journal/socket
unix 12 [ ] DGRAM 7139 /dev/log
unix 2 [ ACC ] STREAM LISTENING 12264 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 11078
unix 3 [ ] STREAM CONNECTED 12950
unix 3 [ ] STREAM CONNECTED 87917171
unix 3 [ ] STREAM CONNECTED 12955
unix 3 [ ] STREAM CONNECTED 87917172
unix 2 [ ] DGRAM 12869
unix 3 [ ] STREAM CONNECTED 11079 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12958 /run/dbus/system_bus_socket
unix 2 [ ] STREAM CONNECTED 17180743
unix 2 [ ] DGRAM 11286
unix 2 [ ] STREAM CONNECTED 198461
unix 3 [ ] STREAM CONNECTED 12820 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 12836
unix 3 [ ] STREAM CONNECTED 12822 /run/systemd/journal/stdout
unix 3 [ ] DGRAM 11303
unix 3 [ ] STREAM CONNECTED 12533
unix 3 [ ] DGRAM 11302
unix 3 [ ] STREAM CONNECTED 12532
unix 3 [ ] STREAM CONNECTED 12489
unix 2 [ ] STREAM CONNECTED 198028
unix 3 [ ] STREAM CONNECTED 71984509 /usr/local/yd.socket.server
unix 3 [ ] STREAM CONNECTED 12724
unix 3 [ ] STREAM CONNECTED 14027 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 10588
unix 2 [ ] STREAM CONNECTED 17180589
unix 3 [ ] STREAM CONNECTED 14026
unix 2 [ ] DGRAM 24037
unix 3 [ ] STREAM CONNECTED 12957 /run/dbus/system_bus_socket
unix 2 [ ] DGRAM 87882967
unix 3 [ ] STREAM CONNECTED 11215
unix 2 [ ] DGRAM 14110
unix 2 [ ] DGRAM 14092
unix 3 [ ] STREAM CONNECTED 186376
unix 3 [ ] STREAM CONNECTED 12818 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 186388 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 15705
unix 3 [ ] STREAM CONNECTED 12107
unix 2 [ ] DGRAM 12097
unix 3 [ ] STREAM CONNECTED 12106
unix 3 [ ] STREAM CONNECTED 14617
unix 3 [ ] STREAM CONNECTED 15706 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 14772 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12834 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12864
unix 3 [ ] STREAM CONNECTED 12023 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12815
unix 2 [ ] DGRAM 87917197
unix 2 [ ] DGRAM 13029
unix 2 [ ] DGRAM 182376
unix 3 [ ] STREAM CONNECTED 12954
unix 2 [ ] DGRAM 12851
unix 2 [ ] DGRAM 14898
unix 3 [ ] STREAM CONNECTED 14771
unix 3 [ ] STREAM CONNECTED 14776 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12956 /run/dbus/system_bus_socket
[root@VM_0_16_centos test]#
6.Linux的权限命令
1)查看权限 ls -l
权限是Linux中的重要概念,每个文件/目录等都具有权限,通过***ls -l***命令我们可以 查看某个目录下的文件或目录的权限
[root@VM_0_16_centos test]# cd /
[root@VM_0_16_centos /]# ls -l
total 72
lrwxrwxrwx. 1 root root 7 Aug 8 2018 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 Dec 12 09:16 boot
drwxr-xr-x 4 root root 4096 Nov 24 2018 data
drwxr-xr-x 19 root root 2980 Dec 12 09:47 dev
drwxr-xr-x. 85 root root 4096 May 30 16:32 etc
drwxr-xr-x. 2 root root 4096 Nov 24 2018 home
lrwxrwxrwx. 1 root root 7 Aug 8 2018 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Aug 8 2018 lib64 -> usr/lib64
drwxr-x--- 2 root root 4096 Dec 12 17:32 logs
drwx------. 2 root root 16384 Aug 8 2018 lost+found
drwxr-xr-x. 2 root root 4096 Apr 11 2018 media
drwxr-xr-x. 2 root root 4096 Apr 11 2018 mnt
drwxr-xr-x. 3 root root 4096 Aug 8 2018 opt
dr-xr-xr-x 92 root root 0 Dec 12 09:47 proc
dr-xr-x---. 7 root root 4096 May 30 16:45 root
drwxr-xr-x 23 root root 840 May 29 22:41 run
lrwxrwxrwx. 1 root root 8 Aug 8 2018 sbin -> usr/sbin
drwxr-xr-x. 2 root root 4096 Apr 11 2018 srv
dr-xr-xr-x 13 root root 0 May 29 16:58 sys
drwxr-xr-x 3 root root 4096 May 30 17:07 test
drwxrwxrwt. 9 root root 4096 May 30 17:11 tmp
drwxr-xr-x. 13 root root 4096 Aug 8 2018 usr
drwxr-xr-x. 19 root root 4096 Aug 13 2018 var
[root@VM_0_16_centos /]#
第一列的内容的信息解释如下:
文件的类型:
d:代表目录
-:代表文件
l:代表链接(可以认为是window中的快捷方式)
后面的9位分为3组,每3位置一组,分别代表属主的权限,与当前用户同组的 用户的权限,其他用户的权限
r:代表权限是可读,r也可以用数字4表示
w:代表权限是可写,w也可以用数字2表示
x:代表权限是可执行,x也可以用数字1表示
2)修改权限 chmod
示例:修改/test下的aaa.txt的权限为属主有全部权限,属主所在的组有读写权限,其他用户只有读的权限
chmod u=rwx,g=rw,o=rw asd.txt
[root@VM_0_16_centos /]# cd test/
[root@VM_0_16_centos test]# ls
aaa asd.txt sudo.conf test.tar.gz testXX.tar.gz
[root@VM_0_16_centos test]# ls -l
total 20
drwxr-xr-x 2 root root 4096 May 30 17:07 aaa
-rw-r--r-- 1 root root 34 May 30 16:45 asd.txt
-rwxr-xr-x 1 root root 1786 May 30 16:33 sudo.conf
-rw-r--r-- 1 root root 1042 May 30 16:54 test.tar.gz
-rw-r--r-- 1 root root 2287 May 30 16:57 testXX.tar.gz
[root@VM_0_16_centos test]# chmod u=rwx,g=rw,o=rw asd.txt
[root@VM_0_16_centos test]# ls -l
total 20
drwxr-xr-x 2 root root 4096 May 30 17:07 aaa
-rwxrw-rw- 1 root root 34 May 30 16:45 asd.txt
-rwxr-xr-x 1 root root 1786 May 30 16:33 sudo.conf
-rw-r--r-- 1 root root 1042 May 30 16:54 test.tar.gz
-rw-r--r-- 1 root root 2287 May 30 16:57 testXX.tar.gz
[root@VM_0_16_centos test]#
如上,修改asd.txt文件的权限。
上述示例还可以使用数字表示:
chmod 766 asd.txt
因为三种权限的数字组合不可能重复,因为可以根据数值来判断权限。
4 2 1可以组合成多种属性:
4:r,可读
2:w,可写
1:x,可执行
3:wx,可写可执行
5:rx,可读可执行
6:rw,可读可写
7:rwx,可读可写可执行
7.网络配置
(1)vim命令配置
根目录下查看网卡配置 cat etc/sysconfig/network-scripts/ifcfg-eth0
概要信息:
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=dhcp #静态获取IP,其他取值static,如果是static,则还需要设置下面信息
DEVICE=eth0 #网卡类型
HWADDR=52:54:00:5e:f7:67
NM_CONTROLLED=no
ONBOOT=yes #是否开机启动网卡
TYPE=Ethernet
USERCTL=no
PERSISTENT_DHCLIENT=yes
#如果BOOTPROTO=static,还需要设置以下信息
IPADDR=188.131.164.167 #IP地址
GATEWAY= #网关
NETMASK=255.255.255.0 #子网掩码
三、Linux安装jdk、mysql、tomcat
安装完成后即可部署服务