Linux小实验

实验前提条件:
开启防火墙
关闭selinux(开启加分)setenforce 0
主机名为:姓名全拼 hostnamectl set-hostname liyixuan
IP地址:192.168.x.0/24网段(x为你的组号) nmcli connection add con-name lyx type ethernet ifname ens33 ip4 192.168.5.1/24 gw4 192.168.5.1

实验要求:
1、A服务器和B服务器之间互做免密
2、在B服务器上搭建日志服务器
3、在A服务器上搭建FTP服务器,并允许用户soul登录读写
4、在B服务器上搭建DNS服务器,解析域名:super.wuban.com和man.wuban.com
IP地址分别为:192.168.x.100和192.168.x.200
5、在A服务器上搭建Apache服务器,域名为:super.wuban.com和man.wuban.com,网站主目录在/opt/wu/下,只允许192.168.x.10的用户通过火狐浏览器访问
6、使用宿主机可以访问所有的服务

1.A服务器和B服务器之间互做免密
A服务器
[root@liyixuan ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)?
[root@liyixuan ~]# ssh-copy-id 192.168.5.2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/root/.ssh/id_rsa.pub”
The authenticity of host ‘192.168.1.40 (192.168.1.40)’ can’t be established.
ECDSA key fingerprint is SHA256:t2cA2xqsHKsA6wuRRWhDAU+jIvA6p9c0q8yW4HrlrUU.
ECDSA key fingerprint is MD5:be:ad:6e:3b:74:e4:8d:e6:17:e6:15:a2:53:0f:f5:d2.
Are you sure you want to continue connecting (yes/no)? yes
already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
[email protected]’s password:
B服务器
[root@liyixuan ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:p8a6iCtQ34ItbnkaUS98FYF+/EXB7kGzDx9Vytsdzfc root@liyixuan
The key’s randomart image is:
+—[RSA 2048]—-+
| .o. … o|
| . . =. oo|
| .. .. + ooo+|
| .o …o * .o=|
| ..+o.o.S..o =..E|
|. o.+o.. o. . o |
|…o . + |
|. +o.. o |
| o++. o. |
+—-[SHA256]—–+
root@liyixuan ~]# ssh-copy-id 192.168.5.1
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
[email protected]’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘192.168.5.1’”
and check to make sure that only the key(s) you wanted were added.
A测试
[root@liyixuan ~]# ssh 192.168.5.2
Last login: Wed Jun 27 06:27:54 2018 from 192.168.5.1
[root@liyixuan ~]# ifconfig
ens33: flags=4163

Package Arch Version Repository Size

Installing:
vsftpd x86_64 3.0.2-22.el7 name 169 k

Transaction Summary

Install 1 Package

Total download size: 169 k
Installed size: 348 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-22.el7.x86_64 1/1
name/productid | 1.6 kB 00:00
Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1

Installed:
vsftpd.x86_64 0:3.0.2-22.el7

Complete!

编辑配置文件[root@liyixuan ~]# vim /etc/vsftpd/vsftpd.conf
12 #anonymous_enable=YES ——匿名用户可访问注释掉
重启服务[root@liyixuan ~]# systemctl restart vsftpd
防火墙允许ftp访问 [root@liyixuan ~]# firewall-cmd –add-service=ftp
success
创建用户
[root@liyixuan ~]# useradd soul
[root@liyixuan ~]# passwd soul
Changing password for user soul.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
在共享目录下创建文件
[root@liyixuan ~]# cd /home/soul/
[root@liyixuan soul]# touch 1.txt
[root@liyixuan soul]# chmod 777 1.txt

B 搭建yum
[root@yixuan yum.repos.d]# yum install ftp -y
测试
[root@yixuan yum.repos.d]# ftp 192.168.5.1
Connected to 192.168.5.1 (192.168.5.1).
220 (vsFTPd 3.0.2)
Name (192.168.5.1:root): soul
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,5,1,213,153).
150 Here comes the directory listing.
-rwxrwxrwx 1 0 0 0 Jun 27 07:41 1.txt
226 Directory send OK.
ftp> get 1.txt
local: 1.txt remote: 1.txt
227 Entering Passive Mode (192,168,5,1,195,21).
150 Opening BINARY mode data connection for 1.txt (0 bytes).
226 Transfer complete.

