###############ip设置#######################
cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<END END开始 END结束 ##将cat的输出放到这个文件中
>DEVICE=eth0
>NAME=eth0
>ONBOOT=yes ##开启网络激活设备
>BOOTPROTO=dhcp ##动态获取
>END
systemctl restart network
vim /mnt/set-ip.sh
cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<END END开始 END结束 ######创建一个脚本
>DEVICE=eth0
>NAME=eth0
>ONBOOT=yes ##开启网络激活设备
>BOOTPROTO=dhcp ##动态获取
>END
systemctl restart network
bash /mnt/set-ip.sh
##############dhcp设置##################
服务端设置:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none ##静态获取
NETMASK=255.255.255.0
IPADDR=172.25.254.114
systemctl restart network ##重启网络
systemctl stop firewalld.service ##关闭防火墙
yum install dhcp -y ##安装dhcp
cp /usr/share/doc/dhcp-4.2.5/dhcp.conf.example /etc/dhcp/dhcpd.conf ##把dhcp的配置文件模版复制到文件
删除37行往后 和27 28行
改第7,8行
将域名改为 “example.com”
将DNS改为 172.25.254.250
32行subnet(子网)172.25.254.0 (表示地址池里面的网络位地址 172.25.254.0(0没有意义))netmask255.255.255.0{ ## 子网
range 172.25.254.180 172.25.254.199 ## 地址池 0没有意义 255代表广播地址
option routers 172.25.254.254 ## 网关
}
systemctl restart dhcp ## 重启dhcp
vim /var/lib/dhcpd/dhcpd.leases ## 查看客户机的连接状态
客户端设置:
然后拔网线 在另外一台虚拟机上面重启网络 然后获取一个你自己设置的地址池的范围
##########设置两个ip###########
IPADDR0 172.25.254.114
IPADDR1 172.25.254.10
PREFIX0 24
PREFIX1 24
ip addr show 查看ip
################DNS################
vim /etc/hosts ##
本地解析
172.25.254.114 www.baidu.com
ping www.baidu.com
本地解析 172.25.254.114
vim /etc/resolv.conf ##问DNS
namesever 172.25.254.250 ##设置DNS
host www.baidu.com ##问dns百度的ip
vim /etc/nsswitch.conf ##调整优先级 ##默认是本地解析优先级高
39 hosts: files dns 改为hosts: dns files ##那个在前面那个优先级高
less /usr/share/doc/initscripts-9.49.17/sysconfig.txt ##参数文档
自动获取ip但是不自动获取DNS
/etc/sysconfig/network-scripts/ifcfg-eth0 ##修改配置文件
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
PEERDNS=no ##不自动获取dns
静态获取ip和dns
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.114
NETMASK=255.255.255.0
DNS1=172.25.254.250
ip addr show br0 ##查看真机里面的公有网段和私有网段
把虚拟机的ip修改成私有网段
IPADDR 172.25.14.10
........
.....
....
...
###############网关设置###############
vim /etc/sysconfig/network ##网关配置文件
GATEWAY 172.25.14.254
保存退出
systemctl restart network
route -n ##查看网关
然后ping 172.25.254.14
nestat -antulpe
############
日志####################
####系统日志默认分类####
/var/log/messages ##系统服务及日志,包括服务的信息,报错等等
/var/log/secure ##系统认证信息日志
/var/log/maillog ##系统邮件服务信息
/var/log/cron ##系统定时任务信息
/var/log/boot.log ##系统启动信息
systemctl status rsyslog.server ##查看程序状态
vim /etc/rsyslog.conf ##rsyslog程序的配置文件
55 *.* /var/log/westos ##"."前面是程序 后面是日至级别 ##把所有类型的程序的日至级别全部放在/var/log/westos中
systemctl restart rsyslog.service ##重启程序
###日至采集格式##
$template WESTOS, “%timegenerated% %FROMHOST-IP% %syslogtag%%msg%\n”
WESTOS ##日至格式名
%timegenerated% ##时间戳
%FORMHOST-IP% ##显示主机ip
%syslogtag% ##日子记录目标
%msg% ##日至内容
\n ##换行
*.* /var/log/westos;WESTOS ##/var/log/westos日至下的格式按WESTOS格式
########日至同步############
先关闭防火墙
systemctl stop firewalld.server
接受端:
vim /etc/rsyslog.conf
第14,15行
14 $ModLoad imudp ##日志接收插件
15 $UDPServerRun 514 ##日志接收插件使用端口
然后退出保存
然后systemctl restart rsyslog.server ##重启服务
然后清空> /var/log/westos
然后监控watch -n 1 cat /var/log/westos
netstat -anuple | grep rsyslog
udp 0 00.0.0.0:514 0.0.0.0:*
0 629588 15006/rsyslogd
udp6 0 0:::514 :::*
0 629589 15006/rsyslogd
发送端:
关闭防火墙
vim /etc/rsyslog.conf
51 *.* @172.25.14.10 ##通过udp协议把日至发到14号机udp用一个@ tcp用两个@@
然后保存退出
然后重启服务systemctl restart rsyslog.server
然后清空 > /var/log/messages
然后监控watch -n 1 cat /var/log/messages
logger test message ##测试
###########修改主机名字###############
hostnamectl set-hostname client.example.com ###修改主机名称
hostnamectl set-hostname server.example.com
############日至时间同步#############
服务端:
关闭防火墙 systemctl stop firewalld.server
vim /etc/chrony.conf ##配置文件
22 allow 172.25.14.0/24 ##允许这个网段的ip访问
29 local stratum 10
然后退出保存
systemctl restart chronyd.server
客户端:vim /etc/chrony.conf
server 172.25.14.114 iburst ##同步服务器立即生效
然后退出保存
systemctl restart chronyd.server ##重启服务
chronyc sources -v ##查看同步
###clock -s ##把硬件时间同步给软件时间
clock -w ##把软件时间同步给硬件时间
########设置时间#############
timedatectl ##查看时间详情
timedatectl list-timezones ##查看时区列表
timedatectl set-timezone Asia/Shanghai ##将时区设置为上海时区
timedatectl set-local-rtc 1 ##将rtc时间设置为本地时间
timedatectl set-time “年-月-日时:分:秒” ##设置时间
##########journalctl###########
journalctl ##查看日至
journalctl -n 5 ##查看最新的五行日至
journalctl -p err ##查看错误日至
journalctl -f ##动态监控日至
journalctl --since="08:45" --until="08:46" ##查看从啥时间开始到啥时间结束的日至
journalctl -o verbose _PID=1151(进程PID) _SYSTEMD_UNIT=ssh.server(服务名称)
#########不忽略重启电脑前的日至##############(默认情况下systemd-journald会忽略重启前的日至,若要不忽略,做以下操作)
mkdir /var/log/journal ##建立一个目录
chgrp systemd-journal /var/log/journal ##修改目录所有组
chmod g+s /var/log/journal ##修改权限 加s权限
killall -1 systemd-journald ##重新加载
reboot ##重新启动
journalctl ##查看日至
##############yum##############################
yum list softwarename ##查看软件源中是否有次软件
yum list all ##列出所有软件名称
yum list installd ##列出已经安装的软件名称
yum list available ##列出可以用yum安装的软件名称
yum install softwarename ##安装
yum remove softwarename ##卸载
yum update ##更新软件
yum reinstall softwarename ##重新安装
yum info softwarename ##查看软件信息
yum repolist ##列出设定yum源信息
yum clean all ##清空yum缓存
yum search softwareinfo ##根据软件信息搜索软件名字
yum whatprovides filename ##在yum源中查找包含filename文件的软件包
yum history ##查看系统软件改变历史
yum groups list ##查看软件组信息
yum groups info softwaregroup ##查看软件组内包含的软件
yum groups install softwaregroup ##安装组件
yum groups remove softwaregroup ##卸载组件
###########软件仓库的搭建##########
下载iso镜像
lftp 172.25.254.254
get rhel-server-7.1-x86_64-dvd.iso
把镜像挂在/rhel7.2下
mkdir /rhel7.2
mount /home/kiosk/Desktop/rhel-server-7.2-x86_64-dvd.iso /rhel7.2
#####设置源指向############
cd /etc/yum.repos.d/
mv * /mnt/
cd /etc/yum.repos.d/
vim rhel7.2.repo
[RHEL7.2]
name=rhel7.2 source
baseurl=file:///rhel7.2
gpgcheck=0 ##是否安装第三方软件
yum install dhcp ##安装dhcp软件
(1/2): RHEL7.2/group_gz | 136kB 00:00:00
(2/2): RHEL7.2/primary_db