-Linux-3

1.sudo权限

su - chenqian

[root@hadoop001 home]# su - chenqian
[chenqian@hadoop001 ~]$ ls -l /root

    若直接 sudo ls -l /root 报错当前用户无sudo权限
[root@hadoop001 ~]# vi /etc/sudoers    进入编辑

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
ruoze2   ALL=(root)      NOPASSWD:ALL    照上进行编辑内容
ruoze1   ALL=(root)      NOPASSWD:ALL
ruoze3   ALL=(root)      NOPASSWD:ALL
chenqian ALL=(root)      NOPASSWD:ALL

[root@hadoop001 ~]# su - chenqian

[chenqian@hadoop001 ~]$ sudo ls -l /root          sudo执行root权限
total 84
-rw-r--r-- 1 root root    2 Jun 20 06:49 1
drwxr-xr-x 3 root root 4096 Mar 15 00:31 1.
-rw-r--r-- 1 root root  259 Jun 21 12:24 123.log
drwxr-xr-x 2 root root 4096 Jun 20 18:32 20180620
drwxr-xr-x 3 root root 4096 Jun 18 12:38 20190618
drwxr-xr-x 3 root root 4096 Jun 20 22:42 chenqian
drwxr-xr-x 7 root root 4096 Mar 17 22:39 chenxiaoer
drwxr-xr-x 2 root root 4096 Mar 16 23:31 chenyi
drwxr-xr-x 2 root root 4096 Mar 14 23:19 d
drwxr-xr-x 2 root root 4096 Jun 21 12:20 d66
drwxr-xr-x 2 root root 4096 Mar 17 22:56 root
drwxr-xr-x 3 root root 4096 Mar 19 02:44 ruoze
drwxr-xr-x 2 root root 4096 Jun 19 06:37 ruozedata
-rw-r--r-- 1 root root    0 Jun 18 22:38 tail1.log
-rw-r--r-- 1 root root    8 Jun 18 22:39 tail1.log1
-rw-r--r-- 1 root root   17 Jun 18 22:55 tail22.log
-rw-r--r-- 1 root root    3 Jun 18 22:52 tail22.log1
-rw-r--r-- 1 root root    4 Jun 18 22:41 tail2.log
-rw-r--r-- 1 root root    8 Jun 18 22:41 tail2.log1
-rw-r--r-- 1 root root    8 Jun 18 22:40 tail2.log2
drwxr-xr-x 7 root root 4096 Mar 16 23:11 test
drwxr-xr-x 2 root root 4096 Mar 21 02:07 win

生产上建议:最好需要一个拥有sudo权限且不输入密码的普通用户。 (牵扯到部署环境 比如CDH)

2 进程和端口号 kill

进程 [root@hadoop001 ~]# ps -ef 查看进程打印出来

[root@hadoop001 ~]# ps -ef|grep 123   管道过滤打印出来的123文件
root      1570  1555  0 14:59 pts/1    00:00:00 tail -f 123.log
root      1578  1555  0 15:00 pts/1    00:00:00 tail -f 123.log
root      1581  1555  0 15:00 pts/1    00:00:00 tail -F 123.log
root      1608  1509  0 15:04 pts/0    00:00:00 grep 123     把自己过滤出来
进程用户    pid  父pid                            进程的内容
[root@hadoop001 ~]# ps -ef|grep 123 |grep -v grep     再作一次过滤  -v排除
root      1570  1555  0 14:59 pts/1    00:00:00 tail -f 123.log
root      1578  1555  0 15:00 pts/1    00:00:00 tail -f 123.log
root      1581  1555  0 15:00 pts/1    00:00:00 tail -F 123.log
[root@hadoop001 ~]# kill -9 1570       杀进程
[root@hadoop001 ~]# ps -ef|grep 123 |grep -v grep    
root      1578  1555  0 15:00 pts/1    00:00:00 tail -f 123.log
root      1581  1555  0 15:00 pts/1    00:00:00 tail -F 123.log

