Sword point data warehouse Shell command three

Keywords: Hadoop Linux sudo PHP

1, Last course review

2, Linux basic command 3

Three. Homework

1, Last course review

  • Blog link: https://blog.csdn.net/SparkOnYarn/article/details/104793896

  • In the future, when deploying components of big data, you must check whether they are effective or not. There is no problem if you are careful. Aliases are actually used to simplify operations. Deleting commands is a high-risk command because they are frequently used in work. History can view history records and execute historical commands;

2, Linux basic command 2

2.1 users and user groups

  1. Create user
1,How to use users and user groups: add, delete and modify
[root@hadoop001 sbin]# ll /usr/sbin/user*
-rwxr-x--- 1 root root 118192 Nov  6  2016 /usr/sbin/useradd
-rwxr-x--- 1 root root  80360 Nov  6  2016 /usr/sbin/userdel
-rwxr-x--- 1 root root 113840 Nov  6  2016 /usr/sbin/usermod
-rwsr-xr-x 1 root root  11296 Apr 13  2017 /usr/sbin/usernetctl
[root@hadoop001 sbin]# ll /usr/sbin/group*
-rwxr-x--- 1 root root 65480 Nov  6  2016 /usr/sbin/groupadd
-rwxr-x--- 1 root root 57016 Nov  6  2016 /usr/sbin/groupdel
-rwxr-x--- 1 root root 57064 Nov  6  2016 /usr/sbin/groupmems
-rwxr-x--- 1 root root 76424 Nov  6  2016 /usr/sbin/groupmod

2,We create a user for ruoze,Create a user group with this name by default ruoze,And set the primary group of this user ruoze
[root@hadoop001 sbin]# useradd ruoze
[root@hadoop001 sbin]# id ruoze
uid=1001(ruoze) gid=1001(ruoze) groups=1001(ruoze)

//For example: the boss's sister-in-law belongs to both the finance department and the human resources department, but the main department is the finance department==>Analogy to finance department is the main group
  1. Storage directory for users and user groups:
1,User storage file directory:
cat /etc/passwd

2,User group storage file directory:
cat /etc/group

3,The created user will default to home Create your own directory under Directory:
[root@hadoop001 home]# ll
total 8
drwx------ 7 hadoop hadoop 4096 Mar 11 16:18 hadoop
drwx------ 2 ruoze  ruoze  4096 Mar 12 10:47 ruoze
//Permission user user group folder size not allowed to create time (ll -rt for time sorting)
  1. Test delete user:

1. Because there is only one ruoze user in the ruoze group, the ruoze user group will be deleted when deleting the ruoze user. When there are other members in the group, the ruoze group will not be deleted

[root@hadoop001 home]# id ruoze
uid=1001(ruoze) gid=1001(ruoze) groups=1001(ruoze)
[root@hadoop001 home]# userdel ruoze
[root@hadoop001 home]# id ruoze
id: ruoze: no such user
[root@hadoop001 home]# cat /etc/passwd | grep ruoze 
[root@hadoop001 home]# cat /etc/group | grep ruoze
[root@hadoop001 home]# ll
total 8
drwx------ 7 hadoop hadoop 4096 Mar 11 16:18 hadoop
drwx------ 2   1001   1001 4096 Mar 12 10:47 ruoze
  1. After deleting the ruoze user, continue to try to add the user. How to restore the lost style
1,This passage means home Directory.bash File already exists, user and user group directory already exist ruoze Users
[root@hadoop001 home]# useradd ruoze
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists
[root@hadoop001 home]# cat /etc/passwd|grep ruoze
ruoze:x:1001:1001::/home/ruoze:/bin/bash
[root@hadoop001 home]# cat /etc/group | grep ruoze
ruoze:x:1001:

2,Use root User switch to ruoze Users, deleting.bash Hidden files
[root@hadoop001 ~]# su - ruoze
[ruoze@hadoop001 ~]$ ll -a
total 20
drwx------  2 ruoze ruoze 4096 Mar 12 10:47 .
drwxr-xr-x. 4 root  root  4096 Mar 12 10:47 ..
-rw-r--r--  1 ruoze ruoze   18 Dec  7  2016 .bash_logout
-rw-r--r--  1 ruoze ruoze  193 Dec  7  2016 .bash_profile
-rw-r--r--  1 ruoze ruoze  231 Dec  7  2016 .bashrc
[ruoze@hadoop001 ~]$ rm -rf .bash*
[ruoze@hadoop001 ~]$ ll -a
total 8
drwx------  2 ruoze ruoze 4096 Mar 12 11:17 .
drwxr-xr-x. 4 root  root  4096 Mar 12 10:47 ..

