运维学习第十一天

xiaoxiao2021-02-27  474

#########################################################

#####第六单元linux中常用的基础命#########

#########################################################

1.diff比较两个文件的不同

diff -u file file.new >file.path ##生成补丁文件

yum install patch -y ##安装打补丁工具

patch  -b file file.path ##给老软件打补丁,清且对老软件进行备份

 

 

2.grep ##过滤字符

-i ##或略大小写

-n ##显示结果所在行的行号

-c ##结果个数

-v ##反向过滤

-r 关键字 目录 ##在目录中过滤还有关键字的文件

-E "关键字1|关键字2|....." ##过滤多个关键字

 

 

cut    -d   ##指定用于提取字段的分隔符

cut    -f    ##指定要从每行中提取的字段

cut    -c   ##指定要从每行中提取的文本列

3.sort ##排序

-n ##纯数字

-r ##倒序

-u ##去掉重复行

-t ##指定分隔符

-k ##指定排序的列

 

 

 

4.uniq ##处理重复行

-c ##统计重复行的个数

-u ##显示唯一的行

-d ##显示重复行

 

5.tr ##转换字符大小写

tr 'a-z' 'A-Z' <file ##把file中所有小写字符转换成大写

 

6.sed ##控制流输出

sed 's/nologin/westos/g' passwd   ##替换输出中的nologin为westos

sed '1,5s/nologin/westos/g' passwd ##替换输出中1-5行的nologin为wesots

sed '/games/,/nobody/s/nologin/westos/g' passwd ##替换输出中的games字符到nobody字符之间的nologin为westos

sed -e 's/nologin/westos/g' -e 's/sbin/lee/g' passwd ##多条替换策略用-e连接

sed 3d passwd ##不显示文件中的第三行

sed 3,7d file ##不显示文件中的3-7行

sed 3,7p file ##重复显示文件中的3-7行

sed -n 3,7p file ##只显示文件中的3-7行

[root@westos mnt]# cat rule ##规则文件内容

s/nologin/westos/g

s/sbin/lee/g

[root@westos mnt]# sed -f rule  file ##使用规则文件更改输出

     1 root:x:0:0:root:/root:/bin/bash

     2 bin:x:1:1:bin:/bin:/lee/westos

     3 daemon:x:2:2:daemon:/lee:/lee/westos

     4 adm:x:3:4:adm:/var/adm:/lee/westos

############################################\

##第七单元访问网络共享文件系统##

#############################################

1.cifs

如何访问1

1)yum install samba-client ##安装共享访问客户端

2)smbclient -L //ip  ##识别共享目录

3)smbclient //ip/sharename ##访问共享(命令访问)

如何访问2(挂载访问)

mount //ip/sharename /mountpoint -o username=guest

vim /etc/fstab

//ip/sharename /mountpoint cifs defaults,username=guest 0 0

mount -a

 

2.nfs

手动挂载方式

1)yum install nfs-utils

2)showmount -e ip

3)mount ip:/sharedir /mountpoint

自动挂载方式

1)yum install autofs

2)systemctl start autofs

3)cd /net/ip/

4)vim /etc/syscofig/autofs

TIMEOUT=5

 

5).自定义挂载方式

vim /etc/auto.master

最终挂载点的上层目录                 子策略文件

/nfs                                                  /etc/auto.nfs

vim 子策略文件(vim /etc/auto.nfs)

最终挂载点               网络挂载资源

nfs1                        172.25.254.250:/nfsshare/nfs1

*                               172.25.254.250:/nfsshare/&

systemctl restart autofs

 cd /nfs/nfs1

[root@westos nfs1]# df

Filesystem                    1K-blocks     Used Available Use% Mounted on

/dev/vda1                      10473900  3262308   7211592  32% /

devtmpfs                         927072        0    927072   0% /dev

tmpfs                            942660        0    942660   0% /dev/shm

tmpfs                            942660    16968    925692   2% /run

tmpfs                            942660        0    942660   0% /sys/fs/cgroup

/dev/vdb1                       1038336   749744    288592  73% /pub

172.25.254.250:/nfsshare/nfs1 100221952 57231360  42990592  58% /nfs/nfs1

#######################################

####第八单元ldap网络帐号####

#######################################

1.ldap是什么

ldap目录服务认证,和windows活动目录类似,就是记录数据的一种方式

 

2.ldap客户端所须软件

yum sssd krb5-workstation -y

 

3.如何开启ldap用户认证(图形)