[root@hadoop001 ~]# ps -ef|grep 123 |grep -v grep
root      1649  1555  0 15:18 pts/1    00:00:00 tail -F 123.log
[root@hadoop001 ~]# ps -ef|grep 1555          查看父pip
root      1555  1553  0 14:59 pts/1    00:00:00 -bash   解释器
root      1649  1555  0 15:18 pts/1    00:00:00 tail -F 123.log
root      1654  1509  0 15:18 pts/0    00:00:00 grep 1555
[root@hadoop001 ~]# ps -ef|grep 1553|grep -v grep     再一次查看父pip,层层向上查看
root      1553  1133  0 14:59 ?        00:00:00 sshd: root@pts/1    SSH登录进来的执行
root      1555  1553  0 14:59 pts/1    00:00:00 -bash
[root@hadoop001 ~]# 

[root@hadoop001 ~]# kill -9 $(pgrep -f 123)        一次杀死多个进程命令
[root@hadoop001 ~]# kill -9 2095 2098                一次杀死多个进程命令

**生产上提醒:生产上假如非要执行kill杀进程,一定要确认清楚   1.该进程是否真的杀?需求确认清楚,多问问       2.杀的进程是否你想要杀的,勿杀错。**

端口号 netstat

[root@hadoop001 ~]# ps -ef|grep ssh       先找到ssh进程的pid
root      1132  1133  0 14:13 ?        00:00:00 sshd: root@pts/0    
root      1133     1  0 Jun20 ?        00:00:12 /usr/sbin/sshd           ssh后台进程
root      1553  1133  0 14:59 ?        00:00:00 sshd: root@pts/1 
root      1722  1133  0 15:27 ?        00:00:00 sshd: root@pts/2 
root      1825  1509  0 15:38 pts/0    00:00:00 grep ssh
[root@hadoop001 ~]# netstat -nlp|grep 1133      再通过pid找到该进程的端口号 
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN         1133/sshd                  
tcp        0      0 :::22                       :::*                        LISTEN      1133/sshd           
[root@hadoop001 ~]# 

[root@hadoop001 ~]# netstat -nlp|grep ssh 这样也可以找到端口号,但太多数据,不建议

生产流程:正常流程:进程名称–>pid–>port(端口号)

1.port(端口号) 是否正确 是否变更。 一般都是80端口号,需更改
2.案例 :打开某个服务的web外部界面? 服务对外:ip+port
yum install httpd 安装
service httpd start 启动

root@hadoop001 ~]# ps -ef|grep httpd|grep http   找到http进程的pid和父pid
root      1915     1  0 15:53 ?        00:00:00 /usr/sbin/httpd
apache    1917  1915  0 15:53 ?        00:00:00 /usr/sbin/httpd
apache    1918  1915  0 15:53 ?        00:00:00 /usr/sbin/httpd
apache    1919  1915  0 15:53 ?        00:00:00 /usr/sbin/httpd
apache    1920  1915  0 15:53 ?        00:00:00 /usr/sbin/httpd
apache    1921  1915  0 15:53 ?        00:00:00 /usr/sbin/httpd
apache    1922  1915  0 15:53 ?        00:00:00 /usr/sbin/httpd
apache    1923  1915  0 15:53 ?        00:00:00 /usr/sbin/httpd
apache    1924  1915  0 15:53 ?        00:00:00 /usr/sbin/httpd
root      1992  1555  0 16:06 pts/1    00:00:00 grep httpd
[root@hadoop001 ~]# netstat -nlp|grep 1915   由于此处pid多,这里通过父pid找到端口号
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1915/httpd 

Linux 和 win 查看IP的方法

[root@hadoop001 ~]# ifconfig    命令
eth0      Link encap:Ethernet  HWaddr 52:54:00:66:9C:38  
          inet addr:10.9.6.136 **此处** Bcast:10.9.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1454  Metric:1
          RX packets:328409 errors:0 dropped:0 overruns:0 frame:0
          TX packets:435647 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:58342227 (55.6 MiB)  TX bytes:60248079 (57.4 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@hadoop001 ~]# cat /etc/hosts  命令
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6







127.0.0.1 10-9-6-136
10.9.6.136 **此处** 10-9-6-136

window: ipconfig

