Steps to build a file server using Apache under Linux

Steps to build a file server using Apache under Linux

1. About the file server

In a project, if you want to share public software or data with project team members, you can build a simple file server to achieve it. As long as the members are in the local area network, they can download and access the data through the browser or wget command. It can achieve the effect of information sharing and consistent software versions. This article describes how to use Apache service to build a file server in a Linux environment.

2. Use Apache to build a file server

1. The Apache service in the Linux environment is called httpd, so first install the httpd service. If the yum source is configured, directly use the yum command to install

If the yum source is not configured, you can refer to the blog "linux configure local yum source, configure domestic yum source, configure epel source" for configuration. The URL is: //www.jb51.net/article/202406.htm

[root@node5 ~]# yum -y install httpd

2. Start the httpd service

#Start httpd service[root@node5 ~]# systemctl start httpd

#Check httpd service status[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.

#Check the Apache version [root@node5 ~]# httpd -version
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 16 2020 16:18:20

3. Check the IP address and access the Apache page

#You can see that the local IP address is 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

Visit http://192.168.110.184/ in your browser. If the following interface appears, it means that the Apache service has been installed successfully.

4. Create a shared directory /opt/soft and put all the files that need to be shared in this directory

[root@node5 soft]# mkdir /opt/soft

#This command puts all the tar.gz compressed packages in the system into the shared directory [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 cookies.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. Because the default page for accessing Apache is /var/www/html/, just link the shared directory to /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. Restart the Apache service and view the page

[root@node5 ~]# systemctl restart httpd

Use a browser to access http://192.168.110.184/file/. If the following interface appears, it means that the file server has been set up.

7. Through the web page, we found that Chinese characters are garbled. We can modify the configuration file to make Chinese characters display normally.

#Append a line to the end of the Apache configuration file [root@node5 ~]# echo "IndexOptions Charset=UTF-8" >> /etc/httpd/conf/httpd.conf

[root@node5 ~]# systemctl restart httpd

Visit the web page http://192.168.110.184/file/ again and find that the Chinese text on the page is displayed normally.

3. Test whether the file server is available

1. Use a browser on Windows to access http://192.168.110.184/file/. If the page can be opened and the software is automatically downloaded when you click it, it means that the file is downloaded successfully through Windows.

2. Test whether you can download files on another Linux machine in the LAN

#First, use the root account on the node8 machine to test the download file #Use the wget command to download the file [root@node8 ~]# wget http://192.168.110.184/file/Cookie.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: 'cookies.txt'

100%[= ...   

2020-12-17 16:53:00 (130 MB/s) - 'cookie.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%[= ...   

2020-12-17 16:53:26 (268 MB/s) - 'today_db.tar.gz' saved [767/767]

#Found that the file can be downloaded normally [root@node8 ~]# ls cookie.txt today_db.tar.gz
today_db.tar.gz cookies.txt

#Use the common account file1 on the node8 machine to test the download file [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/Cookie.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: 'cookies.txt'

100%[= ...   

2020-12-17 17:44:10 (254 MB/s) - 'cookie.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%[= ...   

2020-12-17 17:44:20 (216 MB/s) - 'today_db.tar.gz' saved [767/767]

#Found that the file [file1@node8 ~] can be downloaded normally$ ls
today_db.tar.gz cookies.txt

Since then, the file server has been successfully built and functions normally.

The above are the details of the steps to use Apache to build a file server under Linux. For more information about building a file server in Linux, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Linux installation apache server configuration process
  • How to install Apache service in Linux operating system
  • Detailed explanation of Apache website service configuration based on Linux
  • A brief analysis of the configuration and management of Apache servers under Linux
  • Deployment and configuration of Apache service under Linux

<<:  Creation, constraints and deletion of foreign keys in MySQL

>>:  Vue implements table paging function

Recommend

How to use the MySQL authorization command grant

The examples in this article run on MySQL 5.0 and...

MySQL 8.0 WITH query details

Table of contents Learning about WITH queries in ...

Specific use of GNU Parallel

what is it? GNU Parallel is a shell tool for exec...

A brief introduction to the usage of decimal type in MySQL

The floating-point types supported in MySQL are F...

Specific use of MySQL window functions

Table of contents 1. What is a window function? 1...

Vue implements zoom in, zoom out and drag function

This article example shares the specific code of ...

Implementing custom radio and check box functions with pure CSS

1. Achieve the effect 2 Knowledge Points 2.1 <...

Tutorial on resetting the root password of Mac MySQL

Disclaimer: This password reset method can direct...

Docker build PHP environment tutorial detailed explanation

Docker installation Use the official installation...

Implementation code for partial refresh of HTML page

Event response refresh: refresh only when request...

How to change the root password in a container using Docker

1. Use the following command to set the ssh passw...

Hide HTML elements through display or visibility

Sometimes we need to control whether HTML elements...

React introduces antd-mobile+postcss to build mobile terminal

Install antd-mobile Global import npm install ant...