authconfig-tui

 

                       ┌────────────────┤ Authentication Configuration ├─────────────────┐

                       │                                                                 │

                       │  User Information        Authentication                         │

                       │  [ ] Cache Information   [ ] Use MD5 Passwords                  │

                       │  [*] Use LDAP            [*] Use Shadow Passwords               │

                       │  [ ] Use NIS             [ ] Use LDAP Authentication            │

                       │  [ ] Use IPAv2           [*] Use Kerberos                       │

                       │  [ ] Use Winbind         [ ] Use Fingerprint reader             │

                       │                          [ ] Use Winbind Authentication         │

                       │                          [*] Local authorization is sufficient  │

                       │                                                                 │

                       │            ┌────────┐                      ┌──────┐             │

                       │            │ Cancel │                      │ Next │             │

                       │            └────────┘                      └──────┘             │

                       │                                                                 │

                       │                                                                 │

                       └─────────────────────────────────────────────────────────────────┘

                                                                                           

 

 

                              ┌─────────────────┤ LDAP Settings ├─────────────────┐

                              │                                                   │

                              │          [*] Use TLS                              │

                              │  Server: ldap://classroom.example.com/___________ │

                              │ Base DN: dc=example,dc=com_______________________ │

                              │                                                   │

                              │         ┌──────┐                ┌──────┐          │

                              │         │ Back │                │ Next │          │

                              │         └──────┘                └──────┘          │

                              │                                                   │

                              │                                                   │

                              └───────────────────────────────────────────────────┘

                                                                                    

 

 

 

                           ┌─────────────────┤ Kerberos Settings ├──────────────────┐

                           │                                                        │

                           │        Realm: EXAMPLE.COM_____________________________ │

                           │          KDC: classroom.example.com___________________ │

                           │ Admin Server: classroom.example.com___________________ │

                           │               [ ] Use DNS to resolve hosts to realms   │

                           │               [ ] Use DNS to locate KDCs for realms    │

                           │                                                        │

                           │          ┌──────┐                    ┌────┐            │

                           │          │ Back │                    │ Ok │            │

                           │          └──────┘                    └────┘            │

                           │                                                        │

                           │                                                        │

                           └────────────────────────────────────────────────────────┘

                                                                                     

<当出现以下报错时>

 

                                 ┌────────────────┤ Warning ├─────────────────┐

                                 │                                            │

                                 │ To connect to a LDAP server with TLS       │

                                 │ protocol enabled you need a CA certificate │

                                 │ which signed your server's certificate.    │

                                 │ Copy the certificate in the PEM format to  │

                                 │ the '/etc/openldap/cacerts' directory.     │

                                 │ Then press OK.                             │

                                 │                                            │

                                 │                  ┌────┐                    │

                                 │                  │ Ok │                    │

                                 │                  └────┘                    │

                                 │                                            │

                                 │                                            │

                                 └────────────────────────────────────────────┘

                                                                                

时因为tls的证书缺失,需要到服务器端下载所需要的证书到/etc/openldap/cacerts,

用到的命令

wget http://172.25.254.254/pub/example-ca.crt

 

<测试>

getent passwd ldapuser1

如果用户信息可以正常显示,证明客户端认成功。

 

脚本执行

vim /mnt/auto-config.sh

#!/bin/bash

echo "install packages..."

yum install sssd krb5-workstation autofs -y &> /dev/null

echo "config authconfig..."

authconfig \

--enableldap \

--enablekrb5 \

--disableldapauth \

--enableldaptls \

--ldapserver="classroom.example.com" \

--ldapbasedn="dc=example,dc=com" \

--ldaploadcacert=http://172.25.254.254/pub/example-ca.crt \

--krb5realm="EXAMPLE.COM" \

--krb5kdc="claddroom.example.com" \

--krb5adminserver="classroom.example.com" \

--update

echo "config autofs..."

echo "/home/guests /etc/auto.ldap" >>/etc/auto.master

echo "* 172.25.254.254:/home/guests/&" >>/etc/auto.ldap

echo "ok !!!"

systemctl restart autofs

 

————————————————————

测试:sh auth-config.sh

     id     ldapuser1

     su - ldapuser1

 

4.自动挂载用户家目录

yum install autofs -y

vim /etc/autofs.master

 --/home/guests /etc/auto.ldap

 

vim /etc/auto.ldap

ldapuser1 172.25.254.254:/home/guests/ldapuser1

*                  172.25.254.254:/home/guests/&

 

systemctl restart autofs                                

 

 

 

 

 

转载请注明原文地址: https://www.6miu.com/read-159.html

最新回复(0)