对虚拟机进行的操作
虚拟机的网络配置
[root@localhost yum.repos.d]# hostnamectl set-hostnameserverx.exampel.com
[root@localhost yum.repos.d]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-eth0
ifdown-ppp
ifup-eth
ifup-s
[root@localhost network-scripts]# rm -fr ifcfg-eth0
[root@localhost network-scripts]# vim ifcfg-eth0
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>
mtu 1500
inet 172.25.20.11
netmask 255.255.255.0
broadcast 172.25.20.255
inet6fe80::5054:ff:fe00:330a
prefixlen64
scopeid 0x20<link>
ether 52:54:00:00:33:0a
txqueuelen 1000
(Ethernet)
RX packets 125
bytes 5562 (5.4 KiB)
RX errors 0
dropped 0 overruns 0
frame 0
TX packets 866
bytes 42032 (41.0 KiB)
TX errors 0
dropped 0 overruns 0
carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1
netmask 255.0.0.0
inet6 ::1
prefixlen 128 scopeid 0x10<host>
loop
txqueuelen 0 (Local Loopback)
RX packets 565
bytes 55442 (54.1 KiB)
RX errors 0
dropped 0 overruns 0
frame 0
TX packets 565
bytes 55442 (54.1 KiB)
TX errors 0
dropped 0 overruns 0
carrier 0 collisions 0
1.修改虚拟机root密码
passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost Desktop]# etho "westosExam" |passwd --stdinroot
Changing password for user root.
bash: etho: command not found...
passwd: Authentication token manipulation error
[root@localhost Desktop]# etho "westosExam" |passwd --stdinro^C
[root@localhost Desktop]#
[root@localhost Desktop]# echo "westosExam" |passwd --stdinroot
Changing password for user root.
passwd: all authentication tokens updated successfully.
2.为系统配置一个默认的ruanjiancangku
[root@localhost Desktop]# df
Filesystem
1K-blocks
Used Available Use% Mounted on
/dev/vda1
10473900 3157728
7316172 31% /
devtmpfs
927072
0 927072
0% /dev
tmpfs
942660
140 942520
1% /dev/shm
tmpfs
942660
17012 925648
2% /run
tmpfs
942660
0 942660
0% /sys/fs/cgroup
/dev/mapper/vg0-vo
483670
2367 451812
1% /home
/dev/sr0
3947824 3947824
0 100% /run/media/root/RHEL-7.2Server.x86_64
[root@localhost Desktop]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost Desktop]# df
Filesystem
1K-blocks
Used Available Use% Mounted on
/dev/vda1
10473900 3157636
7316264 31% /
devtmpfs
927072
0 927072
0% /dev
tmpfs
942660
140 942520
1% /dev/shm
tmpfs
942660
17012 925648
2% /run
tmpfs
942660
0 942660
0% /sys/fs/cgroup
/dev/mapper/vg0-vo
483670
2367 451812
1% /home
/dev/sr0
3947824 3947824
0 100% /mnt
[root@localhost Desktop]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -fr *
[root@localhost yum.repos.d]# vim westos.repo
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: langpacks
Cleaning repos: rhel7
Cleaning up everything
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: langpacks
rhel7 | 4.1 kB
00:00
(1/2): rhel7/group_gz
| 136kB
00:00
(2/2): rhel7/primary_db |
3.6 MB
00:00
repo id repo name status
rhel7 rhel7 4,620
repolist: 4,620
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# systemctl stop firewalld
[root@localhost yum.repos.d]# yum install httpd -y
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-40.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-40.el7 for package:httpd-2.4.6-40.el7.x86_64
--> Processing Dependency: /etc/mime.types for package:httpd-2.4.6-40.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package:httpd-2.4.6-40.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package:httpd-2.4.6-40.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-40.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package
Arch Version Repository
Size
================================================================================
Installing:
httpd
x86_64
2.4.6-40.el7
rhel7
1.2 M
Installing for dependencies:
apr
x86_64
1.4.8-3.el7
rhel7
103 k
apr-util
x86_64
1.5.2-6.el7
rhel7
92 k
httpd-tools
x86_64
2.4.6-40.el7
rhel7
82 k
mailcap noarch
2.1.41-2.el7
rhel7
31 k
Transaction Summary
================================================================================
Install
1 Package (+4 Dependentpackages)
Total download size: 1.5 M
Installed size: 4.3 M
Downloading packages:
--------------------------------------------------------------------------------
Total 6.7 MB/s | 1.5 MB
00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing :apr-1.4.8-3.el7.x86_64
1/5
Installing :apr-util-1.5.2-6.el7.x86_64
2/5
Installing :httpd-tools-2.4.6-40.el7.x86_64 3/5
Installing :mailcap-2.1.41-2.el7.noarch
4/5
Installing :httpd-2.4.6-40.el7.x86_64
5/5
Verifying
: mailcap-2.1.41-2.el7.noarch
1/5
Verifying
: httpd-tools-2.4.6-40.el7.x86_64
2/5
Verifying
: apr-1.4.8-3.el7.x86_64
3/5
Verifying
: apr-util-1.5.2-6.el7.x86_64
4/5
Verifying
: httpd-2.4.6-40.el7.x86_64
5/5
Installed:
httpd.x86_64 0:2.4.6-40.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-40.el7
mailcap.noarch 0:2.1.41-2.el7
Complete!
[root@serverx rhel7.0]# systemctl stop firewalld
[root@serverx rhel7.0]# systemctl disable firewalld
[root@serverx rhel7.0]# systemctl enable httpd
[root@serverx rhel7.0]# mkdir -p /var/www/html/rhel7.0/x86_64/dvd
[root@serverx rhel7.0]# mount /dev/sr0 /var/www/html/rhel7.0/x86_64/dvd/
mount: /dev/sr0 is write-protected, mounting read-only
[root@serverx rhel7.0]# df
Filesystem
1K-blocks
Used Available Use% Mounted on
/dev/vda1
10473900 3188356
7285544 31% /
devtmpfs
927072
0 927072
0% /dev
tmpfs
942660
140 942520
1% /dev/shm
tmpfs
942660
17060 925600
2% /run
tmpfs
942660
0 942660
0% /sys/fs/cgroup
/dev/mapper/vg0-vo
483670
2367 451812
1% /home
/dev/sr0
3947824 3947824
0 100%/var/www/html/rhel7.0/x86_64/dvd
[root@serverx rhel7.0]# vim /etc/yum.repos.d/westos.repo
[root@serverx rhel7.0]# cat /etc/yum.repos.d/westos.repo
[rhel7.0]
name=rhel7.0
baseurl=http://172.25.20.11/rhel7.0/x86_64/dvd
gpgcheck=0
enabled=1
[root@serverx rhel7.0]# yum clean all
Loaded plugins: langpacks
Cleaning repos: InstallMedia rhel7.0
Cleaning up everything
[root@serverx rhel7.0]# systemctl restart network
[root@serverx rhel7.0]# yum repolist
Loaded plugins: langpacks
rhel7.0 | 4.1 kB
00:00
(1/2): rhel7.0/group_gz
| 136 kB
00:00
(2/2): rhel7.0/primary_db
| 3.6 MB
00:00
repo id
reponame status
rhel7.0 rhel7.0 4,620
repolist: 4,620
3.创建用户帐号和用户组
[root@serverx Desktop]# groupadd sysmgrs
[root@serverx Desktop]# cat /etc/group |tail -n 3
westos:x:1008:
apache:x:48:
sysmgrs:x:1009:
[root@serverx Desktop]# useradd -G 1009 natasha
[root@serverx Desktop]# useradd -G 1009 harry
[root@serverx Desktop]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
[root@serverx Desktop]# useradd -s /sbin/nologin sarah
[root@serverx Desktop]# cat /etc/passwd |tail-n 3
natasha:x:1009:1010::/home/natasha:/bin/bash
harry:x:1010:1011::/home/harry:/bin/bash
sarah:x:1011:1012::/home/sarah:/sbin/nologin
[root@serverx Desktop]# echo "westosExam" |passwd --stdinnatasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@serverx Desktop]# echo "westosExam" |passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@serverx Desktop]# echo "westosExam" |passwd --stdin sarah
Changing password for user sarah.
passwd: all authentication tokens updated successfully.
4.对配置文件/var/tmp/fstab
的权限
[root@serverx Desktop]# cp /etc/fstab /var/tmp/fstab
[root@serverx Desktop]# ls -l /var/tmp/fstab
-rw-r--r-- 1 root root 349 Oct 30 11:47 /var/tmp/fstab
[root@serverx Desktop]# chown root /var/tmp/fstab
[root@serverx Desktop]# chgrp root /var/tmp/fstab
[root@serverx Desktop]# setfacl -m u:natasha:rw- /var/tmp/fstab
[root@serverx Desktop]# setfacl -m u:harry:--- /var/tmp/fstab
[root@serverx Desktop]# getfacl /var/tmp/fstab
getfacl: Removing leading '/' from absolute path names
# file: var/tmp/fstab
# owner: root
# group: root
user::rw-
user:natasha:rw-
user:harry:---
group::r--
mask::rw-
other::r--
5.创建一个共享目录
[root@serverx Desktop]# mkdir /home/managers
[root@serverx Desktop]# ls -lr /home/managers/
total 0
[root@serverx Desktop]# getfacl /home/managers/
getfacl: Removing leading '/' from absolute path names
# file: home/managers/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
[root@serverx Desktop]# chgrp sysmgrs /home/managers/
[root@serverx Desktop]# getfacl /home/managers/
getfacl: Removing leading '/' from absolute path names
# file: home/managers/
# owner: root
# group: sysmgrs
user::rwx
group::r-x
other::r-x
[root@serverx Desktop]# chmod 050 /home/managers/
[root@serverx Desktop]# getfacl /home/managers/
getfacl: Removing leading '/' from absolute path names
# file: home/managers/
# owner: root
# group: sysmgrs
user::---
group::r-x
other::---
[root@serverx Desktop]# chmod 2050 /home/managers/
[root@serverx Desktop]# getfacl /home/managers/
getfacl: Removing leading '/' from absolute path names
# file: home/managers/
# owner: root
# group: sysmgrs
# flags: -s-
user::---
group::r-x
other::---
6.安装lftp,并将安装后产生的信息保存到/mnt/lftp.txt
[root@serverx Desktop]# yum search lftp
Loaded plugins: langpacks
============================== N/S matched: lftp===============================
lftp.i686 : A sophisticated file transfer program
lftp.x86_64 : A sophisticated file transfer program
Name and summary matches only, use"search all" for everything.
[root@serverx Desktop]# yum install lftp.x86_64 -y
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package lftp.x86_64 0:4.4.8-7.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package
Arch
Version
Repository
Size
================================================================================
Installing:
lftp
x86_64
4.4.8-7.el7
rhel7.0
750 k
Transaction Summary
================================================================================
Install
1 Package
Total download size: 750 k
Installed size: 2.4 M
Downloading packages:
lftp-4.4.8-7.el7.x86_64.rpm
| 750 kB
00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing :lftp-4.4.8-7.el7.x86_64
1/1
Verifying
: lftp-4.4.8-7.el7.x86_64
1/1
Installed:
lftp.x86_64 0:4.4.8-7.el7
Complete!
[root@serverx Desktop]# touch /mnt/lftp.txt
[root@serverx Desktop]# yum info lftp.x86_64 |tee /mnt/lftp.txt
Loaded plugins: langpacks
Installed Packages
Name
: lftp
Arch
: x86_64
Version
: 4.4.8
Release
: 7.el7
Size
: 2.4 M
Repo
: installed
From repo
: rhel7.0
Summary
: A sophisticated filetransfer program
URL
: http://lftp.yar.ru/
License
: GPLv3+
Description : LFTP is a sophisticated ftp/http file transfer program. Likebash,
: it has job control and usesthe readline library for input. It has
: bookmarks, built-inmirroring, and can transfer several files in
: parallel. It is designedwith reliability in mind.
7.配置主机与真机时间同步
[root@serverx Desktop]# systemctl stop firewalld
[root@serverx Desktop]# vim /etc/chrony.conf
[root@serverx Desktop]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.rhel.pool.ntp.org iburst
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 3.rhel.pool.ntp.org iburst
server 172.25.254.51 iburst
# Ignore stratum in source selection.
stratumweight 0
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Enable kernel RTC synchronization.
rtcsync
# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3
# Allow NTP client access from local network.
#allow 192.168/16
# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
# Serve time even if not synchronized to any NTP server.
#local stratum 10
keyfile /etc/chrony.keys
# Specify the key used as password for chronyc.
commandkey 1
# Generate command key if missing.
generatecommandkey
# Disable logging of client accesses.
noclientlog
# Send a message to syslog if a clock adjustment is larger than 0.5seconds.
logchange 0.5
logdir /var/log/chrony
#log measurements statistics tracking
[root@serverx Desktop]# systemctl restart chronyd.service
无密码连接测试
[root@serverx Desktop]# ssh root@172.25.254.51
Last login: Wed Nov
1 00:38:332017
[root@foundation51 ~]#
8.归档与文件操作
[root@serverx Desktop]# tar zcf /root/backup.tar.gz /usr/local/
tar: Removing leading `/' from member names
[root@serverx Desktop]# cd /root/
[root@serverx ~]# ls
anaconda-ks.cfg
Desktop
Downloads Pictures
Templates
backup.tar.gz
Documents
Music Public
Videos
b)
find /bin/ -name '*[[:upper:]]*' |tee/mnt/binFile.txt|wc -l >>/mnt/binFIle.txt
9.配置一个cron任务
[root@serverx Desktop]# crontab -u natasha -e
crontab: installing new crontab
"23 14 * * * mail -s test root </etc/passwd"
对真机进行的操作
[kiosk@foundation51 Desktop]$ su - root
Password:
Last login: Thu Oct 26 20:25:54 CST 2017 on pts/0
[root@foundation51 ~]# systemctl stop firewalld
[root@foundation51 ~]# vim /etc/chrony.conf
[root@foundation51 ~]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 172.25.254.254 iburst
# Ignore stratum in source selection.
stratumweight 0
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Enable kernel RTC synchronization.
rtcsync
# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3
# Allow NTP client access from local network.
#allow 192.168/16
allow 172.25.254.0/24
# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
# Serve time even if not synchronized to any NTP server.
local stratum 10
keyfile /etc/chrony.keys
# Specify the key used as password for chronyc.
commandkey 1
# Generate command key if missing.
generatecommandkey
# Disable logging of client accesses.
noclientlog
# Send a message to syslog if a clock adjustment is larger than 0.5seconds.
logchange 0.5
logdir /var/log/chrony
#log measurements statistics tracking
[root@foundation51 ~]# systemctl restart chronyd.service
7.2是虚拟机可以无密码连接真机
[kiosk@foundation51 Desktop]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kiosk/.ssh/id_rsa):
/home/kiosk/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/kiosk/.ssh/id_rsa.
Your public key has been saved in /home/kiosk/.ssh/id_rsa.pub.
The key fingerprint is:
75:ac:ed:7c:f3:23:28:1c:9c:54:4f:5b:10:63:fc:4ekiosk@foundation51.ilt.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|
.=o
|
|
o.o.. |
|
o = +
|
|
o + o E |
|
S o . o
|
|
+ o
. |
|
. . + o
|
|
o . o + |
|
.
. o|
+-----------------+
[kiosk@foundation51 Desktop]$ ls /root/.ssh
ls: cannot access /root/.ssh: Permission denied
[kiosk@foundation51 Desktop]$
[kiosk@foundation51 Desktop]$ su - root
Password:
Last login: Wed Nov
1 00:16:30 CST 2017on pts/0
[root@foundation51 ~]# 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)? y
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:
76:7d:6a:e7:9e:69:74:8e:14:64:df:42:1b:bd:cd:98root@foundation51.ilt.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|
. |
|
= .|
|
+ B+|
|
.
E.=|
|
S . . .o |
|
. .
oo .|
|
oo.+ |
|
. ooo.|
|
o=
|
+-----------------+
[root@foundation51 ~]# ls /root/.ssh/
authorized_keys
id_rsa
id_rsa.pub known_hosts
root@172.25.254.151
[root@foundation51 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pubroot@172.25.254.51
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter outany that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are promptednow it is to install the new keys
root@172.25.254.51's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.254.51'"
and check to make sure that only the key(s) you wanted were added.
[root@foundation51 ~]# scp /root/.ssh/id_rsaroot@172.25.254.154:/root/.ssh/
The authenticity of host '172.25.254.154 (172.25.254.154)' can't beestablished.
ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.25.254.154' (ECDSA) to the list of knownhosts.
root@172.25.254.154's password:
id_rsa 100% 1675
1.6KB/s
00:00