apache编译安装,服务控制方式

发布于:2023-02-03 ⋅ 阅读:(449) ⋅ 点赞:(0)

apache编译安装,服务控制方式


1.下载httpd源码包并解压

[root@192 yum.repos.d]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
[root@192 yum.repos.d]# tar xf httpd-2.4.54.tar.gz -C /usr/local/src/

2.安装开发环境和apr依赖包,和解压依赖包

[root@192 yum.repos.d]# dnf -y groups mark install "Development Tools"
[root@192 yum.repos.d]#  dnf -y install openssl-devel pcre-devel expat-devel libtool
[root@192 yum.repos.d]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
[root@192 yum.repos.d]# wget https://mirrors.aliyun.com/apache/apr/apr-1.6.5.tar.gz
[root@192 src]# tar xf apr-1.6.5.tar.gz
[root@192 src]# tar xf apr-util-1.6.1.tar.gz

3.编译安装apr依赖包

进入配置文件修改配置文件,将 R M " RM " RM"cfgfile"注释掉或者删掉

[root@192 apr-1.6.5]# vim configure		//修改配置文件
[root@192 apr-1.6.5]# ./configure --prefix=/usr/local/apr	//指定安装在某个目录
[root@192 apr-1.6.5]# dnf -y install gcc gcc-c++ make	//安装编译锅具
[root@192 apr-1.6.5]# make && make install		//进行编译安装

