技术流ken

运维拯救世界

DAY5: 河北科技大学课堂记录–samba,ftp,dhcp,nfs,ntp

day4复习

 

网卡配置:

三种网络模式:

 

桥接模式:

可以通外网

其他主机可以和他进行通信

 

nat模式:

可以通外网

外部设备无法和它进行通信

 

仅主机模式

不可以通外网

其他设备也无法和它进行通信

 

网卡配置DHCP:

TYPE=Ethernet

ONBOOT=yes

DEVICE=eth0

BOOTPROTO=DHCP

 

网卡配置STATIC:

TYPE=Ethernet

ONBOOT=yes

DEVICE=eth0

BOOTPROTO=static

IPADDR=192.168.64.4

NETMASK=255.255.255.0

GATEWAY=192.168.64.1

DNS1=8.8.8.8

DNS2=114.114.114.114

 

RPM包管理

 

rpm使用

1.怎么使用rpm进行下载

rpm -ivh  软件包名

 

2. rpm卸载软件

rpm -e  软件名

 

3. rpm查询软件是否安装

rpm -q 软件名

 

4. rpm查询软件包生成的文件

rpm -ql 软件名

 

5. rpm查询一个命令所依赖的软件

rpm -qf `which apachectl`

 

6.rpm怎么查看所有已经安装的包

rpm -qa

 

 

yum管理软件包

 

yum 常用操作:

1. yum 安装软件

yum  install httpd lrzsz -y

 

2.yum卸载软件

yum remove httpd lrzsz -y

 

3. yum清除所有的缓存

yum clean all

 

4.yum查询已经安装的包

yum list installed

 

5.yum获取可以下载的包

yum list available

 

6. yum列出所有的包

yum list 、 yum list all

 

7.yum列出来所有可以用仓库

yum repolist

 

 

yum本地源配置过程:

第一步:在/etc/yum.repos.d目录下创建以.repo结尾的文件

vim /etc/yum.repos.d/local.repo

[ken]

name=ken

enabled=1

gpgcheck=0

baseurl=file:///ken    #是repodata所在路径

 

第二步:创建挂载点并挂载

mkdir /ken

mount /dev/cdrom /ken

 

第三步:开机自动挂载

方法一:

vim /etc/rc.local

mount /dev/cdrom /mnt

 

方法二:

vim /etc/fstab

/dev/cdrom /ken iso9660 defaults 0 0

 

第四步:清除缓存

yum clean all

yum repolist

 

 

网络源:确保自己的网络能通外网

[extra]
name=centos extra
enabled=1
gpgcheck=0
baseurl=https://mirrors.aliyun.com/centos/7/extras/x86_64/

[epel]
name=epel
enabled=1
gpgcheck=0
baseurl=https://mirrors.aliyun.com/epel/7Server/x86_64/

 

vsftpd服务–本地用户登录模式

第一步:下载vsftpd

yum install vsftpd -y

 

第二步:编辑配置文件

vim /etc/vsftpd/vstfpd.conf’

 

第三步:创建用户并设置密码

useradd ken && echo “123”  | passwd –stdin ken

 

第四步:查看IP

第五步:物理机访问

ftp://ip

 

systemctl常用操作

systemctl start vsftpd  #启动

systemctl restart vsftpd   #重启

systemctl stop  vsftpd #关闭

systemctl status  vsftpd  #查看运行状态

systemctl enable vsftpd #开机自启

systemctl disable vsftpd #开机不自启

 

关掉防火墙:

systemctl stop firewalld

systemctl disable firewalld

 

vsftpd匿名模式

 

第一步:下载

[root@ken ~]# yum install vsftpd -y

 

第二步:配置vsftpd文件

[root@ken ~]# vim /etc/vsftpd/vsftpd.conf

anon_upload_enable=YES

anon_mkdir_write_enable=YES

 

 

第三步:重启vsftpd

[root@ken ~]# systemctl restart vsftpd

 

第四步:访问

ftp://ip

 

第五步:查看权限

[root@ken ~]# find / -name “pub”
/var/ftp/pub

[root@ken ~]# ls -ld /var/ftp/pub/
drwxr-xr-x 2 root root 6 Oct 31 2018 /var/ftp/pub/

第六步:设置权限更改属主