3,Deleted.bash New after hiding files session,Switch to ruoze User, missing style found==>To put it bluntly is to lose.bash file
[root@hadoop001 ~]# su - ruoze
Last login: Thu Mar 12 11:17:05 CST 2020 on pts/1
-bash-4.2$ 
-bash-4.2$ 

4,What if the style is lost?
//Copy the files in this directory to the ruoze user directory
[root@hadoop001 skel]# cp /etc/skel/.* /home/ruoze/
[root@hadoop001 skel]# chown -R ruoze:ruoze /home/ruoze/.bash*

//The simplest is to directly copy the. bash files of other users to the ruoze directory, and modify users and user groups
  1. Add user group
1,increase bigdata User group
groupadd bigdata

2,Add to ruoze User to bigdata User group
[root@hadoop001 skel]# id ruoze
uid=1001(ruoze) gid=1001(ruoze) groups=1001(ruoze)
[root@hadoop001 skel]# usermod -a -G bigdata ruoze
[root@hadoop001 skel]# id ruoze
uid=1001(ruoze) gid=1001(ruoze) groups=1001(ruoze),1002(bigdata)

3,usermod --help View command help
Usage: usermod [options] LOGIN

-g, --gid GROUP               force use GROUP as new primary group
//Force group as new group

-G, --groups GROUPS           new list of supplementary GROUPS
//List of new supplementary groups

-a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups
//Append the user to the supplementary group, mention the - G option, but do not delete him from other groups 
  1. Requirement: modify bigdata to be the main group of ruoze users, and ruoze users should also be in ruoze group:
1,Before modification, ruoze The user's group and primary group are ruoze,still bigdata In group
[ro[root@hadoop001 skel]# id ruoze
uid=1001(ruoze) gid=1001(ruoze) groups=1001(ruoze),1002(bigdata)

2,Mandatory modification ruoze User's group and primary group
[root@hadoop001 skel]# usermod -g bigdata ruoze
[root@hadoop001 skel]# id ruoze
uid=1001(ruoze) gid=1002(bigdata) groups=1002(bigdata)

3,ruoze The user's primary group is bigdata,hold ruoze This group is added additionally
[root@hadoop001 skel]# usermod -a -G ruoze ruoze
[root@hadoop001 skel]# id ruoze
uid=1001(ruoze) gid=1002(bigdata) groups=1002(bigdata),1001(ruoze)

2.2. Set password and sudo authority for ordinary users

1. Set the password for the user, using the root user to set:

[root@hadoop001 skel]# passwd ruoze
Changing password for user ruoze.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@hadoop001 skel]# su - ruoze
Last login: Thu Mar 12 11:26:07 CST 2020 on pts/1

2. Password setting for ordinary users is mainly used for remote connection:

  • File > quick connect > enter host name

3. The name not followed by passwd is to change the password for the current user

  • Changing password for ruoze.
    (current) UNIX password:

Give normal user root the maximum permission and no password

 1. Using root user, vi /etc/sudoers, edit this file, find the following lines and add the following information after 91 lines: hadoop is my user, NOPASSWD:ALL means no password is required
 90 allow root to run any commands anywhere
 91 root    ALL=(ALL)       ALL
 92 hadoop  ALL=(ALL)       NOPASSWD:ALL

2.3 differences between su and su -

1. The difference between su and su

1,Use su Switch to ruoze The user is still in the original user's directory
[root@hadoop001 ~]# su ruoze
[ruoze@hadoop001 root]$ pwd
/root
[ruoze@hadoop001 root]$ exit;
exit

2,su - When it's time to switch ruoze User's home directory, and execute ruoze User's environment variable file
[root@hadoop001 ~]# su - ruoze
Last login: Thu Mar 12 11:56:52 CST 2020 on pts/2
[ruoze@hadoop001 ~]$ pwd
/home/ruoze

2. How to verify su - ruoze will execute the environment variable of ruoze user, but su ruoze will not take effect

The point verified here is that the. Bash? Profile file will not be executed by su ruoze
 . bashrc will execute for both su ruoze and su - ruoze
  • The conclusion is that we need to use su user to switch users later, and the environment variables should be configured in the configuration file. bashrc.

2.4 analysis of / etc/passwd

1. To view and modify the contents of the / etc/passwd file:

1. View the last two lines of the file
ldap:x:55:55:OpenLDAP server:/var/lib/ldap:/sbin/nologin
ruoze:x:1001:1002::/home/ruoze:/bin/bash

2. Modify / bin/bash to / bin/false and / sbin/nologin
 You can't log in after changing to either

2. Explanation of production environment:

There are many components in CDH:
hdfs component has hdfs users
 hbase components have hbase users,
Yarn components have yarn users;
The existing situation: switching users can't be done. As long as the last line of content in the / etc/passwd file is modified to / bin/bash, there is no problem.