[root@192 src]# cd apr-util-1.6.1/
[root@192 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

4.编译安装httpd服务

[root@192 httpd-2.4.54]# cd httpd-2.4.54/
[root@192 httpd-2.4.54]#  ./configure --prefix=/usr/local/apache \
>  --enable-so \
>  --enable-ssl \
>  --enable-cgi \
>  --enable-rewrite \
>  --with-zlib \
>  --with-pcre \
>  --with-apr=/usr/local/apr \
>  --with-apr-util=/usr/local/apr-util/ \
>  --enable-modules=most \
>  --enable-mpms-shared=all \
> --with-mpm=prefork
[root@192 httpd-2.4.54]# make && make install

5.配置全局变量,并关闭防火墙和selinux,然后开启httpd服务

[root@192 ~]# echo 'export PATH=$PATH:/usr/local/apache/bin/' >> /etc/profile.d/apache.sh
[root@192 ~]# source /etc/profile.d/apache.sh 
[root@192 ~]# apachectl
[root@192 ~]# ss -anltup 
Netid   State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   Process                                                                            
tcp     LISTEN   0        128               0.0.0.0:22              0.0.0.0:*       users:(("sshd",pid=1026,fd=5))                                                    
tcp     LISTEN   0        128                     *:80                    *:*       users:(("httpd",pid=42002,fd=4),("httpd",pid=42001,fd=4),("httpd",pid=42000,fd=4),("httpd",pid=41999,fd=4),("httpd",pid=41998,fd=4),("httpd",pid=41997,fd=4))
tcp     LISTEN   0        128                  [::]:22                 [::]:*       users:(("sshd",pid=1026,fd=7))
[root@192 ~]# systemctl stop firewalld.service 
[root@192 ~]# systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@192 ~]# setenforce 0
[root@192 ~]# vim /etc/selinux/config 
[root@192 ~]# getenforce 
Permissive

6.访问网站

7.服务控制systemctl

//status name.service     //查看服务状态
[root@192 ~]# systemctl status postfix.service 
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor prese>
   Active: inactive (dead)
   
// start name.service      //启动服务
[root@hwf ~]# systemctl start postfix
[root@hwf ~]# systemctl status postfix.service 
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor prese>
   Active: active (running) since Wed 2022-07-13 21:34:39 CST; 30s ago
  Process: 1776 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 1775 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, stat>
  Process: 1770 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0>
 Main PID: 1845 (master)
    Tasks: 3 (limit: 23502)
    
// stop name.service       //停止服务
[root@hwf ~]# systemctl stop postfix.service 
[root@hwf ~]# systemctl status postfix.service 
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor prese>
   Active: inactive (dead)

Jul 13 21:29:45 192.168.159.100 postfix[1729]: fatal: unable to use my own hostname
Jul 13 21:29:46 192.168.159.100 systemd[1]: postfix.service: Control process exite>
Jul 13 21:29:46 192.168.159.100 systemd[1]: postfix.service: Failed with result 'e>
Jul 13 21:29:46 192.168.159.100 systemd[1]: Failed to start Postfix Mail Transport>
Jul 13 21:34:38 hwf systemd[1]: Starting Postfix Mail Transport Agent...
Jul 13 21:34:39 hwf postfix/master[1845]: daemon started -- version 3.5.8, configu>
Jul 13 21:34:39 hwf systemd[1]: Started Postfix Mail Transport Agent.
Jul 13 21:36:22 hwf systemd[1]: Stopping Postfix Mail Transport Agent...
Jul 13 21:36:22 hwf systemd[1]: postfix.service: Succeeded.
Jul 13 21:36:22 hwf systemd[1]: Stopped Postfix Mail Transport Agent.

// restart name.service    //重启服务
[root@hwf ~]# systemctl restart postfix.service 
[root@hwf ~]# systemctl status postfix.service 
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor prese>
   Active: active (running) since Wed 2022-07-13 21:37:28 CST; 4s ago
  Process: 1908 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 1906 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, stat>
  Process: 1903 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0>
 Main PID: 1976 (master)
    Tasks: 3 (limit: 23502)
   Memory: 4.3M
   CGroup: /system.slice/postfix.service
           ├─1976 /usr/libexec/postfix/master -w
           ├─1977 pickup -l -t unix -u
           └─1978 qmgr -l -t unix -u

Jul 13 21:37:27 hwf systemd[1]: Starting Postfix Mail Transport Agent...
Jul 13 21:37:28 hwf postfix/master[1976]: daemon started -- version 3.5.8, configu>
Jul 13 21:37:28 hwf systemd[1]: Started Postfix Mail Transport Agent.

//mask name.service       //禁止设定为开机自启
[root@hwf ~]# systemctl mask postfix.service 
Created symlink /etc/systemd/system/postfix.service → /dev/null.
[root@hwf ~]# systemctl status postfix.service 
● postfix.service
   Loaded: masked (Reason: Unit postfix.service is masked.)
   Active: active (running) since Wed 2022-07-13 21:37:28 CST; 1min 27s ago
 Main PID: 1976 (master)
    Tasks: 3 (limit: 23502)
   Memory: 4.3M
   CGroup: /system.slice/postfix.service
           ├─1976 /usr/libexec/postfix/master -w
           ├─1977 pickup -l -t unix -u
           └─1978 qmgr -l -t unix -u

// unmask name.service     //取消禁止设定为开机自启
[root@hwf ~]# systemctl unmask postfix.service 
Removed /etc/systemd/system/postfix.service.
[root@hwf ~]# systemctl status postfix.service 
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset:>
   Active: active (running) since Wed 2022-07-13 21:37:28 CST; 2min 28s ago
 Main PID: 1976 (master)
    Tasks: 3 (limit: 23502)
   Memory: 4.3M
   CGroup: /system.slice/postfix.service
           ├─1976 /usr/libexec/postfix/master -w
           ├─1977 pickup -l -t unix -u
           └─1978 qmgr -l -t unix -u
// enable name.service     //设定某服务开机自动启动
[root@hwf ~]# systemctl enable postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@hwf ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset:>
   Active: active (running) since Wed 2022-07-13 21:37:28 CST; 5min ago
 Main PID: 1976 (master)
    Tasks: 3 (limit: 23502)
   Memory: 4.3M
   CGroup: /system.slice/postfix.service
           ├─1976 /usr/libexec/postfix/master -w
           ├─1977 pickup -l -t unix -u
           └─1978 qmgr -l -t unix -u

//disable name.service    //禁止服务开机自动启动
[root@hwf ~]# systemctl disable postfix
Removed /etc/systemd/system/multi-user.target.wants/postfix.service.
[root@hwf ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor preset>
   Active: active (running) since Wed 2022-07-13 21:37:28 CST; 5min ago
 Main PID: 1976 (master)
    Tasks: 3 (limit: 23502)
   Memory: 4.3M
   CGroup: /system.slice/postfix.service
           ├─1976 /usr/libexec/postfix/master -w
           ├─1977 pickup -l -t unix -u
           └─1978 qmgr -l -t unix -u
           
//is-enabled name.service      //查看服务是否开机自动启动
[root@hwf ~]# systemctl is-enabled postfix.service 
disabled

// is-active name.service      //查看某服务当前激活与否的状态
[root@hwf ~]# systemctl is-active postfix.service 
active

 list-dependencies name.service      //查看服务的依赖关系
[root@hwf ~]# systemctl list-dependencies postfix.service 
postfix.service
● ├─-.mount
● ├─system.slice
● └─sysinit.target
●   ├─dev-hugepages.mount
●   ├─dev-mqueue.mount
●   ├─dracut-shutdown.service
●   ├─import-state.service
●   ├─kmod-static-nodes.service
●   ├─ldconfig.service
●   ├─loadmodules.service
●   ├─lvm2-lvmpolld.socket
●   ├─lvm2-monitor.service
●   ├─nis-domainname.service
●   ├─plymouth-read-write.service
●   ├─plymouth-start.service
●   ├─proc-sys-fs-binfmt_misc.automount
●   ├─selinux-autorelabel-mark.service
●   ├─sys-fs-fuse-connections.mount
●   ├─sys-kernel-config.mount
●   ├─sys-kernel-debug.mount
●   ├─systemd-ask-password-console.path
●   ├─systemd-binfmt.service
●   ├─systemd-firstboot.service

//get-default     //查看默认运行级别
[root@hwf ~]# systemctl get-default 
multi-user.target

8.设置apache开机自启

进入 /usr/lib/systemd/system找到sshd服务,复制出另一份来修改配置文件
[root@hwf system]# cp sshd.service httpd.servier
[root@hwf system]# vim httpd.servier
[root@hwf system]# cat httpd.servier
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecReload=/usr/local/apache/bin/apachectl restart
ExecStop=/usr/local/apache/bin/apachectl stop

[Install]
WantedBy=multi-user.target

[root@hwf system]# 

//重新加载一下配置文件
[root@hwf system]# systemctl daemon-reload 		//重新加载命令
[root@hwf system]# systemctl status httpd.service 		//查看状态
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: >
   Active: inactive (dead)
     Docs: man:httpd.service(8)
[root@hwf system]# systemctl start httpd.service		//开启服务 
[root@hwf system]# systemctl enable httpd.service 		//开启开机自启服务
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@hwf system]# ss -anltup
Netid   State    Recv-Q   Send-Q       Local Address:Port       Peer Address:Port   Process                                                                             
tcp     LISTEN   0        128                0.0.0.0:22              0.0.0.0:*       users:(("sshd",pid=953,fd=4))                                                      
tcp     LISTEN   0        100              127.0.0.1:25              0.0.0.0:*       users:(("master",pid=1976,fd=16))                                                  
tcp     LISTEN   0        128                      *:80                    *:*       users:(("httpd",pid=2295,fd=4),("httpd",pid=2294,fd=4),("httpd",pid=2293,fd=4),("httpd",pid=2291,fd=4))
tcp     LISTEN   0        128                   [::]:22                 [::]:*       users:(("sshd",pid=953,fd=6))                                                      
tcp     LISTEN   0        100                  [::1]:25                 [::]:*       users:(("master",pid=1976,fd=17))  

9.网络常用命令

//修改一下网卡的配置文件
[root@hwf network-scripts]# mv ifcfg-ens33 ifcfg-eth0 
[root@hwf network-scripts]# vim ifcfg-eth0
[root@hwf network-scripts]# cat ifcfg-eth0 
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
UUID=c0401f32-6948-472e-9bd5-905bc5fca573
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.159.100
PREFIX=24
GATEWAY=192.168.159.2
DNS1=192.168.159.2
[root@hwf network-scripts]#
//编辑/etc/default/grub配置文件,在以GRUB_CMDLINE_LINUX开头的行内rhgb的前面加上net.ifnames=0 biosdevname=0 
[root@hwf network-scripts]# vim /etc/default/grub 
[root@hwf network-scripts]# cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true

//为grub2生成其配置文件
[root@hwf ~]# grub2-mkconfig -o /etc/grub2.cfg
Generating grub configuration file ...
done
//重启系统
[root@hwf ~]# reboot
[root@hwf ~]# 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 fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:1e:f5:09 brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.143/24 brd 192.168.159.255 scope global dynamic noprefixroute eth0
       valid_lft 1665sec preferred_lft 1665sec
    inet6 fe80::20c:29ff:fe1e:f509/64 scope link 
       valid_lft forever preferred_lft forever

10.ifconfig命令

//先安装ifconfig
[root@hwf ~]# yum provides ifconfig
[root@hwf ~]# dnf -y install net-tools
[root@hwf ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.159.143  netmask 255.255.255.0  broadcast 192.168.159.255
        inet6 fe80::20c:29ff:fe1e:f509  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:1e:f5:09  txqueuelen 1000  (Ethernet)
        RX packets 1044  bytes 407080 (397.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 598  bytes 63617 (62.1 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 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
//进查看eth0的网卡状态
[root@hwf ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.159.143  netmask 255.255.255.0  broadcast 192.168.159.255
        inet6 fe80::20c:29ff:fe1e:f509  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:1e:f5:09  txqueuelen 1000  (Ethernet)
        RX packets 1058  bytes 408108 (398.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 610  bytes 65611 (64.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

//查看所有网卡状态信息, 包括禁用和启用
[root@hwf ~]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.159.143  netmask 255.255.255.0  broadcast 192.168.159.255
        inet6 fe80::20c:29ff:fe1e:f509  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:1e:f5:09  txqueuelen 1000  (Ethernet)
        RX packets 1082  bytes 409908 (400.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 628  bytes 67709 (66.1 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 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

11.ip

//语法:ip [ OPTIONS ] OBJECT { COMMAND | help }
OBJECT:
link:网络接口属性
addr:协议地址
route:路由

//查看网络接口所有地址  
[root@hwf ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:1e:f5:09 brd ff:ff:ff:ff:ff:ff

//显示报文统计信息
[root@hwf ~]# ip -s link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped missed  mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0       
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:1e:f5:09 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped missed  mcast   
    415670     1161     0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    72799      671      0       0       0       0    

//启用或禁用网络接口ip link set DEV {up|down}
[root@hwf ~]# ip link set lo down
[root@hwf ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.159.143  netmask 255.255.255.0  broadcast 192.168.159.255
        inet6 fe80::20c:29ff:fe1e:f509  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:1e:f5:09  txqueuelen 1000  (Ethernet)
        RX packets 1220  bytes 420128 (410.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 706  bytes 76891 (75.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        
//ip addr add ADDRESS dev DEV:添加IP地址
[root@hwf ~]# ip addr show eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:1e:f5:09 brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.143/24 brd 192.168.159.255 scope global dynamic noprefixroute eth0
       valid_lft 1040sec preferred_lft 1040sec
    inet6 fe80::20c:29ff:fe1e:f509/64 scope link 
       valid_lft forever preferred_lft forever

[root@hwf ~]# ip addr add 192.168.159.200/24 dev eth0
[root@hwf ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:1e:f5:09 brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.100/24 brd 192.168.159.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet 192.168.159.200/24 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe1e:f509/64 scope link 
       valid_lft forever preferred_lft forever

//删除ip地址
[root@hwf ~]# ip addr del 192.168.159.200/24 dev eth0
[root@hwf ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:1e:f5:09 brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.100/24 brd 192.168.159.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe1e:f509/64 scope link 
       valid_lft forever preferred_lft forever

//ip addr show DEV:查看网络接口的地址

12.route

Linux主机之间是使用IP进行通信, 假设A主机和B主机同在一个网段内且网卡都处于激活状态, 则A具备和B直接通信的能力, 但如果A主机和B主机处于两个不同的网段, 则A必须通过路由器才能和B通信, 路由器属于IT设备的基础设施, 每一个网段都应该至少有一个网关

//查看当前路由表
[root@hwf ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.159.2   0.0.0.0         UG    100    0        0 eth0
192.168.159.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0

//以数字方式显示各主机或端口等相关信息
[root@hwf ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.159.2   0.0.0.0         UG    100    0        0 eth0
192.168.159.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0

//增加路由
//语法:route add [-net|-host] target [netmask Nm] [gw Gw]  [[dev] If]

//增加网段路由
[root@localhost ~]# route add -net 172.16.12.0/24 gw 172.16.12.2 dev eth1
[root@localhost ~]# route add -net 0.0.0.0/0 gw 172.16.12.2 dev eth1

//增加主机路由
[root@localhost ~]# route add -host 172.16.12.128 gw 172.16.12.2


//删除路由
[root@localhost ~]# route del -net 172.16.12.0/24
[root@localhost ~]# route del -net 0.0.0.0/0 gw 172.16.12.2

13.hostname和hostnamectl

生产环境中必须配置主机名,同时主机名也需要遵循一定的规范, 比如:

公有云: 地区-项目-业务-服务-节点-地址
wh-shop-register-nginx-node1-192.168.56.13
wh-med-pay-mysql-master01-192.168.56.11
wh-med-pay-mysql-slave01-192.168.56.12

//hostname查看主机名
[root@hwf ~]# hostname
hwf

//hostname临时修改主机名
[root@hwf ~]# hostname hhh
[root@hwf ~]# cat /etc/hostname		//需要重新登录才能显示
hwf

//rhel7系统建议使用hostnamectl修改和查看主机名
//设定永久名称
[root@hwf ~]# hostnamectl set-hostname hhh
[root@hwf ~]# cat /etc/hostname
hhh

//查看主机信息
[root@hwf ~]# hostnamectl 
   Static hostname: hhh
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 90d8f3e50b144a24b3c0821244efb674
           Boot ID: 301b28e156874d7eb636e4dd05c94eac
    Virtualization: vmware
  Operating System: CentOS Linux 8
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-348.el8.x86_64
      Architecture: x86-64

改和查看主机名
//设定永久名称
[root@hwf ~]# hostnamectl set-hostname hhh
[root@hwf ~]# cat /etc/hostname
hhh

//查看主机信息
[root@hwf ~]# hostnamectl 
   Static hostname: hhh
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 90d8f3e50b144a24b3c0821244efb674
           Boot ID: 301b28e156874d7eb636e4dd05c94eac
    Virtualization: vmware
  Operating System: CentOS Linux 8
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-348.el8.x86_64
      Architecture: x86-64

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到