设置启动级别
[root@centos7 ~]# ll /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 37 2月 24 14:51 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target
[root@centos7 ~]# ll /lib/systemd/system/runlevel*.target
lrwxrwxrwx. 1 root root 15 2月 24 14:36 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 2月 24 14:36 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 2月 24 14:36 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 2月 24 14:36 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 2月 24 14:36 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 2月 24 14:36 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 2月 24 14:36 /lib/systemd/system/runlevel6.target -> reboot.target
2/3/4级别都是一样的,default.target是默认启动级别
[root@centos7 ~]# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
systemctl管理服务
查看所有服务
[root@centos7 ~]# systemctl list-unit-files
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
dev-mqueue.mount static
proc-sys-fs-binfmt_misc.mount static
sys-fs-fuse-connections.mount static
sys-kernel-config.mount static
sys-kernel-debug.mount static
tmp.mount disabled
brandbot.path disabled
systemd-ask-password-console.path static
systemd-ask-password-plymouth.path static
systemd-ask-password-wall.path static
session-1.scope static
session-2.scope static
session-3.scope static
auditd.service enabled
autovt@.service disabled
blk-availability.service disabled
brandbot.service static
console-getty.service disabled
console-shell.service disabled
container-getty@.service static
......
查看开机自启的服务
[root@centos7 ~]# systemctl list-unit-files | grep enabled
auditd.service enabled
crond.service enabled
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service enabled
getty@.service enabled
irqbalance.service enabled
kdump.service enabled
microcode.service enabled
NetworkManager-dispatcher.service enabled
NetworkManager.service enabled
postfix.service enabled
rsyslog.service enabled
sshd.service enabled
systemd-readahead-collect.service enabled
systemd-readahead-drop.service enabled
systemd-readahead-replay.service enabled
tuned.service enabled
default.target enabled
multi-user.target enabled
remote-fs.target enabled
设置sshd为开机自启
[root@centos7 ~]# systemctl enable sshd
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.
禁止sshd开机自启
[root@centos7 ~]# systemctl disable sshd
Removed symlink /etc/systemd/system/multi-user.target.wants/sshd.service.
启动vsftpd服务
[root@centos7 ~]# systemctl start vsftpd
[root@centos7 ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2016-02-24 15:37:31 CST; 11s ago
Process: 9847 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 9848 (vsftpd)
CGroup: /system.slice/vsftpd.service
└─9848 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
2月 24 15:37:31 centos7 systemd[1]: Starting Vsftpd ftp daemon...
2月 24 15:37:31 centos7 systemd[1]: Started Vsftpd ftp daemon.
停止vsftpd服务
[root@centos7 ~]# systemctl stop vsftpd
[root@centos7 ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
2月 24 15:37:31 centos7 systemd[1]: Starting Vsftpd ftp daemon...
2月 24 15:37:31 centos7 systemd[1]: Started Vsftpd ftp daemon.
2月 24 15:38:05 centos7 systemd[1]: Stopping Vsftpd ftp daemon...
2月 24 15:38:05 centos7 systemd[1]: Stopped Vsftpd ftp daemon.
查看vsftpd服务的状态
[root@centos7 ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
2月 24 15:37:31 centos7 systemd[1]: Starting Vsftpd ftp daemon...
2月 24 15:37:31 centos7 systemd[1]: Started Vsftpd ftp daemon.
2月 24 15:38:05 centos7 systemd[1]: Stopping Vsftpd ftp daemon...
2月 24 15:38:05 centos7 systemd[1]: Stopped Vsftpd ftp daemon.
查看ip地址
[root@xiaomo ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:8b:07:ee brd ff:ff:ff:ff:ff:ff
inet 192.168.1.93/23 brd 192.168.1.255 scope global dynamic enp0s3
valid_lft 2957sec preferred_lft 2957sec
inet6 fe80::a00:27ff:fe8b:7ee/64 scope link
valid_lft forever preferred_lft forever
查看网络接口统计信息
[root@xiaomo ~]# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 08:00:27:8b:07:ee brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
30226996 27412 0 0 0 3
TX: bytes packets errors dropped carrier collsns
1142346 14641 0 0 0 0
查看路由
[root@xiaomo ~]# ip route
default via 192.168.1.1 dev enp0s3 proto static metric 100
192.168.0.0/23 dev enp0s3 proto kernel scope link src 192.168.1.93 metric 100
[root@xiaomo ~]# ip route | column -t
default via 192.168.1.1 dev enp0s3 proto static metric 100
192.168.0.0/23 dev enp0s3 proto kernel scope link src 192.168.1.93 metric 100
添加静态路由(临时)
[root@xiaomo ~]# ip route add 10.10.0.0/24 via 192.168.1.1 dev enp0s3
[root@xiaomo ~]# ip route | column -t
default via 192.168.1.1 dev enp0s3 proto static metric 100
10.10.0.0/24 via 192.168.1.1 dev enp0s3
192.168.0.0/23 dev enp0s3 proto kernel scope link src 192.168.1.93 metric 100
删除静态路由
[root@xiaomo ~]# ip route del 10.10.0.0/24
[root@xiaomo ~]# ip route | column -t
default via 192.168.1.1 dev enp0s3 proto static metric 100
192.168.0.0/23 dev enp0s3 proto kernel scope link src 192.168.1.93 metric 100
添加静态路由(永久)
[root@xiaomo ~]# echo "10.10.0.0/24 via 192.168.1.1 dev enp0s3" >> /etc/sysconfig/network-scripts/route-enp0s3
[root@xiaomo ~]# cat /etc/sysconfig/network-scripts/route-enp0s3
10.10.0.0/24 via 192.168.1.1 dev enp0s3
删除静态路由
[root@xiaomo ~]# rm -f /etc/sysconfig/network-scripts/route-enp0s3
ip neighbor代替arp -n
[root@xiaomo ~]# ip nei
192.168.1.121 dev enp0s3 lladdr 28:d2:44:60:bd:b9 REACHABLE
192.168.1.1 dev enp0s3 lladdr 3c:8c:40:9b:cc:79 STALE
192.168.1.105 dev enp0s3 lladdr ac:bc:32:93:af:0b STALE
192.168.1.163 dev enp0s3 lladdr d4:97:0b:50:c5:1f STALE
[root@xiaomo ~]# ip neighbor
192.168.1.121 dev enp0s3 lladdr 28:d2:44:60:bd:b9 REACHABLE
192.168.1.1 dev enp0s3 lladdr 3c:8c:40:9b:cc:79 STALE
192.168.1.105 dev enp0s3 lladdr ac:bc:32:93:af:0b STALE
192.168.1.163 dev enp0s3 lladdr d4:97:0b:50:c5:1f STALE
ss代替netstat
[root@xiaomo ~]# ss -lnpt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:* users:(("sshd",pid=719,fd=3))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=719,fd=4))
网络配置文件:
/etc/hostname 主机名
/etc/resolv.conf DNS设置
/etc/sysconfig/network-scripts/ 连接配置信息 ifcfg 文件
/etc/NetworkManager/system-connections/ ×××、移动宽带、PPPoE连接
nmtui配置基本网络连接
nmtui 属于curses-based text user interface(文本用户界面),类似 CentOS6 的 setup 工具,但只能编辑连接/启用/禁用连接,更改主机名。
nmcli和其他网络设置
查看连接的设备
[root@xiaomo ~]# nmcli con show
名称 UUID 类型 设备
enp0s3 5c940ebd-d27f-475f-bb7c-f0944aaa4938 802-3-ethernet enp0s3
[root@xiaomo ~]# nmcli con show enp0s3
connection.id: enp0s3
connection.uuid: 5c940ebd-d27f-475f-bb7c-f0944aaa4938
connection.interface-name: enp0s3
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.timestamp: 1456298282
connection.read-only: no
connection.permissions:
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries:
connection.gateway-ping-timeout: 0
connection.metered: 未知
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: yes
802-3-ethernet.mac-address: --
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu: 自动
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options:
802-3-ethernet.wake-on-lan: 1 (default)
802-3-ethernet.wake-on-lan-password: --
ipv4.method: auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.gateway: --
ipv4.routes:
ipv4.route-metric: -1
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv6.method: auto
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.gateway: --
ipv6.routes:
ipv6.route-metric: -1
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (未知)
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
GENERAL.名称: enp0s3
GENERAL.UUID: 5c940ebd-d27f-475f-bb7c-f0944aaa4938
GENERAL.设备: enp0s3
GENERAL.状态: 已激活
GENERAL.默认: 是
GENERAL.DEFAULT6: 否
GENERAL.×××: 否
GENERAL.ZONE: --
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/0
GENERAL.SPEC 对象: /
GENERAL.MASTER-PATH: --
IP4.地址[1]: 192.168.1.93/23
IP4.网关: 192.168.1.1
IP4.DNS[1]: 202.106.46.151
IP4.DNS[2]: 202.106.196.115
DHCP4.选项[1]: requested_domain_search = 1
DHCP4.选项[2]: requested_nis_domain = 1
DHCP4.选项[3]: requested_time_offset = 1
DHCP4.选项[4]: requested_broadcast_address = 1
DHCP4.选项[5]: requested_rfc3442_classless_static_routes = 1
DHCP4.选项[6]: requested_classless_static_routes = 1
DHCP4.选项[7]: requested_domain_name = 1
DHCP4.选项[8]: expiry = 1456301645
DHCP4.选项[9]: requested_wpad = 1
DHCP4.选项[10]: next_server = 192.168.1.1
DHCP4.选项[11]: broadcast_address = 192.168.1.255
DHCP4.选项[12]: dhcp_message_type = 5
DHCP4.选项[13]: requested_subnet_mask = 1
DHCP4.选项[14]: dhcp_lease_time = 3600
DHCP4.选项[15]: routers = 192.168.1.1
DHCP4.选项[16]: ip_address = 192.168.1.93
DHCP4.选项[17]: requested_static_routes = 1
DHCP4.选项[18]: requested_interface_mtu = 1
DHCP4.选项[19]: requested_nis_servers = 1
DHCP4.选项[20]: requested_ntp_servers = 1
DHCP4.选项[21]: subnet_mask = 255.255.254.0
DHCP4.选项[22]: domain_name_servers = 202.106.46.151 202.106.196.115
DHCP4.选项[23]: requested_ms_classless_static_routes = 1
DHCP4.选项[24]: requested_routers = 1
DHCP4.选项[25]: requested_domain_name_servers = 1
DHCP4.选项[26]: network_number = 192.168.0.0
DHCP4.选项[27]: requested_host_name = 1
DHCP4.选项[28]: dhcp_server_identifier = 192.168.1.1
IP6.地址[1]: fe80::a00:27ff:fe8b:7ee/64
IP6.网关:
查看设备信息
[root@xiaomo ~]# nmcli dev show enp0s3
GENERAL.设备: enp0s3
GENERAL.类型: ethernet
GENERAL.硬盘: 08:00:27:8B:07:EE
GENERAL.MTU: 1500
GENERAL.状态: 100 (连接的)
GENERAL.CONNECTION: enp0s3
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2
WIRED-PROPERTIES.容器: 开
IP4.地址[1]: 192.168.1.93/23
IP4.网关: 192.168.1.1
IP4.DNS[1]: 202.106.46.151
IP4.DNS[2]: 202.106.196.115
IP6.地址[1]: fe80::a00:27ff:fe8b:7ee/64
IP6.网关:
友好的显示
[root@xiaomo ~]# nmcli -t -f IP4.ADDRESS dev show enp0s3
IP4.地址[1]:192.168.1.93/23
[root@xiaomo ~]# nmcli con load /etc/sysconfig/network-scripts/ifcfg-enp0s3
[root@xiaomo ~]# nmcli dev connect enp0s3
初次启动
装完机后,开机进系统的界面换了,乍一看以为是两个内核,原来有一个是rescue选择,而且按e后,会发现所有的grub.conf的信息全出来了,好不容易找到内核启动的地方,写了个 1(要进单用户模式),然后进了rescue模式。
字符界面
进系统后,是图形界面,想进字符界面,结果找到/etc/inittab,发现几乎是个空文件,文件中提示想改runlevel的话,可以把 /lib/systemd/system/runlevel*.target 软连到 /etc/systemd/system/default.target下(当然考过来,覆盖也行),试了一下还行,能改到字符界面runlevel3。
配置网络和主机名
然后,想配置网络,进/etc/sysconfig/network-script/一看,我靠,网卡改名了enp1s5,好有趣,配置完网络后改 主机名, 到/etc/sysconfig/network去改名字,发现这个文件也是空的,按原6版本的去修改,重启后没效果,man了一下hostname, 发现7中改名要到/etc/hostname去改名字。
本地yum源和挂载
接着,想配置一个本地yum源,配上后要挂光盘,手动挂上了,然后直接echo“mount ......”到rc.local中,毕竟是启动执行脚本,重启之后竟然没挂上,进去rc.local中看了一下,7中竟然要手动的把chmod +x rc.local, 是的,要手动加执行权限,难道我之前装的6以前的系统中这个都要手动加执行权限,我不记得啊!!!! 当然,加了权限后,开机后启动执行了rc.local的mount命令。
LVM和xfs
后来,想着装一个lvm玩玩,于是啊就分区,格式化(特意格式化为了xfs),pv,vg,lv一步一步,都没问题,然后想着放大,缩小,这时出问 题了,执行resize2fs时,怎么一直报superblock什么的出错,这是怎么回事,然后man resize2fs一下,发现这命令只支持ext的文件系统,我艹,那我装系统是怎么是lvm的,这个问题我还没解决,应该有解决方法。
dhcp和服务
接着,想着装一个dhcp玩玩,惊奇的发现所有dhcp的包装上之后,不能service dhcpd start,然后发现/etc/init.d/中竟然没一个dhcp类似的东西,毕竟6之前有dhcpd,dhcpd6,dhcrelay的,然后发现 /sbin/dhcpd有启动文件,难道,难道,以后的服务想service启,都要手动自己编?错了,是在/usr/lib/systemd /system/dhcpd.service,还要修改好多,然后加权限,执行service 服务 restart/stop。。。。。。可以,但是指向了systemctl restart/start/stop 服务.service
iptables
又发现iptables这次也不是作为一个服务在/etc/init.d/下面了,/sbin下有;
然后,然后,就没有然后了,或许,真的是或许,发现新东西,再在这个日志上更新吧,真的是或许。
对了,我还发现/etc/sysctl.conf也空了,想做个路由转发都要到/proc/sys/net下
转载于:https://blog.51cto.com/xiaofengmo/1744661