在“萬物互聯(lián)”的技術(shù)浪潮下,網(wǎng)絡(luò)服務(wù)已成為連接物理世界與數(shù)字世界的核心紐帶,它不僅賦予了終端設(shè)備“開口說話”的能力,更構(gòu)建了智能設(shè)備的開發(fā)范式。
本文就將以飛凌嵌入式OK-MX9352-C開發(fā)板(搭載了在工業(yè)物聯(lián)網(wǎng)領(lǐng)域廣泛應(yīng)用的NXP i.MX9352處理器)為平臺,介紹如何在Linux6.1.36開發(fā)環(huán)境當(dāng)中如何搭建常用的網(wǎng)絡(luò)服務(wù),各位工程師朋友可以參考本文進(jìn)行操作。
1、TFTP服務(wù)搭建
TFTP(簡單文件傳輸協(xié)議),是TCP/IP協(xié)議族中用來在客戶機(jī)和服務(wù)器之間進(jìn)行簡單文件傳輸?shù)膮f(xié)議,通常用于內(nèi)核調(diào)試。在嵌入式Linux開發(fā)過程中,內(nèi)核調(diào)試是其中一個基礎(chǔ)、重要的環(huán)節(jié)。
1.1 安裝服務(wù)器、客戶端和守護(hù)進(jìn)程
forlinx@ubuntu:~$ sudo apt-get install tftp-hpa tftpd-hpa xinetd
1.2 服務(wù)器配置
首先,在根目錄下建一個tftpboot,并把屬性改成任意用戶可讀寫:
forlinx@ubuntu:~$ cd /
forlinx@ubuntu:/$ sudo mkdir tftpboot
forlinx@ubuntu:/$ sudo chmod 777 tftpboot
然后,進(jìn)入目錄/etc/xinetd.d/,并在其中新建文件tftp,把指定的內(nèi)容加入到tftp文件中:
forlinx@ubuntu:/$ cd /etc/xinetd.d/
forlinx@ubuntu:/etc/xinetd.d$ sudo vim tftp
添加以下內(nèi)容到tftp文件
service tftp
{
disable = no 138
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot -c
per_source = 11
cps = 100 2
}
最后,修改配置文件/etc/default/tftpd-hpa
forlinx@ubuntu:/etc/xinetd.d$ cd /
forlinx@ubuntu:/$ sudo vim /etc/default/tftpd-hpa
這里需要注意,將“TFTP_DIRECTORY”改為新建tftpboot目錄所在的路徑。
1.3 重新啟動服務(wù)
forlinx@ubuntu:/$ sudo /etc/init.d/xinetd reload
forlinx@ubuntu:/$ sudo /etc/init.d/xinetd restart
forlinx@ubuntu:/$ sudo /etc/init.d/tftpd-hpa restart
1.4 測試服務(wù)器
測試一下,在/tftpboot文件夾下新建一個文件
forlinx@ubuntu:/$ cd /tftpboot/
forlinx@ubuntu:/tftpboot$ sudo touch abc
進(jìn)入另外一個文件夾:
forlinx@ubuntu:/tftpboot$ cd /home/
forlinx@ubuntu:/home$ sudo tftp 192.168.2.57 //192.168.2.57為本機(jī)IP
tftp> get abc
tftp> quit
forlinx@ubuntu:/home$ ls
abc
如果可以下載說明服務(wù)器已經(jīng)安裝成功,將開發(fā)板同PC通過網(wǎng)線進(jìn)行連接后即可使用tftp下載文件。
bootz ${loadaddr} - ${fdt_addr};
2、NFS服務(wù)搭建
NFS(網(wǎng)絡(luò)文件系統(tǒng)),可以通過網(wǎng)絡(luò)讓不同機(jī)器、不同系統(tǒng)之間可以實現(xiàn)文件共享。通過NFS,可以訪問遠(yuǎn)程共享目錄,就像訪問本地磁盤一樣。
2.1 Ubuntu下搭建NFS服務(wù)器方法如下
軟件下載安裝
forlinx@ubuntu:~# sudo apt-get install nfs-kernel-server nfs-common portmap
創(chuàng)建NFS目錄并解壓文件系統(tǒng)(以rootfs.tar.bz2文件系統(tǒng)為例,當(dāng)前目錄為根目錄)
forlinx@ubuntu:~# cd /
forlinx@ubuntu:/# sudo mkdir nfs_rootfs
forlinx@ubuntu:/# sudo tar -xvf rootfs.tar.bz2 -C /nfs_rootfs/
修改配置文件
forlinx@ubuntu:/# sudo vim /etc/exports
在文件中添加以下配置:
/nfs_rootfs *(rw,sync,no_root_squash,no_subtree_check)
重啟配置文件和服務(wù)
forlinx@ubuntu:/# sudo exportfs -rv
forlinx@ubuntu:/# sudo /etc/init.d/rpcbind restart
forlinx@ubuntu:/# sudo /etc/init.d/nfs-kernel-server restart
2.2 在i.MX9352開發(fā)板上驗證NFS服務(wù)器
執(zhí)行完以下命令將NFS服務(wù)器掛載到開發(fā)板的/mnt目錄
root@ok-mx93:~# mount -t nfs4 -o vers=4 192.168.0.57:/nfs_rootfs /mnt
掛載成功后,查看/mnt目錄,會看到剛才解壓的文件系統(tǒng)
root@ok-mx93:~# ls /mnt/
注:192.168.0.57為NFS服務(wù)器主機(jī)Ubuntu的IP,Ubuntu的網(wǎng)絡(luò)需設(shè)置為橋接模式,并跟i.MX9352開發(fā)板在同一網(wǎng)段。
3、SSH服務(wù)搭建
SSH是較可靠的專為遠(yuǎn)程登錄會話和其他網(wǎng)絡(luò)服務(wù)提供安全性的協(xié)議,利用SSH協(xié)議可以有效防止遠(yuǎn)程管理過程中的信息泄露問題。SSH最初是UNIX系統(tǒng)上的一個程序,后來又迅速擴(kuò)展到其他操作平臺。
3.1 安裝SSH
在Ubuntu(Linux主機(jī))終端鍵入以下指令,安裝SSH服務(wù):
forlinx@ubuntu:/$?sudo?apt-get?install?ssh
3.2 啟動SSH服務(wù)
forlinx@ubuntu:/$ sudo service ssh start
3.3 查看SSH服務(wù)的狀態(tài)
forlinx@ubuntu:/$ sudo service ssh status
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-08-23 17:19:57 CST; 45s ago
Main PID: 7383 (sshd)
Tasks: 1 (limit: 2292)
CGroup: /system.slice/ssh.service
└─7383 /usr/sbin/sshd -D
8月 23 17:19:57 ubuntu systemd[1]: Starting OpenBSD Secure Shell server...
8月 23 17:19:57 ubuntu sshd[7383]: Server listening on 0.0.0.0 port 22.
8月 23 17:19:57 ubuntu sshd[7383]: Server listening on :: port 22.
8月 23 17:19:57 ubuntu systemd[1]: Started OpenBSD Secure Shell server.
3.4 關(guān)閉SSH服務(wù)
forlinx@ubuntu:/$ sudo service ssh stop
3.5 測試方法
i.MX9352開發(fā)板通過SSH訪問Linux主機(jī):
root@ok-mx93:~# ssh forlinx@192.168.0.57
Host '192.168.0.57' is not in the trusted hosts file.
(ecdsa-sha2-nistp256 fingerprint md5 07:72:76:56:47:e0:da:5e:77:a2:58:b1:b5:9f:cb:2a)
Do you want to continue connecting? (y/n) y //首次登錄需要確認(rèn),輸入y
forlinx@192.168.0.57's password: //輸入forlinx賬戶密碼
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-56-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 updates can be applied immediately.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
forlinx@ubuntu:~$???????????????????????//通過用戶名和主機(jī)名確認(rèn)ssh登錄成功
Linux主機(jī)通過SSH登錄i.MX9352開發(fā)板:
forlinx@ubuntu:~$ ssh -oHostKeyAlgorithms=+ssh-rsa root@192.168.0.232
The authenticity of host '192.168.0.232 (192.168.0.232)' can't be established.
RSA key fingerprint is SHA256:fsa3SVdSPDtCMacfd8PjHF1RIPsnXB22gKS97qJpwys.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes //首次登錄需要確認(rèn),輸入yes
Warning: Permanently added '192.168.0.232' (RSA) to the list of known hosts.
root@ok-mx93:~# //通過用戶名和主機(jī)名確認(rèn)ssh登錄成功
以上就是在飛凌嵌入式OK-MX9352-C開發(fā)板的Linux6.1.36系統(tǒng)上完成網(wǎng)絡(luò)服務(wù)搭建的方法,希望能夠?qū)Ω魑还こ處熍笥延兴鶐椭?。需要注意的是,本文的操作方法適用于飛凌嵌入式OK-MX9352-C平臺的Linux6.1.36操作系統(tǒng),其他平臺可能會存在差異,本文的方法僅作為參考。