318笔记
服务管理学习
先以windows的服务为例,如何找到win的服务管理
win键 + r快捷键,打开运行窗口,输入如下指令
services.msc
ssh服务
ssh服务
root@boos ~]# netstat -tnlp |grep sshd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1081/sshd
[root@boos ~]#
可以自由启动,关闭,重启该服务,查看效果
centos7,启动的强大,服务管理命令
systemctl start/stop/restart/status 服务名称
systemctl stop sshd
systemctl status sshd
systemctl start sshd 启动
4sshd服务,运行后,即可去访问该服务
network服务
管理linux的网络功能,名字network
systemctl stop network 停止
systemctl status network 查看状态
systemctl start network 启动
systemctl restart 重启
systemctl服务管理命令
在centos7之前,是通过service和chkconfig两个命令来管理服务,
service 负责启动 停止服务 显示服务状态
service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、重新加载配置(reload)、查看状态(status)
# service mysqld 指令 #打印指定服务mysqld的命令行使用帮助。
# service mysqld start #启动mysqld
# service mysqld stop #停止mysqld
# service mysqld restart #重启mysqld (先停止,再运行 ,进程会断开,id会变化)
service mysqld reload # 当你修改了mysqld程序的配置文件,需要重新加载该配置文件,而不重启
chkconfig: 指定服务是否开机启动
sshd 远程连接服务
network 提供网络的服务
设置开机自启
chkconfig --list 查看系统程序列表
chkconfig httpd on 将httpd加入开机启动
chkconfig httpd off 关闭httpd开机启动
冲centos7开始 同意使用systemctl来管理服务,systemctl同时拥有service和chkconfig命令的功能
systemd是linux下的一款系统和服务管理器兼容sysV和LSB的启动脚本
并且你依然可以使用旧的命令,系统会自动的转变为systemctl去执行。
做了向下兼容的操作,新命令,兼容旧命令。
systemctl语法
systemctl(英文全拼:system control)用于控制 systemd 系统和管理服务。
语法
systemctl [OPTIONS...] COMMAND [UNIT...]
command 选项字如下:
unit(单元,服务,指的是如sshd,network,nginx,这样的服务名(unit))
这几个指令,就替代了旧版的service 服务名 start/stop/等等
start:启动指定的 unit。
stop:关闭指定的 unit。
restart:重启指定 unit。
reload:重载指定 unit。
status:查看指定 unit 当前运行状态。
is-enabled :查看是否设置了开机自启
替代了旧版的chkconfig 服务名 on/off
enable:系统开机时自动启动指定 unit,前提是配置文件中有相关配置。 设置开机自启
disable:开机时不自动运行指定 unit。 禁用开机自
参数:unit 是要配置的服务名称。
比如sshd服务,也可以更换为其他的内置服务名,即可管理.
- 启动sshd,systemctl start sshd
- 关闭,systemctl stop sshd
- 重启,systemctl restart sshd
- 重新加载 systemctl reload sshd
- 开机自启 ,systemctl enable sshd
- 禁止开机自启,systemctl disbale sshd
- 查看,sshd服务,是否开机自启,systemctl is-enabled sshd.service
列出系统中,所有的内置服务,名字,和状态
运行中 挂掉的 全部列出来
[root@boos ~]# systemctl list-units --type service --all
UNIT LOAD ACTIVE SUB DESCRIPTION
aegis.service loaded active running Aegis Service
aliyun.service loaded active running Aliyun Assist
AssistDaemon.service loaded active running AssistDaemon
atd.service loaded active running Job spooling tools
auditd.service loaded active running Security Auditing Service
chronyd.service loaded active running NTP client/server
cloud-config.service loaded active exited Apply the settings specified in cloud-config
cloud-final.service loaded active exited Execute cloud user/final scripts
cloud-init-local.service loaded active exited Initial cloud-init job (pre-networking)
cloud-init.service loaded active exited Initial cloud-init job (metadata service crawler)
cpupower.service loaded inactive dead Configure CPU power related settings
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
● display-manager.service not-found inactive dead display-manager.service
dracut-cmdline.service loaded inactive dead dracut cmdline hook
dracut-initqueue.service loaded inactive dead dracut initqueue hook
dracut-mount.service loaded inactive dead dracut mount hook
dracut-pre-mount.service loaded inactive dead dracut pre-mount hook
dracut-pre-pivot.service loaded inactive dead dracut pre-pivot and cleanup hook
dracut-pre-trigger.service loaded inactive dead dracut pre-trigger hook
dracut-pre-udev.service loaded inactive dead dracut pre-udev hook
dracut-shutdown.service loaded inactive dead Restore /run/initramfs
ecs_mq.service loaded inactive dead ECS enable networking multiqueue
emergency.service loaded inactive dead Emergency Shell
● exim.service not-found inactive dead exim.service
getty@tty1.service loaded active running Getty on tty1
initrd-cleanup.service loaded inactive dead Cleaning Up and Shutting Down Daemons
initrd-parse-etc.service loaded inactive dead Reload Configuration from the Real Root
initrd-switch-root.service loaded inactive dead Switch Root
initrd-udevadm-cleanup-db.service loaded inactive dead Cleanup udevd DB
● ip6tables.service not-found inactive dead ip6tables.service
● iptables.service not-found inactive dead iptables.service
irqbalance.service loaded inactive dead irqbalance daemon
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
microcode.service loaded inactive dead Load CPU microcode update
network.service loaded active running LSB: Bring up/down networking
lines 1-37
只列出启动的服务
[root@boos ~]# systemctl list-units --type service
UNIT LOAD ACTIVE SUB DESCRIPTION
aegis.service loaded active running Aegis Service
aliyun.service loaded active running Aliyun Assist
AssistDaemon.service loaded active running AssistDaemon
atd.service loaded active running Job spooling tools
auditd.service loaded active running Security Auditing Service
chronyd.service loaded active running NTP client/server
cloud-config.service loaded active exited Apply the settings specified in cloud-config
cloud-final.service loaded active exited Execute cloud user/final scripts
cloud-init-local.service loaded active exited Initial cloud-init job (pre-networking)
cloud-init.service loaded active exited Initial cloud-init job (metadata service crawler)
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
getty@tty1.service loaded active running Getty on tty1
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
network.service loaded active running LSB: Bring up/down networking
polkit.service loaded active running Authorization Manager
postfix.service loaded active running Postfix Mail Transport Agent
rhel-dmesg.service loaded active exited Dump dmesg to /var/log/dmesg
rhel-domainname.service loaded active exited Read and set NIS domainname from /etc/sysconfig/network
rhel-import-state.service loaded active exited Import network configuration from initramfs
rhel-readonly.service loaded active exited Configure read-only root support
rsyslog.service loaded active running System Logging Service
serial-getty@ttyS0.service loaded active running Serial Getty on ttyS0
sshd.service loaded active running OpenSSH server daemon
sysstat.service loaded active exited Resets System Activity Logs
systemd-fsck-root.service loaded active exited File System Check on Root Device
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
可以利用该命令,搜索出,系统内置服务名的完整名称,才可以去管理
[root@boos ~]# systemctl list-units --type service --all |grep ssh
sshd-keygen.service loaded inactive dead OpenSSH Server Key Generation
sshd.service loaded active running OpenSSH server daemon
[root@boos ~]#
修改网络模式,修改静态ip,动态ip获取方式
system control 系统控制,systemctl
查看当前的上网信息
确保你的机器,是连接的网络的,是插上了网线的。(模拟了物理服务器的软件是什么?看你的虚拟的机器(vmware))
给虚拟机配置静态ip
进入系统,查看软件的网络配置
[rootlocalhost ~~16:41:12]#cd /etc/sysconfig/network-scripts/
[rootlocalhost network-scripts/etc/sysconfig/network-scripts16:41:49]#ll
total 228
-rw-r--r--. 1 root root 424 Mar 18 12:26 ifcfg-ens33
-rw-r--r--. 1 root root 254 Jan 3 2018 ifcfg-lo
lrwxrwxrwx. 1 root root 24 Mar 2 15:39 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root 654 Jan 3 2018 ifdown-bnep
-rwxr-xr-x. 1 root root 6569 Jan 3 2018 ifdown-eth
-rwxr-xr-x. 1 root root 781 Jan 3 2018 ifdown-ippp
-rwxr-xr-x. 1 root root 4540 Jan 3 2018 ifdown-ipv6
lrwxrwxrwx. 1 root root 11 Mar 2 15:39 ifdown-isdn -> ifdown-ippp
-rwxr-xr-x. 1 root root 2102 Jan 3 2018 ifdown-post
-rwxr-xr-x. 1 root root 1068 Jan 3 2018 ifdown-ppp
-rwxr-xr-x. 1 root root 870 Jan 3 2018 ifdown-routes
-rwxr-xr-x. 1 root root 1456 Jan 3 2018 ifdown-sit
-rwxr-xr-x. 1 root root 1621 Mar 18 2017 ifdown-Team
-rwxr-xr-x. 1 root root 1556 Mar 18 2017 ifdown-TeamPort
-rwxr-xr-x. 1 root root 1462 Jan 3 2018 ifdown-tunnel
lrwxrwxrwx. 1 root root 22 Mar 2 15:39 ifup -> ../../../usr/sbin/ifup
-rwxr-xr-x. 1 root root 12415 Jan 3 2018 ifup-aliases
-rwxr-xr-x. 1 root root 910 Jan 3 2018 ifup-bnep
-rwxr-xr-x. 1 root root 13442 Jan 3 2018 ifup-eth
-rwxr-xr-x. 1 root root 12075 Jan 3 2018 ifup-ippp
-rwxr-xr-x. 1 root root 11893 Jan 3 2018 ifup-ipv6
lrwxrwxrwx. 1 root root 9 Mar 2 15:39 ifup-isdn -> ifup-ippp
-rwxr-xr-x. 1 root root 650 Jan 3 2018 ifup-plip
-rwxr-xr-x. 1 root root 1064 Jan 3 2018 ifup-plusb
-rwxr-xr-x. 1 root root 4981 Jan 3 2018 ifup-post
-rwxr-xr-x. 1 root root 4154 Jan 3 2018 ifup-ppp
-rwxr-xr-x. 1 root root 2001 Jan 3 2018 ifup-routes
-rwxr-xr-x. 1 root root 3303 Jan 3 2018 ifup-sit
-rwxr-xr-x. 1 root root 1755 Mar 18 2017 ifup-Team
-rwxr-xr-x. 1 root root 1876 Mar 18 2017 ifup-TeamPort
-rwxr-xr-x. 1 root root 2711 Jan 3 2018 ifup-tunnel
-rwxr-xr-x. 1 root root 1836 Jan 3 2018 ifup-wireless
-rwxr-xr-x. 1 root root 5419 Jan 3 2018 init.ipv6-global
-rw-r--r--. 1 root root 19948 Jan 3 2018 network-functions
-rw-r--r--. 1 root root 31027 Jan 3 2018 network-functions-ipv6
[rootlocalhost network-scripts/etc/sysconfig/network-scripts16:41:54]#
编辑网卡的配置文件
[rootlocalhost network-scripts/etc/sysconfig/network-scripts16:43:10]#vim ifcfg-ens33
如下
修改配置文件,一定要重启网络服务
重新使用新的ip地址,试试连接
补充的history命令
history -c # 清空历史记录命令,清空当前以登录的这个会话,所敲打的命令
所有的历史记录,想要持久化存储
被写入到文件里 ~/.bash_history
捋一捋
1.你登录了一个机器,你的操作,都会被history记录,临时存储在哎内存中
2.退出登录后,记录被写入到文件,永久存储,下一次登录 ,系统会去加载家目录中的资料,也包括 ~/.bash_hisotry
彻底清空的动作
> .bash_history
1.你登录了某机器,做了某操作,不想被记录, 直接hisotry -c ,清空你当前登录后,执行的所有操作
2. 把当前的历史记录,写入到文件中,强制写入(退出登录)
history -w # 把当前的历史记录,内存中的数据,写入到文件里
history -c
history -w
下次再登录,啥也看不到了