一.關(guān)于文件服務(wù)器
在一個(gè)項(xiàng)目中,如果想把公共軟件或者資料共享給項(xiàng)目組成員,可以搭建一個(gè)簡(jiǎn)易的文件服務(wù)器來(lái)實(shí)現(xiàn),只要是在局域網(wǎng)內(nèi)的成員都可以通過(guò)瀏覽器或者wget命令來(lái)下載和訪問(wèn)資料??梢赃_(dá)到信息共享,軟件版本一致的效果。本文講述在linux環(huán)境下使用Apache服務(wù)搭建文件服務(wù)器。
二.使用Apache搭建文件服務(wù)器
1.Apache服務(wù)在linux環(huán)境下的程序叫做httpd,所以首先安裝httpd服務(wù),如果配置好了yum源的話,直接使用yum命令安
裝,如果沒(méi)有配置好yum源的話,可以參考博客“l(fā)inux 配置本地yum源,配置國(guó)內(nèi)yum源,配置epel源”進(jìn)行配置,網(wǎng)址為://www.jb51.net/article/202406.htm
[root@node5 ~]# yum -y install httpd
2.啟動(dòng)httpd服務(wù)
#啟動(dòng)httpd服務(wù)
[root@node5 ~]# systemctl start httpd
#查看httpd服務(wù)狀態(tài)
[root@node5 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2020-12-17 16:26:05 CST; 7s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 98576 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─98576 /usr/sbin/httpd -DFOREGROUND
├─98577 /usr/sbin/httpd -DFOREGROUND
├─98578 /usr/sbin/httpd -DFOREGROUND
├─98579 /usr/sbin/httpd -DFOREGROUND
├─98580 /usr/sbin/httpd -DFOREGROUND
└─98581 /usr/sbin/httpd -DFOREGROUND
Dec 17 16:26:05 node5 systemd[1]: Starting The Apache HTTP Server...
Dec 17 16:26:05 node5 httpd[98576]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.110.184. Set the 'ServerName' directive globally to su...ss this message
Dec 17 16:26:05 node5 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
#查看Apache版本
[root@node5 ~]# httpd -version
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 16 2020 16:18:20
3.查看IP地址,訪問(wèn)Apache頁(yè)面
#可以看到本機(jī)IP地址為192.168.110.184
[root@node5 soft]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.110.184 netmask 255.255.255.0 broadcast 192.168.110.255
ether 00:0c:29:11:c4:4a txqueuelen 1000 (Ethernet)
RX packets 24682 bytes 13301526 (12.6 MiB)
RX errors 0 dropped 4 overruns 0 frame 0
TX packets 15119 bytes 2166095 (2.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 2402 bytes 221903 (216.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2402 bytes 221903 (216.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
在瀏覽器里訪問(wèn)http://192.168.110.184/,如果出現(xiàn)如下界面說(shuō)明Apache服務(wù)安裝成功
4.創(chuàng)建共享目錄/opt/soft,把需要共享的文件都放在這個(gè)目錄
[root@node5 soft]# mkdir /opt/soft
#此命令把系統(tǒng)所有的tar.gz的壓縮包都放在共享目錄里
[root@node5 soft]# find / -name "*.tar.gz" -exec mv {} /opt/soft \;
[root@node5 soft]# ls /opt/soft/
amhello-1.0.tar.gz elasticsearch-6.2.2.tar.gz FastDFS_v5.08.tar.gz kibana-6.2.2-linux-x86_64.tar.gz nginx-1.19.3.tar.gz ntp-4.2.6p5.tar.gz tomcat-native.tar.gz
apache-tomcat-8.0.51.tar.gz fastdfs_client_java._v1.25.tar.gz findfile.tar.gz libopts-40.0.15.tar.gz nginx-1.8.0.tar.gz rarlinux-3.8.0.tar.gz 餅干.txt
commons-daemon-native.tar.gz fastdfs-nginx-module_v1.16.tar.gz jdk-8u172-linux-x64.tar.gz nginx-1.10.0.tar.gz ngx_cache_purge-2.3.tar.gz today_db.tar.gz
5.因?yàn)樵L問(wèn)Apache頁(yè)面默認(rèn)讀取的是/var/www/html/頁(yè)面,所以把共享目錄鏈接到/var/www/html/下就可以了
[root@node5 ~]# ln -s /opt/soft /var/www/html/file
[root@node5 ~]# ll /var/www/html/file
lrwxrwxrwx 1 root root 9 Dec 17 16:29 /var/www/html/file -> /opt/soft
6.重啟Apache服務(wù),查看頁(yè)面
[root@node5 ~]# systemctl restart httpd
使用瀏覽器訪問(wèn)http://192.168.110.184/file/,如果出現(xiàn)如下界面,就說(shuō)明文件服務(wù)器搭建好了
7.通過(guò)網(wǎng)頁(yè)我們發(fā)現(xiàn)中文是亂碼,可以修改配置文件使中文正常顯示
#在Apache配置文件的末尾追加一行
[root@node5 ~]# echo "IndexOptions Charset=UTF-8" >> /etc/httpd/conf/httpd.conf
[root@node5 ~]# systemctl restart httpd
再次訪問(wèn)網(wǎng)頁(yè)http://192.168.110.184/file/,發(fā)現(xiàn)頁(yè)面的中文正常顯示了
三.測(cè)試文件服務(wù)器是否可用
1.在windows上使用瀏覽器訪問(wèn)http://192.168.110.184/file/,如果頁(yè)面可以打開(kāi),并且點(diǎn)擊軟件會(huì)自動(dòng)下載,說(shuō)明通過(guò)windows下載文件成功。
2.在局域網(wǎng)內(nèi)的另外一臺(tái)linux機(jī)器上測(cè)試是否可以下載文件
#首先在node8機(jī)器上使用root賬戶測(cè)試下載文件
#使用wget命令下載文件
[root@node8 ~]# wget http://192.168.110.184/file/餅干.txt
--2020-12-17 16:53:00-- http://192.168.110.184/file/%E9%A5%BC%E5%B9%B2.txt
Connecting to 192.168.110.184:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1181 (1.2K) [text/plain]
Saving to: ‘餅干.txt'
100%[=======================================================================================================================================================================>] 1,181 --.-K/s in 0s
2020-12-17 16:53:00 (130 MB/s) - ‘餅干.txt' saved [1181/1181]
[root@node8 ~]# wget http://192.168.110.184/file/today_db.tar.gz
--2020-12-17 16:53:26-- http://192.168.110.184/file/today_db.tar.gz
Connecting to 192.168.110.184:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 767 [application/x-gzip]
Saving to: ‘today_db.tar.gz'
100%[=======================================================================================================================================================================>] 767 --.-K/s in 0s
2020-12-17 16:53:26 (268 MB/s) - ‘today_db.tar.gz' saved [767/767]
#發(fā)現(xiàn)文件能正常下載
[root@node8 ~]# ls 餅干.txt today_db.tar.gz
today_db.tar.gz 餅干.txt
#使用node8機(jī)器上的普通賬戶file1測(cè)試下載文件
[root@node8 ~]# useradd file1
[root@node8 ~]# echo "123456" | passwd --stdin file1
Changing password for user file1.
passwd: all authentication tokens updated successfully.
[root@node8 ~]# su - file1
[file1@node8 ~]$ pwd
/home/file1
[file1@node8 ~]$ ls
[file1@node8 ~]$ wget http://192.168.110.184/file/餅干.txt
--2020-12-17 17:44:10-- http://192.168.110.184/file/%E9%A5%BC%E5%B9%B2.txt
Connecting to 192.168.110.184:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1181 (1.2K) [text/plain]
Saving to: ‘餅干.txt'
100%[=======================================================================================================================================================================>] 1,181 --.-K/s in 0s
2020-12-17 17:44:10 (254 MB/s) - ‘餅干.txt' saved [1181/1181]
[file1@node8 ~]$ wget http://192.168.110.184/file/today_db.tar.gz
--2020-12-17 17:44:20-- http://192.168.110.184/file/today_db.tar.gz
Connecting to 192.168.110.184:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 767 [application/x-gzip]
Saving to: ‘today_db.tar.gz'
100%[=======================================================================================================================================================================>] 767 --.-K/s in 0s
2020-12-17 17:44:20 (216 MB/s) - ‘today_db.tar.gz' saved [767/767]
#發(fā)現(xiàn)能正常下載文件
[file1@node8 ~]$ ls
today_db.tar.gz 餅干.txt
自此文件服務(wù)器搭建成功,功能正常。
以上就是linux下使用Apache搭建文件服務(wù)器的步驟的詳細(xì)內(nèi)容,更多關(guān)于Linux 搭建文件服務(wù)器的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!