<!DOCTYPE html>
    <html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
    <head>
<title>Cách sử dụng Systemctl để liệt kê tất cả các service Linux</title>
<meta name="description" content="Cách sử dụng Systemctl để liệt kê tất cả các service Linux - Savefile - Tin Tức -...">
<meta name="author" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :.">
<meta name="copyright" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :. [admin@nguoicodonvn2008.info]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.5">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Cách sử dụng Systemctl để liệt kê tất cả các service Linux">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;www.nguoicodonvn2008.info&#x002F;vi&#x002F;news&#x002F;savefile&#x002F;kien-thuc-may-tinh&#x002F;cach-su-dung-systemctl-de-liet-ke-tat-ca-cac-service-linux-10177.html">
<meta property="og:site_name" content=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.">
<meta property="og:url" content="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/cach-su-dung-systemctl-de-liet-ke-tat-ca-cac-service-linux-10177.html">
<link rel="shortcut icon" href="https://www.nguoicodonvn2008.info/favicon.ico">
<link rel="canonical" href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/cach-su-dung-systemctl-de-liet-ke-tat-ca-cac-service-linux-10177.html">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/karaoke-dual/" title="Tin Tức - Karaoke Dual" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/nhac-tre/" title="Tin Tức - Nhạc trẻ" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/tru-tinh/" title="Tin Tức - Trữ tình" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/nuoc-ngoai/" title="Tin Tức - Nước ngoài" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/remix/" title="Tin Tức - Remix" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/tam-su-tinh-yeu/" title="Tin Tức - Tâm sự tình yêu" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/tho-suu-tam/" title="Tin Tức - Thơ sưu tầm" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/cuoc-song/" title="Tin Tức - Cuộc sống" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/phan-mem/" title="Tin Tức - Phần mềm" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/kien-thuc-may-tinh/" title="Tin Tức - Kiến thức máy tính" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/hoc-tap/" title="Tin Tức - Học tập" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/tai-lieu/" title="Tin Tức - Tài liệu" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/de-thi/" title="Tin Tức - Đề thi" type="application/rss+xml">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/style.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/news.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/custom.css" type="text/css">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/themes/default/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/themes/default/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/themes/default/js/bootstrap.min.js" type="text/javascript">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/themes/default/css/style.css">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://www.nguoicodonvn2008.info/themes/default/css/news.css">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/themes/default/css/custom.css">
<style type="text/css">
	body{background: #fff;}
</style>
    </head>
    <body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">.&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.</h2>
		<p class="pull-right"><a title=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;." href="https://www.nguoicodonvn2008.info/">https://www.nguoicodonvn2008.info</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Cách sử dụng Systemctl để liệt kê tất cả các service Linux</h1>
		<ul class="list-inline">
			<li>Thứ hai - 14/04/2025 23:37</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
		</div>
				<div class="imghome">
			<img alt="Cách sử dụng Systemctl để liệt kê tất cả các service Linux" src="https://st.quantrimang.com/photos/image/2015/08/05/install-ubuntu-01-size-80x80-znd.jpg" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<p style="text-align: justify;">Khi quản lý hệ thống Linux, việc hiểu cách kiểm soát và giám sát các service hệ thống là rất quan trọng. Systemd, trình quản lý hệ thống và service cho hầu hết các bản phân phối Linux, cung cấp một bộ công cụ mạnh mẽ cho mục đích này. Bài viết hôm nay sẽ đi sâu vào cách bạn có thể liệt kê tất cả các service đang chạy trong systemd, tập trung vào terminal Ubuntu làm ví dụ.</p>

<h2 style="text-align: justify;">Systemd là gì?</h2>

<p style="text-align: justify;">Systemd là một hệ thống init được sử dụng để khởi động không gian người dùng và quản lý các tiến trình hệ thống sau khi khởi động. Hiện nay, hầu hết các bản phân phối Linux chính đều sử dụng hệ thống này. Hệ thống này thay thế hệ thống SysVinit cũ và đã trở thành tiêu chuẩn cho việc quản lý service trong Linux.</p>

<h2 style="text-align: justify;">Kiểm tra trạng thái của các service</h2>

<p style="text-align: justify;">Để bắt đầu, lệnh chính để tương tác với systemd là systemctl. Hãy cùng xem cách chúng ta có thể sử dụng systemctl để liệt kê tất cả các service đang chạy.</p>

<p style="text-align: justify;">Liệt kê các service đang chạy bằng systemctl</p>

<p style="text-align: justify;">Bạn có thể liệt kê tất cả các service systemd đang chạy bằng lệnh sau:</p>

<pre id="pre0">
<code>systemctl list-units --type=service --state=running</code></pre>

<p style="text-align: justify;">Khi bạn chạy lệnh này trong terminal Ubuntu, nó sẽ hiển thị danh sách tất cả các service đang hoạt động. Kết quả đầu ra có thể trông như thế này:</p>

<pre id="pre1">
<code>UNIT                               LOAD   ACTIVE SUB     DESCRIPTION
● atd.service                        loaded active running Deferred execution scheduler
  avahi-daemon.service               loaded active running Avahi mDNS/DNS-SD Stack
  cron.service                       loaded active running Regular background program processing daemon
  dbus.service                       loaded active running D-Bus System Message Bus
  networking.service                 loaded active running Raise network interfaces
  ssh.service                        loaded active running OpenBSD Secure Shell server</code></pre>

<p style="text-align: justify;">Kết quả đầu ra này hiển thị một số cột:</p>

<ul>
	<li style="text-align: justify;"><strong>UNIT:</strong>&nbsp;Tên của service.</li>
	<li style="text-align: justify;"><strong>LOAD:</strong>&nbsp;Chỉ ra file cấu hình của service đã được load thành công hay chưa.</li>
	<li style="text-align: justify;"><strong>ACTIVE:</strong>&nbsp;Trạng thái kích hoạt cấp cao.</li>
	<li style="text-align: justify;"><strong>SUB:</strong>&nbsp;Trạng thái kích hoạt cấp thấp.</li>
	<li style="text-align: justify;"><strong>DESCRIPTION:</strong>&nbsp;Mô tả ngắn gọn về service.</li>
</ul>

<p style="text-align: justify;">Kết quả đầu ra mặc định khá hữu ích, nhưng đôi khi hơi quá. Nếu thích chế độ xem đơn giản hơn, bạn có thể tùy chỉnh đầu ra bằng tùy chọn&nbsp;<strong>--no-pager</strong>&nbsp;để ngăn đầu ra được gửi qua công cụ phân trang và grep để lọc qua các service. Ví dụ:</p>

<pre id="pre2">
<code>systemctl list-units --type=service --state=running --no-pager | grep ssh</code></pre>

<p style="text-align: justify;">Lệnh này sẽ chỉ hiển thị các service liên quan đến ssh, rất tiện lợi nếu bạn đặc biệt quan tâm đến trạng thái của những service liên quan đến&nbsp;<a data-type="internal" href="https://quantrimang.com/cong-nghe/tim-hieu-ve-ssh-154483" title="SSH là gì?">SSH</a>.</p>

<h2 style="text-align: justify;">Cách xử lý các service không chạy</h2>

<p style="text-align: justify;">Điều quan trọng nữa là phải biết cách tìm các service không chạy. Ví dụ, để xem các service đã lỗi, bạn có thể sử dụng:</p>

<pre id="pre3">
<code>systemctl --failed</code></pre>

<p style="text-align: justify;">Lệnh này sẽ liệt kê các service không load hoặc không khởi động được. Đây là cách đầu ra có thể xuất hiện:</p>

<pre id="pre4">
<code> UNIT                         LOAD   ACTIVE SUB    DESCRIPTION
● nginx.service                loaded failed failed A high performance web server
● mysql.service                loaded failed failed MySQL Community Server</code></pre>

<p style="text-align: justify;">Điều này đặc biệt hữu ích để khắc phục sự cố vì nó làm nổi bật các service cần chú ý.</p>

<h2 style="text-align: justify;">Mẹo và thủ thuật bổ sung</h2>

<h3 style="text-align: justify;">Lọc danh sách</h3>

<p style="text-align: justify;">Systemd cung cấp một số cách để lọc và xem các loại service cụ thể. Ví dụ, bạn có thể sử dụng flag&nbsp;<strong>--all</strong>&nbsp;để liệt kê tất cả các service bất kể trạng thái của chúng hoặc chỉ định một service cụ thể theo tên chính xác của nó để có thông tin trạng thái chi tiết:</p>

<pre id="pre5">
<code>systemctl status ssh.service</code></pre>

<h3 style="text-align: justify;">Thưởng thức quyền kiểm soát</h3>

<p style="text-align: justify;">Nếu là người thích tinh chỉnh và kiểm soát chi tiết những gì đang chạy trên hệ thống của mình, bạn sẽ đánh giá cao khả năng của systemd. Các công cụ mà systemd cung cấp rất mạnh mẽ và linh hoạt, cho phép quản lý chi tiết trạng thái service cần thiết cho bất kỳ quản trị viên hệ thống nào.</p>

<h3 style="text-align: justify;">Làm thế nào để liệt kê tất cả các service, cho dù đang hoạt động hay không?</h3>

<p style="text-align: justify;">Bạn có thể liệt kê tất cả các service đã cài đặt, cho dù đang hoạt động hay không, bằng cách sử dụng lệnh sau:</p>

<pre id="pre6">
<code>systemctl list-units --type=service --all</code></pre>

<p style="text-align: justify;">Lệnh này hiển thị mọi service được cài đặt trên hệ thống của bạn, bao gồm cả những service hiện không chạy.</p>

<h3 style="text-align: justify;">Làm thế nào để bắt đầu hoặc dừng một service?</h3>

<p style="text-align: justify;">Để bắt đầu một service, hãy sử dụng:</p>

<pre id="pre7">
<code>sudo systemctl start &#91;service-name&#93;.service</code></pre>

<p style="text-align: justify;">Để dừng một service, hãy sử dụng:</p>

<pre id="pre8">
<code>sudo systemctl stop &#91;service-name&#93;.service</code></pre>

<p style="text-align: justify;">Thay thế&nbsp;<strong>&#91;service-name&#93;</strong>&nbsp;bằng tên của service mà bạn muốn kiểm soát.</p>

<h3 style="text-align: justify;">Làm thế nào để cho phép một service bắt đầu khi khởi động?</h3>

<p style="text-align: justify;">Để đảm bảo service tự động chạy khi khởi động, hãy sử dụng:</p>

<pre id="pre9">
<code>sudo systemctl enable &#91;service-name&#93;.service</code></pre>

<p style="text-align: justify;">Lệnh này tạo liên kết tượng trưng từ bản sao file service của hệ thống (thường nằm trong&nbsp;<strong>/etc/systemd/system/</strong>&nbsp;hoặc&nbsp;<strong>/lib/systemd/system/</strong>) đến vị trí mà systemd tìm kiếm các file tự động chạy khi khởi động.</p>

<h3 style="text-align: justify;">Lệnh nào để kiểm tra trạng thái của một service cụ thể?</h3>

<p style="text-align: justify;">Để kiểm tra trạng thái của một service cụ thể, bạn có thể sử dụng:</p>

<pre id="pre10">
<code>systemctl status &#91;service-name&#93;.service</code></pre>

<p style="text-align: justify;">Lệnh này cung cấp thông tin chi tiết về service, bao gồm trạng thái hiện tại, nhật ký gần đây nhất và cấu hình.</p>

<h3 style="text-align: justify;">Làm thế nào để load lại service sau khi thay đổi cấu hình của service đó?</h3>

<p style="text-align: justify;">Sau khi sửa đổi cấu hình của service, bạn có thể load lại service để áp dụng những thay đổi này bằng:</p>

<pre id="pre11">
<code>sudo systemctl reload &#91;service-name&#93;.service</code></pre>

<p style="text-align: justify;">Lệnh này yêu cầu service load lại các file cấu hình của mình mà không dừng và khởi động lại hoàn toàn service.</p>

<h3 style="text-align: justify;">Có cách nào để xem nhật ký của một service cụ thể không?</h3>

<p style="text-align: justify;">Có, để xem nhật ký cho một service cụ thể, bạn có thể sử dụng lệnh journalctl:</p>

<pre id="pre12">
<code>journalctl -u &#91;service-name&#93;.service</code></pre>

<p style="text-align: justify;">Lệnh này sẽ hiển thị các mục nhật ký cho service được chỉ định. Thêm&nbsp;<strong>-f</strong>&nbsp;sẽ theo dõi nhật ký, hiển thị các mục mới khi chúng xuất hiện.</p>

<p style="text-align: justify;">Bạn có thể liệt kê các service theo trạng thái load hoặc trạng thái hoạt động của chúng không?<br />
Hoàn toàn có thể! Bạn có thể lọc các service dựa trên trạng thái load hoặc trạng thái hoạt động của chúng bằng cách sử dụng:</p>

<pre id="pre13">
<code>systemctl list-units --type=service --state=loaded</code></pre>

<p style="text-align: justify;">hoặc</p>

<pre id="pre14">
<code>systemctl list-units --type=service --state=active</code></pre>

<p style="text-align: justify;">Các lệnh này giúp bạn thu hẹp danh sách xuống những service đã được load vào hệ thống hoặc hiện đang hoạt động.</p>

<p style="text-align: justify;">Thành thạo cách liệt kê và quản lý các service bằng systemd là một kỹ năng quan trọng đối với bất kỳ ai sử dụng Linux. Chúng ta đã khám phá cách kiểm tra trạng thái của các service, cách bắt đầu, dừng và quản lý chúng, cũng như cách đảm bảo chúng hoạt động như mong đợi bằng những lệnh như systemctl. Cho dù bạn đang khắc phục sự cố, tinh chỉnh hệ thống của mình hay chỉ tò mò về những gì đang chạy bên trong, các công cụ do systemd cung cấp đều mang đến một cách toàn diện và mạnh mẽ để giữ cho hệ thống Linux của bạn được tổ chức và hoạt động hiệu quả.</p>

<div style="text-align: justify;">&nbsp;</div>
		</div>
				<div id="author">
						<p>
				<strong>Nguồn tin:</strong>
				Quantrimang.com:
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/cach-su-dung-systemctl-de-liet-ke-tat-ca-cac-service-linux-10177.html" title="Cách sử dụng Systemctl để liệt kê tất cả các service Linux">https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/cach-su-dung-systemctl-de-liet-ke-tat-ca-cac-service-linux-10177.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; .&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.
		</div>
		<div id="contact">
			<a href="mailto:admin@nguoicodonvn2008.info">admin@nguoicodonvn2008.info</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://www.nguoicodonvn2008.info/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
		</script>
		<div class="car-top">
  <span><img src="https://www.nguoicodonvn2008.info/themes/default/images/car.png" alt=""></span>
</div>
<div id="run_cronjobs" style="visibility:hidden;display:none;"><img alt="cron" src="/index.php?second=cronjobs&amp;p=n1QMy8bZ" width="1" height="1" /></div>
<script src="https://www.nguoicodonvn2008.info/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4c_e856T",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="https://www.nguoicodonvn2008.info/assets/js/language/vi.js"></script>
<script src="https://www.nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js"></script>
<script src="https://www.nguoicodonvn2008.info/assets/js/global.js"></script>
<script src="https://www.nguoicodonvn2008.info/assets/js/site.js"></script>
<script src="https://www.nguoicodonvn2008.info/themes/default/js/news.js"></script>
<script src="https://www.nguoicodonvn2008.info/themes/default/js/main.js"></script>
<script src="https://www.nguoicodonvn2008.info/themes/default/js/custom.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://www.nguoicodonvn2008.info",
            "logo": "https://www.nguoicodonvn2008.info/uploads/angel.gif"
        }
        </script>
<script src="https://www.nguoicodonvn2008.info/themes/default/js/bootstrap.min.js"></script>
<script type="text/javascript">
var $scrolltop = $('.car-top');
$scrolltop.on('click', function () {
    $('html,body').animate({
        scrollTop: 0
    }, 800);
    $(this).addClass("car-run");
    setTimeout(function(){ $scrolltop.removeClass('car-run');}, 1000);
    return false;
});
$(window).on('scroll', function ()
{ 
    if($(window).scrollTop() >= 200)
    {
        $scrolltop.addClass("show");
        $scrolltop.addClass("car-down");
    }
    else
    {
       $scrolltop.removeClass("show");
       setTimeout(function(){ $scrolltop.removeClass('car-down');}, 300);
    }
});
</script>
</body>
</html>