4、在B服务器上搭建DNS服务器,解析域名:super.wuban.com和man.wuban.com
IP地址分别为:192.168.x.100和192.168.x.200
正想解析(根据域名找ip)
安装bind
[root@yixuan ~]# yum install nin* -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
No package nin* available.
Error: Nothing to do
[root@yixuan ~]# yum install bin* -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Package 32:bind-libs-9.9.4-50.el7.x86_64 already installed and latest version
Package 32:bind-utils-9.9.4-50.el7.x86_64 already installed and latest version
Package 32:bind-license-9.9.4-50.el7.noarch already installed and latest version
Package 32:bind-libs-lite-9.9.4-50.el7.x86_64 already installed and latest version
Package binutils-2.25.1-31.base.el7.x86_64 already installed and latest version
Resolving Dependencies
–> Running transaction check
—> Package bind.x86_64 32:9.9.4-50.el7 will be installed
—> Package bind-chroot.x86_64 32:9.9.4-50.el7 will be installed
—> Package bind-dyndb-ldap.x86_64 0:11.1-3.el7 will be installed
—> Package bind-pkcs11.x86_64 32:9.9.4-50.el7 will be installed
—> Package bind-pkcs11-libs.x86_64 32:9.9.4-50.el7 will be installed
—> Package bind-pkcs11-utils.x86_64 32:9.9.4-50.el7 will be installed
—> Package binutils-devel.x86_64 0:2.25.1-31.base.el7 will be installed
–> Processing Dependency: zlib-devel for package: binutils-devel-2.25.1-31.base.el7.x86_64
–> Running transaction check
—> Package zlib-devel.x86_64 0:1.2.7-17.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================

Package Arch Version Repository Size

Installing:
bind x86_64 32:9.9.4-50.el7 server 1.8 M
bind-chroot x86_64 32:9.9.4-50.el7 server 86 k
bind-dyndb-ldap x86_64 11.1-3.el7 server 122 k
bind-pkcs11 x86_64 32:9.9.4-50.el7 server 297 k
bind-pkcs11-libs x86_64 32:9.9.4-50.el7 server 1.1 M
bind-pkcs11-utils x86_64 32:9.9.4-50.el7 server 197 k
binutils-devel x86_64 2.25.1-31.base.el7 server 845 k
Installing for dependencies:
zlib-devel x86_64 1.2.7-17.el7 server 50 k

Transaction Summary

Install 7 Packages (+1 Dependent package)

Total download size: 4.5 M
Installed size: 14 M

Downloading packages:

Total 14 MB/s | 4.5 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 32:bind-9.9.4-50.el7.x86_64 1/8
Installing : 32:bind-pkcs11-libs-9.9.4-50.el7.x86_64 2/8
Installing : zlib-devel-1.2.7-17.el7.x86_64 3/8
Installing : binutils-devel-2.25.1-31.base.el7.x86_64 4/8
Installing : 32:bind-pkcs11-9.9.4-50.el7.x86_64 5/8
Installing : 32:bind-pkcs11-utils-9.9.4-50.el7.x86_64 6/8
Installing : 32:bind-chroot-9.9.4-50.el7.x86_64 7/8
Installing : bind-dyndb-ldap-11.1-3.el7.x86_64 8/8
Enabling SELinux boolean named_write_master_zones
Verifying : zlib-devel-1.2.7-17.el7.x86_64 1/8
Verifying : 32:bind-pkcs11-9.9.4-50.el7.x86_64 2/8
Verifying : 32:bind-chroot-9.9.4-50.el7.x86_64 3/8
Verifying : 32:bind-pkcs11-utils-9.9.4-50.el7.x86_64 4/8
Verifying : bind-dyndb-ldap-11.1-3.el7.x86_64 5/8
Verifying : 32:bind-pkcs11-libs-9.9.4-50.el7.x86_64 6/8
Verifying : 32:bind-9.9.4-50.el7.x86_64 7/8
Verifying : binutils-devel-2.25.1-31.base.el7.x86_64 8/8
Installed:
bind.x86_64 32:9.9.4-50.el7
bind-chroot.x86_64 32:9.9.4-50.el7
bind-dyndb-ldap.x86_64 0:11.1-3.el7
bind-pkcs11.x86_64 32:9.9.4-50.el7
bind-pkcs11-libs.x86_64 32:9.9.4-50.el7
bind-pkcs11-utils.x86_64 32:9.9.4-50.el7
binutils-devel.x86_64 0:2.25.1-31.base.el7
Dependency Installed:
zlib-devel.x86_64 0:1.2.7-17.el7
Complete!
[root@yixuan ~]# vim /etc/named.conf
允许任何主机监听
允许任何主机访问
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory “/var/named”;
dump-file “/var/named/data/cache_dump.db”;
statistics-file “/var/named/data/named_stats.txt”;
memstatistics-file “/var/named/data/named_mem_stats.txt”;
allow-query { any; };

    /* 
     - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.

– INSERT –
在52行加注释
51
52 #zone “.” IN {
53 # type hint;
54 # file “named.ca”;
55 #};

区域配置
[root@yixuan ~]# vim /etc/named.rfc1912.zones
删除所有配置
重新编辑
acl “super” { 192.168.1.0/24; };
acl “man” { 192.168.1.0/24; };
view “super” {
match-clients { “super”; };
zone “wuban.com” {
type master;
file “wuban.com.super”;
};
};

view “man” {
match-clients { “man”; };
zone “wuban.com” {
type master;
file “wuban.com.man”;
};
};

[root@yixuan ~]# cd /var/named/
[root@yixuan named]# ls
chroot dynamic named.ca named.localhost slaves
data dyndb-ldap named.empty named.loopback

[root@yixuan named]# cp named.localhost wuban.com.super
[root@yixuan named]# cp named.localhost wuban.com.man
$TTL 1D
@ IN SOA ns1.wuban.com. root.wuban.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ns1.wuban.com.
ns1 A 192.168.5.2
super A 192.168.5.100

[root@yixuan named]# vim wuban.com.man
~ $TTL 1D
@ IN SOA ns1 wuban.com. root.wuban.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ns1.wuban.com.
ns1 A 192.168.5.2
man A 192.168.5.200
~

[root@yixuan named]# chown :named ./wuban.com.man
[root@yixuan named]# chown :named ./wuban.com.super

重启dns [root@yixuan named]# systemctl restart named
开启防火墙 [root@yixuan named]# firewall-cmd –add-service=dns
Success
[root@yixuan ~]# vim /etc/resolv.conf
nameserver 192.168.5.2
[root@yixuan ~]# nslookup super.wuban.com
Server: 192.168.5.2
Address: 192.168.5.2#53

Name: super.wuban.com
Address: 192.168.5.100

wuban.com.man.zone

A安装
[root@liyixuan ~]# yum install bind* -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
name | 4.1 kB 00:00
Package 32:bind-libs-9.9.4-50.el7.x86_64 already installed and latest version
Package 32:bind-utils-9.9.4-50.el7.x86_64 already installed and latest version
Package 32:bind-license-9.9.4-50.el7.noarch already installed and latest version
Package 32:bind-libs-lite-9.9.4-50.el7.x86_64 already installed and latest version
Resolving Dependencies
–> Running transaction check
—> Package bind.x86_64 32:9.9.4-50.el7 will be installed
—> Package bind-chroot.x86_64 32:9.9.4-50.el7 will be installed
—> Package bind-dyndb-ldap.x86_64 0:11.1-3.el7 will be installed
—> Package bind-pkcs11.x86_64 32:9.9.4-50.el7 will be installed
—> Package bind-pkcs11-libs.x86_64 32:9.9.4-50.el7 will be installed
—> Package bind-pkcs11-utils.x86_64 32:9.9.4-50.el7 will be installe
Installed:
bind.x86_64 32:9.9.4-50.el7
bind-chroot.x86_64 32:9.9.4-50.el7
bind-dyndb-ldap.x86_64 0:11.1-3.el7
bind-pkcs11.x86_64 32:9.9.4-50.el7
bind-pkcs11-libs.x86_64 32:9.9.4-50.el7
bind-pkcs11-utils.x86_64 32:9.9.4-50.el7

Complete!
[root@liyixuan ~]# systemctl restart named
[root@liyixuan ~]# vim /etc/resolv.conf

Generated by NetworkManager

nameserver 192.168.5.2
[root@liyixuan ~]# vim /etc/host
192.168.5.2 ns1.wuban.com
[root@liyixuan ~]# systemctl restart network
[root@liyixuan ~]# nslookup

super.wuban.com
Server: 192.168.5.2
Address: 192.168.5.2#53

Name: super.wuban.com
Address: 192.168.5.100

man.zone.wuban.com
Server: 192.168.5.2
Address: 192.168.5.2#53
Name: man.wuban.com
Address: 192.168.1.200

5、在A服务器上搭建Apache服务器,域名为:super.wuban.com和man.wuban.com,网站主目录在/opt/wu/下,只允许192.168.x.10的用户通过火狐浏览器访问
A
[root@liyixuan ~]# yum install httpd -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.4.6-67.el7 will be installed
–> Processing Dependency: httpd-tools = 2.4.6-67.el7 for package: httpd-2.4.6-67.el7.x86_64
–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-67.el7.x86_64
–> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.x86_64
–> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.x86_64
–> Running transaction check
—> Package apr.x86_64 0:1.4.8-3.el7 will be installed
—> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
—> Package httpd-tools.x86_64 0:2.4.6-67.el7 will be installed
—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
Installed:
httpd.x86_64 0:2.4.6-67.el7

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-67.el7 mailcap.noarch 0:2.1.41-2.el7

Complete!
打开防火墙——允许HTTP服务通过
[root@liyixuan ~]# firewall-cmd –add-service=http
success
添加两个网卡
设置ip
192.168.5.100/24
192.168.5.200/24
[root@liyixuan ~]# vim /etc/host
192.168.5.2 ns1.wuban.com
192.168.5.100 super.wuban.com
192.168.5.200 man..wuban.com

[root@liyixuan ~]# vim /etc/resolv.conf

Generated by NetworkManager

nameserver 192.168.5.2
[root@liyixuan ~]# cd /opt/
[root@liyixuan opt]# mkdir wu
Mkdir 1
Mkdir 2
[root@liyixuan 1]# echo “1” > index.html
[root@liyixuan 2]# echo “2” > index.html
[root@liyixuan ~]# chmod -R 777 /opt/
[root@liyixuan ~]# cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/
[root@liyixuan ~]# vim /etc/httpd/httpd-vhosts.conf
lHost super.wuban.com>
DocumentRoot “/opt/wu/1/”

你可能感兴趣的:(Linux小实验)