2.5 permissions (chmod, chown)

chmod -R 777 file or folder
chown -R user: user group file or folder

Permission denied: permission denied

1,Give an example:
[root@hadoop001 hadoop]# ll
total 20
drwxrwxr-x 2 hadoop hadoop 4096 Mar  5 15:58 app

rwx The sum of the first group of permissions is 7, which represents the users of files and folders root,It has read and write permission for this file
rwx  The sum of the second group of permissions is 7, which represents the user group of the file or folder root,Read write execution
r-x The sum of permissions in the third group is 5, which represents the permissions of users in other groups to this file or folder, and has read and execute permissions

chmod

d: directory Catalog
r: read Read, number 4
w: write Write, the number is 2
x: Implementation, the number represented is 1

7 = 4 + 2 + 1,representative r + w + x

777 It means that any user and user group have read-write execution permission

Case study:
There is a / tmp directory on linux. The permissions of the / tmp directory are 777. We create an rz.log file in the / tmp directory;

1. View the / tmp directory and the permissions of the created rz.log file
drwxrwxrwt. 12 root root       4096 Mar 12 17:08 tmp

2. To view the file permissions of rz.log:
-rw-r--r-- 1 root root   24 Mar 12 17:05 rz.log

3. There is no problem in using root user, but when using hadoop user to enter editing and edit rz.log, the prompt is as follows: warning: changing a readonly file, and when using wq! To force saving, the prompt is as follows: can't open file for writing


4. Prompt: if the file cannot be written in 3, we can directly input ctrl+z to interrupt writing. At this time, it is equivalent to generating a cache file. We will delete it after ll-a is checked, rm-f.rz.log.swap
-rw-r--r--   1 root   root      24 Mar 12 17:05 rz.log
-rw-------   1 hadoop hadoop 12288 Mar 12 17:10 .rz.log.swp

5. We have the right to modify vi.log: chmod -R 746 rz.log
 At this time, use Hadoop users to edit: there is no problem in saving and exiting,
Because id hadoop finds that the hadoop user is not the root user or the group of the root user, but belongs to other user groups, so it gives 746 permissions:
[root@hadoop001 tmp]# id hadoop
uid=1000(hadoop) gid=1000(hadoop) groups=1000(hadoop)

Pay attention to the execution of ctrl+z on production, which means that the file will be interrupted directly and the swap file will be generated. At this time, the file will be directly ll-a and then deleted.

  • Test that we add hadoop users to the root user group:
1. Users and user groups to which hadoop originally belonged:
[root@hadoop001 tmp]# id hadoop
uid=1000(hadoop) gid=1000(hadoop) groups=1000(hadoop)

2. Add the hadoop user to the root user group:
[root@hadoop001 tmp]# usermod -a -G root hadoop
[root@hadoop001 tmp]# id hadoop
uid=1000(hadoop) gid=1000(hadoop) groups=1000(hadoop),0(root)

3. The file of / tmp/rz.log still has permissions of 644. At this time, can the test editor use it
 Still prompt can't save

4. Modify the permission of rz.log to chmod -R 664 rz.log for testing:
You need to open a new session or reconnect the current window. vi rz.log can write and save successfully and exit.

2.6 file and folder viewing size

1. View file size:

[root@hadoop001 software]# ll php-7.2.28.tar.gz 
-rw-r--r-- 1 root root 19935034 Mar  5 13:54 php-7.2.28.tar.gz
[root@hadoop001 software]# du -sh php-7.2.28.tar.gz 
20M     php-7.2.28.tar.gz

2. View Folder Size:

[root@hadoop001 hadoop]# du -sh software/
866M    software

2.7 search find command

history
ps -ef view process
top system

1. We have a new machine in hand, such as hadoop, a big data component. Which path do we need to find for deployment?

  • Use the maximum root permission, find / -name "hadoop"
1,Search from root to name hadoop Documents:
[root@hadoop001 ~]# find / -name "hadoop"
/home/hadoop
/var/db/sudo/hadoop
/var/spool/mail/hadoop

2,Can be specified in/home Search below:
[root@hadoop001 ~]# find /home -name "*hadoop*"
/home/hadoop

3,You can fuzzy match the content you need to find: add before and after*Number:
[root@hadoop001 ~]# find / -name "*hadoop*"
/home/hadoop
/var/db/sudo/hadoop
/var/spool/mail/hadoop

Three. This course assignment

Homework:
1. Organize users and user groups
2. sudo command
3. Why can't users log in (/ etc/passwd file related)
4. Permissions (rwx), chown, and chmod commands
Note: the commands using - R on linux are chown and chmod only

Published 3 original articles, won 0 praise and 30 visitors
Private letter follow

Posted by Arsench on Thu, 12 Mar 2020 03:15:32 -0700