云主机是通过外网IP访问web外部界面

3 端口号对外服务的ip地址,假如为127.0.0.1或localhost,只能在这台的机器上访问这个服务。一般这个地址为机器的ip或0.0.0.0 或 :::,表示对外的任意ip可以服务。

**ping网络的两种方法**
[roo[root@hadoop001 ~]# ping 127.0.0.1      **网络连接**
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.053 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.022 ms
^C
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2437ms
rtt min/avg/max/mdev = 0.022/0.037/0.053/0.012 ms

[root@hadoop001 ~]# ping localhost    **网络连接**
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.046 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.105 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.052 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.048 ms
^C
--- localhost ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3106ms
rtt min/avg/max/mdev = 0.046/0.062/0.105/0.026 ms
[root@hadoop001 ~]# 

编辑端口号对外服务的ip地址为 127.0.0.1
t@hadoop001 etc]# cd /etc/httpd/conf    到此目录进行编辑
[root@hadoop001 conf]# ls
httpd.conf  magic
[root@hadoop001 conf]# vi httpd.conf    编辑此文件
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen  127.0.0.1:80      到此处进行编辑,编辑成这样

[root@hadoop001 conf]# service httpd restart    进行重启
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for hadoop001
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]
[root@hadoop001 conf]# 

[root@hadoop001 ~]# netstat -nlp|grep httpd      未编辑之前端口还是0 0.0.0.0:80     可以访问
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      2700/httpd          
[root@hadoop001 ~]# netstat -nlp|grep httpd      编辑之后端口号变成:127.0.0.1:80     无法访问
tcp        0      0 127.0.0.1:80                0.0.0.0:*                   LISTEN      3220/httpd          
[root@hadoop001 ~]# 

因此则外部界面也无法打开
在这里插入图片描述

3.搜索 find

find / -name 'tail'              从根目录开始完全匹配
find / -name '*tail*'            从根目录开始模糊匹配

find /root -name '*tail*'       一般指定目录

拓展联想:
history | grep tail
ps -ef|grep tail
.bash_profile

4.安装 rpm包

yum search xxx      搜索
yum install xxx      yum install -y XXX     安装
service xxx start    启动
service xxx stop     停止
yum remove xxx     rpm -e      卸载删除
service xxx restart   重启
mysql -uroot -p   客户端
show databases;
rpm -qa|grep XXX       搜索出来所有软件包过滤我们想要的  

安装mysql案例
[root@hadoop001 ~]# yum search mysql     搜索MySQL
mysql-server.x86_64         mysql.x86_64
[root@hadoop001 ~]# yum install mysql-server.x86_64      mysql.x86_64   安装MySQL
[root@hadoop001 ~]# service mysqld start               启动MySQL
Starting mysqld:                                           [  OK  ]
[root@hadoop001 ~]# mysql -uroot -p         进入MySQL客户端
Enter password:                                         回车不需要密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> 

卸载mysql案例

[root@hadoop001 ~]# rpm -qa|grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64   客户端
mysql-server-5.1.73-8.el6_8.x86_64

[root@hadoop001 ~]# yum remove mysql-server-5.1.73-    8.el6_8.x86_64                       卸载
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.x86_64 0:5.1.73-8.el6_8 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package              Arch           Version                   Repository     Size
===================================================================================
Removing:
 mysql-server         x86_64         5.1.73-8.el6_8            @base          25 M

Transaction Summary
===================================================================================
Remove        1 Package(s)

Installed size: 25 M
Is this ok [y/N]: y'^H^H
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : mysql-server-5.1.73-8.el6_8.x86_64                              1/1 
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
  Verifying  : mysql-server-5.1.73-8.el6_8.x86_64                              1/1 

Removed:
  mysql-server.x86_64 0:5.1.73-8.el6_8                                             

Complete!
[root@hadoop001 ~]# rpm -e mysql-5.1.73-8.el6_8.x86_64      再删除客户端
[root@hadoop001 ~]# 


不校验依赖性
do not verify package dependencies    报错
rpm -e --nodeps XXX         不校验依赖性命令
[root@hadoop001 ~]# rpm -e --nodeps httpd-2.2.15-69.el6.centos.x86_64      不校验依赖关系命令

