掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
systemd是Linux系統(tǒng)最新的初始化系統(tǒng)(init),作用是提高系統(tǒng)的啟動速度,盡可能啟動較少的進程,盡可能更多進程并發(fā)啟動,下面為大家詳細(xì)講解一下linux中systemctl使用方法。

創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的裕民網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
我們最常使用的ssh服務(wù),系統(tǒng)默認(rèn)ssh服務(wù)22端口,我現(xiàn)在想再開一個ssh服務(wù),端口8888
1.系統(tǒng)服務(wù)啟動腳本 /usr/lib/systemd/system/sshd.service,將其復(fù)制到 /etc/systemd/system/ 下,并改名為 sshd2.service,文件內(nèi)容如下:
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
因為要重啟一個新的服務(wù),所以要修改一下ExecStart這一行,讀取新的配置文件 sshd2_config,改為
ExecStart=/usr/sbin/sshd -D $OPTIONS -f /etc/ssh/sshd2_config
2.到 /etc/ssh/ 下,將 sshd_config 復(fù)制到 sshd2_config,并修改端口那一行
Port 8888
3.運行命令 systemctl reload 重新加載一下配置
4.運行命令 systemctl status sshd2.service 查看狀態(tài)
5 運行命令 systemctl start sshd2.service 開啟服務(wù)
6.運行命令 systemctl enable sshd2.service 設(shè)置開機啟動
7.在另一臺機器上登錄 ssh fancy@ip -p8888 就可以登錄了
1.在 /root/bin/ 下創(chuàng)建一個shell腳本 fancy_test.sh,并修改其權(quán)限,chmod u+x fancy_test.sh,內(nèi)容如下
#!/bin/bash
logdate=$(date +%s)
logdir="/root/log/"
logname=fancy.${logdate}.log
#echo $logname
touch ${logdir}${logname}
意思是,運行該服務(wù)時,在 /root/log/ 目錄下創(chuàng)建一個日志文件
2.在 /etc/systemd/system/ 下創(chuàng)建啟動腳本 fancy_test.service,輸入一下內(nèi)容
[Unit]
Description=fancy_test server daemon
[Service]
Type=simple
ExecStart=/root/bin/fancy_test.sh
[Install]
WantedBy=multi-user.target
3.運行命令 systemctl reload
4.運行命令 systemctl start fancy_test.service
5.此時你會看到在 /root/log/ 目錄下創(chuàng)建了一個日志文件

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流