ubuntu重新启动网卡

When an application runs in the background, it’s called a service. These are essential to run the system or our software applications. Some of the common services you will find on most of the servers are Apache, MySQL, NGINX, etc. When the system boots up, these services are configured to automatically startup.

当应用程序在后台运行时,称为服务。 这些对于运行系统或我们的软件应用程序至关重要。 在大多数服务器上可以找到的一些常见服务是Apache,MySQL,NGINX等。当系统启动时,这些服务被配置为自动启动。

I am using Ubuntu to host my websites. I also use MySQL to store all my websites data. Sometimes, I perform regular updates and it’s essential to restart these services. In this tutorial, we will learn various ways to start, stop, and restart services in Ubuntu.

我正在使用Ubuntu托管我的网站。 我还使用MySQL存储所有网站数据。 有时,我会执行定期更新,因此必须重新启动这些服务。 在本教程中,我们将学习在Ubuntu中启动,停止和重新启动服务的各种方法。

在Ubuntu上启动,停止,重新启动服务的不同方法 (Different Ways to Start, Stop, Restart Services on Ubuntu)

  1. systemctl commandsystemctl命令
  2. service command服务命令
  3. init scripts初始化脚本

使用systemctl启动,停止和重新启动Ubuntu服务 (Using systemctl to start, stop, and restart Ubuntu services)

This is the preferred way to manage Ubuntu services. If you are not sure of the service name, you can run systemctl --all command to list all the services. But, there might be hundreds of services running, so it’s better to filter the list using the grep command.

这是管理Ubuntu服务的首选方法。 如果不确定服务名称,可以运行systemctl --all命令列出所有服务。 但是,可能有数百个服务正在运行,因此最好使用grep命令过滤列表。

Let’s try to find out the service names of MySQL and Apache HTTP server.

让我们尝试找出MySQL和Apache HTTP服务器的服务名称。


# systemctl --all | grep -i mysqlmysql.service                                                                          loaded    active   running   MySQL Community Server
# systemctl --all | grep -i apacheapache2.service                                                                        loaded    active   running   The Apache HTTP Server
#

So, the MySQL service name is “mysql.service” and Apache HTTP server service name is “apache2.service”.

因此,MySQL服务名称为“ mysql.service”,而Apache HTTP服务器服务名称为“ apache2.service”。

Let’s learn how to manage these services using the systemctl command.

让我们学习如何使用systemctl命令管理这些服务。

1.使用systemctl停止服务 (1. Stop service using systemctl)


# systemctl stop mysql.service
#

The command doesn’t give any output if the execution is successful.

如果执行成功,该命令将不提供任何输出。

2.使用systemctl检查服务状态 (2. Checking Service Status using systemctl)

We can check the service status using the below command.

我们可以使用以下命令检查服务状态。


# systemctl status mysql.service
● mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)Active: inactive (dead) since Sat 2020-05-02 17:39:22 UTC; 9s agoMain PID: 26948 (code=exited, status=0/SUCCESS)

3.使用systemctl启动服务 (3. Start service using systemctl)


# systemctl start mysql.service
#
# systemctl status mysql.service
● mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)Active: active (running) since Sat 2020-05-02 17:41:43 UTC; 3s agoProcess: 30254 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, sProcess: 30233 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)Main PID: 30256 (mysqld)Tasks: 27 (limit: 2318)CGroup: /system.slice/mysql.service└─30256 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Notice that when we had stopped the service, the “Active” value was inactive (dead). After starting the service, it’s changed to active (running).

请注意,当我们停止服务时,“活动”值处于非活动状态(无效)。 启动服务后,它已更改为活动(运行)。

4.使用systemctl重新启动服务 (4. Restart service using systemctl)


# systemctl restart apache2.service
# systemctl status apache2.service
● apache2.service - The Apache HTTP ServerLoaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)Drop-In: /lib/systemd/system/apache2.service.d└─apache2-systemd.confActive: active (running) since Sat 2020-05-02 17:55:09 UTC; 8s ago
Ubuntu Systemctl Command Start Stop Restart Status
Ubuntu Systemctl命令启动停止重新启动状态

Tip: It’s not required to use the complete service name with the systemctl command. For example, if we run “systemctl restart mysql” then it will automatically append “.service” to it and execute “systemctl restart mysql.service” command.