5.which $PATH

echo $PATH
which ls
whereis ls xxx

[root@hadoop001 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@hadoop001 ~]# which ls
alias ls=‘ls --color=auto’
/bin/ls
[root@hadoop001 ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
[root@hadoop001 ~]#

错误案例示范

[root@hadoop001 ~]# vi /usr/local/sbin/ls
[root@hadoop001 ~]# cd /usr/local/sbin
[root@hadoop001 sbin]# ll
total 4
-rw-r--r-- 1 root root 18 Jun 24 21:43 ls
[root@hadoop001 sbin]# vi ls     编辑
#!/bin/bash    编辑的内容
[root@hadoop001 sbin]# chmod +x ls
[root@hadoop001 sbin]# which ls
alias ls='ls --color=auto'
	/usr/local/sbin/ls
[root@hadoop001 sbin]# ls
ls
[root@hadoop001 sbin]# rm -f ls
[root@hadoop001 sbin]# which ls
alias ls='ls --color=auto'
	/bin/ls
[root@hadoop001 sbin]# 

yum install lrzsz 
rz命令		 选择window的文件传输给linux
 sz filename文件名称命令     将Linux的文件传输给window   ``
 tar -xzvf      解压

mkdir -p /usr/java
[root@hadoop001 ~]# tar -xzvf jdk-8u45-linux-x64.gz -C /usr/java/ 解压
[root@hadoop001 ~]# cd /usr/java
[root@hadoop001 java]# ll
total 4
drwxr-xr-x 8 uucp 143 4096 Apr 11 2015 jdk1.8.0_45
[root@hadoop001 java]# chown -R root:root /usr/java/jdk1.8.0_45 修正用户和用户组
[root@hadoop001 java]# ll
total 4
drwxr-xr-x 8 root root 4096 Apr 11 2015 jdk1.8.0_45
[root@hadoop001 java]#
1.java目录必须在/usr/java
2.用户用户组发生变更 必须修正 chown -R root:root /usr/java/jdk1.8.0_45

配置全局环境变量 /etc/profie
vi  编辑          vi /etc/profile
JAVA_HOME=usr/java/jdk1.8.0_45    配置编辑内容
PATH=${JAVA_HOME}/bin:$PATH

[root@hadoop001 ~]# source /etc/profile
[root@hadoop001 ~]# which java
/usr/java/jdk1.8.0_45/bin/java
[root@hadoop001 ~]# echo $PATH
/usr/java/jdk1.8.0_45/bin:/bin:/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@hadoop001 ~]#

6 配置hostname机器名称以hostname去连接
Linux

root@hadoop001 ~]# vi /etc/hosts    
106.75.103.178 hadoop001        编辑内容:ip+机器名称
[root@hadoop001 ~]# ping hadoop001
PING hadoop001 (106.75.103.178) 56(84) bytes of data.
64 bytes from hadoop001 (106.75.103.178): icmp_seq=1 ttl=58 time=2.01 ms
64 bytes from hadoop001 (106.75.103.178): icmp_seq=2 ttl=58 time=1.50 ms
64 bytes from hadoop001 (106.75.103.178): icmp_seq=3 ttl=58 time=1.47 ms
64 bytes from hadoop001 (106.75.103.178): icmp_seq=4 ttl=58 time=1.49 ms
64 bytes from hadoop001 (106.75.103.178): icmp_seq=5 ttl=58 time=1.46 ms
64 bytes from hadoop001 (106.75.103.178): icmp_seq=6 ttl=58 time=1.40 ms
^C
--- hadoop001 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5244ms
rtt min/avg/max/mdev = 1.400/1.558/2.018/0.214 ms
[root@hadoop001 ~]# 
[root@hadoop001 ~]# service httpd status
httpd (pid  14179) is running...

window:

C:\Windows\System32\drivers\etc\hosts    找到此处进行编辑:ip+机器名称
注意 没有权限修改 直接复制一份桌面上,修改后 拖拽 覆盖即可     

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值