[root@ken ~]# chown -R ftp: /var/ftp/pub

 

第七步:再次尝试创建文件

成功

 

第八步:是否可以删除文件

发现不可以

修改文件

vim /etc/vsftpd/vsftpd.conf

anon_other_write_enable=YES

 

第九步:重启服务

systemctl restart vsftpd

 

第十步:再次尝试删除

成功!

 

samba服务

 

实现了linux与window之间文件的共享

 

 

第一步:下载samba

[root@ken ~]# yum install samba -y

 

第二步:编辑配置文件

[root@ken ~]# vim /etc/samba/smb.conf

[文件共享]
path = /ken
read only = no
public = yes

 

第三步:创建目录

[root@ken ~]# mkdir /ken

 

第四步:创建一个用户

[root@ken ~]# useradd ken

 

第五步:把该用户设置为可以访问samba服务的用户

[root@ken ~]# pdbedit -a -u ken
new password:
retype new password:   #此密码是使用ken用户去访问samba服务的用户密码

 

第六步:重启samba

[root@ken ~]# systemctl restart smb

 

第七步:访问samba

\\192.168.64.4

 

第八步:修改权限

[root@ken ~]# ls -ld /ken
drwxr-xr-x 2 root root 6 Jun 25 10:08 /ken
[root@ken ~]# chmod -R o+w /ken

 

第九步:再次创建文件

成功!

 

ss命令

作用:可以查看端口信息

-t 显示tcp协议

-n 程序名转化为端口号

-l  处于监听状态的程序

-tnl

例子1:

[root@ken ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:445 *:*
LISTEN 0 50 *:139 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 50 :::445 :::*
LISTEN 0 50 :::139 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*

 

lsof

作用:查看某个端口属于哪个程序

-i

lsof命令需要下载:

[root@ken ~]# yum install lsof -y

例子1:

[root@ken ~]# lsof -i :22

 

web服务器占用的端口是80端口

 

解决xshell连接虚拟机慢的方法:

[root@ken ~]# vim /etc/ssh/sshd_config

UseDNS no

重启sshd服务

[root@ken ~]# systemctl restart ssh

 

虚拟机之间免密登录

第一步:生成秘钥

[root@ken ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:dR5EOKbT06TytYVZWVQzkrkymvNg7cC+UDiyr3szDDc root@ken
The key’s randomart image is:
+—[RSA 2048]—-+
| oo.o*=|
| +..o+ o|
| +.=o+. |
| =.+==o. |
| . oS=+o+o |
| .oEoO… |
| .+.+ * |
| .=.. o |
| o+.o.. |
+—-[SHA256]—–+

 

 

第二步:传送公钥

[root@ken ~]# ssh-copy-id 192.168.64.5

 

第三步:免密登录

[root@ken ~]# ssh 192.168.64.5

 

服务器端隐藏文件

id_rsa 保存了私钥信息

id_rsa.pub 保存了公钥信息

known_hosts 保存了发送秘钥的主机信息

 

客户端隐藏文件

authorized_keys  保存了公钥信息

 

exit退出连接中的主机

 

scp命令

作用:实现了主机之间文件的传输

-r 复制目录时使用

 

例子1:发送当前主机中的普通文件test2到另外一台主机

[root@ken ~]# scp test2 192.168.64.5:/root

 

例子2:把远程主机中的test2文件拉取到本地来

[root@ken ~]# scp 192.168.64.5:/root/test2 /root

 

例子3:把本地的一个目录推送到远程主机

[root@ken ~]# scp -r ken 192.168.64.5:/root

 

例子4:怎么把远程主机中的一个目录拉取到本地来

[root@ken ~]# scp -r 192.168.64.5:/root/ken .

 

ssh执行命令

 

ssh ip cmd

 

例子1:查看远程主机IP

[root@ken ~]# ssh 192.168.64.5 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:f4:23:f8 brd ff:ff:ff:ff:ff:ff
inet 192.168.64.5/24 brd 192.168.64.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fef4:23f8/64 scope link
valid_lft forever preferred_lft forever

 

例子2:远程主机安装samba

[root@ken ~]# ssh 192.168.64.5 yum install samba -y

 

 

NFS服务

 

第一步:下载相关软件包

[root@ken ~]# yum install nfs-utils rpcbind -y

 

第二步:编辑配置文件

[root@ken ~]# vim /etc/exports

/ken 192.168.64.5/24(rw)

 

第三步:创建共享目录

[root@ken ~]# mkdir /ken

 

第四步:修改权限

[root@ken ~]# chown -R nfsnobody: /ken
[root@ken ~]# ls -ld /ken
drwxr-xrwx 3 nfsnobody nfsnobody 88 Jun 25 10:13 /ken

 

第五步:启动相关服务

[root@ken ~]# systemctl restart rpcbind nfs

 

第六步:客户端也要下载nfs-utils

[root@ken ~]# yum install nfs-utils -y

 

第七步:查看服务器端共享信息

[root@ken ~]# showmount -e 192.168.64.4
Export list for 192.168.64.4:
/ken 192.168.64.5/24

 

第八步:创建挂载点

[root@ken ~]# mkdir /test

 

第九步:执行挂载操作

[root@ken ~]# mount -t nfs 192.168.64.4:/ken /test

 

第十步:查看挂载信息

[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.3G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.6M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.2G 4.2G 0 100% /mnt
192.168.64.4:/ken 17G 1.3G 16G 8% /test

 

第十一步:写入文件进行测试

 

NFS共享给所有人

/ken *(rw)

 

NFS共享多个目录

 

第一步:创建目录并设置权限

[root@ken ~]# mkdir /ken1

[root@ken ~]# chown -R nfsnobody: /ken1

 

第二步:编写exports文件

/ken 192.168.64.5(rw)
/ken1 192.168.64.7(rw)

 

第三步:重启nfs

[root@ken ~]# systemctl restart rpcbind nfs

 

第四步:差看共享信息

[root@ken ~]# showmount -e 192.168.64.4
Export list for 192.168.64.4:
/ken1 192.168.64.7
/ken 192.168.64.5

 

第五步:客户端进行验证操作

客户端一:

[root@ken ~]# mount -t nfs 192.168.64.4:/ken1 /test
mount.nfs: access denied by server while mounting 192.168.64.4:/ken1
[root@ken ~]# mount -t nfs 192.168.64.4:/ken /test
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.3G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.6M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.2G 4.2G 0 100% /mnt
192.168.64.4:/ken 17G 1.3G 16G 8% /test

 

客户端二:

[root@ken ~]# mount -t nfs 192.168.64.4:/ken1 /test1

[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.1G 16G 7% /
devtmpfs 224M 0 224M 0% /dev
tmpfs 236M 0 236M 0% /dev/shm
tmpfs 236M 5.6M 230M 3% /run
tmpfs 236M 0 236M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 48M 0 48M 0% /run/user/0
/dev/sr0 4.2G 4.2G 0 100% /mnt
192.168.64.4:/ken1 17G 1.3G 16G 8% /test1

 

DHCP服务

 

第一步:环境准备

1,添加一块仅主机模式的网卡

2,把vmware自动的仅主机模式中的DCHP服务不启用

 

第二步:配置仅主机模式的网络

[root@ken ~]# cd /etc/sysconfig/network-scripts/

[root@ken network-scripts]# cp ifcfg-eth0 ifcfg-eth1

[root@ken network-scripts]# vim ifcfg-eth1

DEVICE=”eth1″
ONBOOT=yes
NETBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.168.182.4
NETMASK=255.255.255.0

 

第三步:重启网络

[root@ken network-scripts]# systemctl restart network

 

第四步:下载dhcp软件包

[root@ken ~]# yum install dhcp -y

 

第五步:配置dhcp服务

[root@ken ~]# vim /etc/dhcp/dhcpd.conf

subnet 192.168.182.0 netmask 255.255.255.0 {
range 192.168.182.20 192.168.182.40;
default-lease-time 600;
max-lease-time 7200;
}

第六步:重启dhcp服务

[root@ken ~]# systemctl restart dhcpd

 

第七步:客户端进行验证

添加王卡即可

 

NTP服务

 

第一步:下载ntp服务

[root@ken ~]# yum install ntp -y

 

第二步: 修改ntp配置文件

[root@ken ~]# vim /etc/ntp.conf

server 127.127.1.0
restrict 127.0.0.1
restrict 192.168.64.5 mask 255.255.255.0
restrict 192.168.64.7 mask 255.255.255.0

 

第三步:重启ntp服务

[root@ken ~]# systemctl restart ntpd

 

第四步:查看ntp服务状态

[root@ken ~]# ntpstat
synchronised to local net at stratum 6
time correct to within 7948 ms
polling server every 64 s

 

第五步:客户端下载ntpdate

[root@ken ~]# yum install ntpdate -y

 

第六步:时间同步

[root@ken ~]# ntpdate 192.168.64.4
26 Jun 00:16:14 ntpdate[2751]: step time server 192.168.64.4 offset -16475786.577923 sec

 

同步网络时间:

ntpdate time1.aliyun.com

 

[root@ken ~]# ntpdate time1.aliyun.com
25 Jun 16:17:49 ntpdate[2754]: step time server 203.107.6.88 offset -28786.471584 sec
[root@ken ~]# date
Tue Jun 25 16:17:51 CST 2019

10 thoughts on “DAY5: 河北科技大学课堂记录–samba,ftp,dhcp,nfs,ntp

  1. Thank you so much for giving everyone remarkably remarkable possiblity to read articles and blog posts from this site. It is often so superb and as well , packed with a lot of fun for me personally and my office mates to search your site no less than thrice every week to see the new stuff you will have. And lastly, I am also usually astounded concerning the dazzling tips and hints you serve. Selected 2 tips on this page are really the finest we’ve had.

  2. Thanks so much for providing individuals with remarkably breathtaking possiblity to read articles and blog posts from here. It is always very pleasant and also stuffed with a lot of fun for me and my office friends to search your web site really thrice a week to learn the fresh items you will have. And lastly, we are usually astounded with the very good guidelines you serve. Certain 2 facts in this post are rather the most beneficial we’ve ever had.

  3. I precisely needed to thank you very much again. I do not know what I would’ve used without the actual secrets revealed by you about this field. Certainly was an absolute alarming scenario in my circumstances, but observing a new specialised fashion you solved the issue took me to leap with delight. I am just grateful for your service and then hope you recognize what an amazing job you happen to be getting into teaching people today all through your blog. More than likely you haven’t got to know any of us.

  4. I am just commenting to let you be aware of of the fine experience my child undergone studying your webblog. She realized plenty of issues, with the inclusion of what it is like to possess an excellent teaching heart to let certain people really easily comprehend specified multifaceted matters. You actually surpassed people’s desires. Thank you for displaying these precious, trustworthy, explanatory and easy tips about your topic to Kate.

  5. I want to show some thanks to this writer just for rescuing me from such a matter. After checking through the search engines and meeting notions that were not productive, I believed my entire life was done. Living without the approaches to the difficulties you’ve resolved by means of the posting is a serious case, and those that might have negatively damaged my career if I hadn’t come across your website. Your actual capability and kindness in touching the whole lot was useful. I am not sure what I would’ve done if I hadn’t come upon such a solution like this. It’s possible to now look forward to my future. Thank you very much for your high quality and results-oriented guide. I will not think twice to refer your web page to any individual who needs to have support about this problem.

  6. I and also my pals were found to be viewing the great hints on your web site and then instantly got a terrible suspicion I had not thanked the web blog owner for those techniques. Those women are actually as a consequence passionate to read all of them and now have clearly been taking advantage of these things. Thank you for getting indeed kind and for going for this kind of beneficial issues millions of individuals are really eager to be informed on. My personal honest apologies for not saying thanks to sooner.

  7. I want to express appreciation to this writer just for rescuing me from this particular problem. Right after checking through the search engines and coming across strategies which are not productive, I believed my entire life was well over. Living without the presence of approaches to the issues you have sorted out through this review is a crucial case, and the ones which could have negatively affected my career if I had not come across your site. Your own training and kindness in dealing with every item was important. I don’t know what I would’ve done if I had not come upon such a point like this. I am able to now look forward to my future. Thanks so much for your impressive and amazing help. I will not be reluctant to endorse your web sites to any individual who would need support about this issue.

  8. I want to show my admiration for your kindness supporting folks who must have help on that content. Your very own commitment to getting the message across became wonderfully valuable and have continuously allowed those just like me to reach their endeavors. This interesting report denotes a great deal to me and a whole lot more to my office workers. With thanks; from all of us.

3进行回复 取消回复

电子邮件地址不会被公开。