提示 :不需要在systemctl命令中使用完整的服务名称。 例如,如果我们运行“ systemctl restart mysql”,它将自动向其附加“ .service”并执行“ systemctl restart mysql.service”命令。

使用service命令管理Ubuntu服务 (Manage Ubuntu Services using service Command)

We can list all the services using service --status-all command. If needed, use the grep command to filter out the service you are looking for.

我们可以使用service --status-all命令列出所有服务。 如果需要,请使用grep命令过滤出您要查找的服务。


# service --status-all | grep mysql[ + ]  mysql
#

In the service command, we have to first specify the service name and then the command to execute.

在service命令中,我们必须首先指定服务名称,然后指定要执行的命令。

Stop a Service:

停止服务:


# service mysql stop

Start a Service:

启动服务:


# service mysql start

Restart a Service:

重新启动服务:


# service mysql restart

Checking Service Status:

检查服务状态:


# service mysql status
● mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)Active: active (running) since Sat 2020-05-02 18:19:34 UTC; 39s agoProcess: 31768 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, sProcess: 31746 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)Main PID: 31770 (mysqld)Tasks: 27 (limit: 2318)CGroup: /system.slice/mysql.service└─31770 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Ubuntu Service Command Start Stop Restart Status
Ubuntu服务命令启动停止重新启动状态

Ubuntu初始化脚本来管理服务 (Ubuntu init scripts to Manage Services)

The services init scripts are located in /etc/init.d/ directory. We can use these scripts to manage the services. However, it’s not recommended to use them anymore and it’s better to use the systemctl command.

服务初始化脚本位于/etc/init.d/目录中。 我们可以使用这些脚本来管理服务。 但是,不建议再使用它们,最好使用systemctl命令。

Stop a Service:

停止服务:


# /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
#

Start a Service:

启动服务:


# /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.
#

Restart a Service:

重新启动服务:


# /etc/init.d/mysql restart
[ ok ] Restarting mysql (via systemctl): mysql.service.
#

Checking Service Status:

检查服务状态:


# /etc/init.d/mysql status
● mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)Active: active (running) since Sat 2020-05-02 18:26:30 UTC; 17s ago
Ubuntu Init Scripts Start Stop Restart Status
Ubuntu Init脚本启动停止重新启动状态

启动/停止服务时的权限问题 (Permission issues when starting/stopping services)

If you are not logged in as root user, the above commands will ask you to provide root user password to execute. If the wrong password is entered, the authentication failed error will be thrown and command will not be executed.

如果您未以root用户身份登录,则上述命令将要求您提供root用户密码才能执行。 如果输入了错误的密码,将抛出认证失败错误,并且将不执行命令。

If you are on the sudoers list, you can run these commands as a sudo user. If you are not on the sudoers list, an error message will be displayed that you are not on the sudoers list and the incident will be reported.

如果您在sudoers列表中,则可以以sudo用户身份运行这些命令。 如果您不在sudoers列表中,则会显示一条错误消息,指出您不在sudoers列表中,并且将报告该事件。


test@localhost:~$ systemctl stop mysql
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'mysql.service'.
Authenticating as: root
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ===
Failed to stop mysql.service: Access denied
See system logs and 'systemctl status mysql.service' for details.
test@localhost:~$ sudo systemctl stop mysql
[sudo] password for test:
test is not in the sudoers file.  This incident will be reported.
test@localhost:~$
User Permission Issue Managing Services
用户权限问题管理服务

So if you want to manage any service, make sure you have necessary privileges to execute these commands.

因此,如果要管理任何服务,请确保您具有执行这些命令所需的特权。

结论 (Conclusion)

We learned various ways to manage services on Ubuntu. The systemctl command is the preferred approach to start/stop/restart services on Ubuntu. However, the init scripts print the command status, which can be useful in shell scripts to run them and immediately get the status of the command.

我们了解了在Ubuntu上管理服务的各种方法。 systemctl命令是在Ubuntu上启动/停止/重新启动服务的首选方法。 但是,init脚本会打印命令状态,这在shell脚本中运行它们并立即获取命令状态很有用。

翻译自: https://www.journaldev.com/39332/ubuntu-start-stop-restart-services

ubuntu重新启动网卡

ubuntu重新启动网卡_Ubuntu –启动,停止,重新启动服务相关推荐

  1. ubuntu设置网卡默认启动_ubuntu 网络配置

    检查网络配置命令:ifconfig 一.通过配置文件配置 新手没怎么用过Ubuntu,所以走了不少弯路,网上找了很多方法,大都没对我起到帮助作用,所以把自己的配置方法写一写. Ubuntu上连了两块网 ...

  2. 【OF框架】使用OF.WinService项目,添加定时服务,进行创建启动停止删除服务操作...

    准备 使用框架搭建完成项目,包含OF.WinService项目. 了解Window Service 和定时服务相关知识. 一.添加一个定时服务 第一步:了解项目结构 第二步:创建一个新的Job 第三步 ...

  3. 启动停止nginx服务

    ========================================================== 传统方法启动nginx服务 因为每次虚拟机重启后会删除路径:/var/run/ng ...

  4. ubuntu设置网卡默认启动_Ubuntu配置网卡IP地址

    Ubuntu Desktop14.04  ,在window7 下的vmware14虚拟机中 cat  /etc/network/interfaces 默认已经有lo: 系统给定的网络回环接口 eth0 ...

  5. ubuntu设置网卡默认启动_ubuntu配置网卡的办法

    常见问题 1. 为什么要配置网卡 因为如果没有配置好网卡,那么就无法正常上网或者与其他的电脑通讯 2.常见的错误有: ping任意地址时出现报错 network is unreachable 或者是在 ...

  6. MacBook/MacOS/Mac OS 关于启动/停止/重启服务(进程/程序)的命令

    文章目录 使用命令 launchctl 停止某个进程 使用命令 launchctl 启动某个进程 使用命令 launchctl 查看某个进程是否启动 使用命令 launchctl 停止某个进程 lia ...

  7. c#用控制台程序安装启动停止卸载服务

    第一步:新建控制台项目  第二步:添加服务 第三步:右键新建完成的服务项 点击 在start 和stop事件中分别写上   第四步 编写代码 双击打开 1 using System; 2 using ...

  8. bat启动/停止oracle服务

    自己的电脑比较慢,尤其装了oracle10g后,服务开启和关闭用bat文件操作省事点 开启服务 @echo off net start OracleServiceORCL net start Orac ...

  9. ubuntu设置网卡默认启动_Ubuntu18.04 配置网卡上网

    2019/10/29, Ubuntu Server 18.04 摘要:Ubuntu Server 18.04 采用netplan作为网络配置管理,修改IP使其连上网络 修改网卡配置 首先使用ip a查 ...

最新文章

  1. ios弧形进度条_ios 圆形进度条
  2. html桌面雪花,html5 canvas雪花形状在线生成器
  3. jmeter参数化之用户参数
  4. dax 筛选 包含某个字_筛选状态(ALL与REMOVEFILTERS)
  5. Nginx进程间通信机制
  6. CocoaPods集成ShareSDK
  7. 如何用代码爬抓电商数据(附淘宝API调用实例)
  8. 制作windows7系统的U盘启动盘
  9. Cool_gamesetup.exe山寨版熊猫烧香病毒
  10. ExoPlayer之SampleQueue
  11. 计算机环境变量怎么恢复默认,环境变量怎么还原
  12. lg相乘公式_lg的运算法则是什么
  13. 阿里某程序员感慨:30岁阿里p7,很迷茫,40岁转行能做什么
  14. 内蒙古巴丹吉林沙漠锁定2021中国唯一申遗名额
  15. 33省市出台区块链专项政策,有地方拿户口、百万奖金抢人
  16. vi 撤销上一步操作
  17. StringWriter/PrintWriter
  18. 成本(CPU Costing)的含义
  19. NVMe1.4 Admin Command学习(6) get feature set feature
  20. Java jdk 环境配置

热门文章

  1. 视频号怎么去变现赚钱?别人已经月入过万了丨国仁网络资讯
  2. 一个完整的python文件即是一个模块_用python玩转数据|基本语法
  3. maven日志打印,解决logger.info打印内容无法显示
  4. u盘插上后响一下但不显示,在其他电脑上可以用。
  5. 接口和抽象类的使用区别?
  6. 计算机桌面屏幕显示不到右边,电脑显示器没有满屏怎么回事
  7. 5w每秒的高并发优化:电商秒杀与抢购
  8. 方舟服务器修改错误,ARK Server Manager 出错
  9. jQuery实现九宫格抽奖游戏
  10. 前端面试题(2021年6月3日)