Create a multi-function FreeBSD Server

Source: Internet
Author: User
Tags disk usage
Create a multi-functional FreeBSD server-Linux Enterprise Application-Linux server application information. The following is a detailed description. Hardware: Sai Yang 566, 8029 MB memory, 20 GB hard drive 9 (// home/usr/var/tmp), compatible with NICs, etc;
Software: Minimum installed FreeBsd 4.7

Let's talk about the sequence from shortest to deep;

1. Install webmin:
# Tar-zxvf webmin-version.tar.gz
# Mv webmin-version/usr/local/webmin
# Cd webmin
# Chmod 755 setup. sh
#./Setup. sh
Then you can basically press enter all the way. You don't understand these simple E-files either :)

2. install apache + mysql + php;
Required software package:
Assume that these packages are stored in the/home/down directory.

A. Install Mysql
# Pw groupadd mysql
# Pw useradd mysql-g mysql-s/nonexitent
# Tar-zxvf mysql-3.23.53.tar.gz
# Music mysql-3.23.53 mysql
# Cd mysql
#./Configure -- prefix =/usr/local/mysql
# Make
# Make install
# Scripts/mysql_install_db
# Chown-R root/usr/local/mysql
# Chown-R mysql/usr/local/mysql/var
# Chgrp-R mysql/usr/local/mysql
# Cp support-files/my-medium.cnf/etc/my. cnf
#/Usr/local/mysql/bin/safe_mysqld -- user = mysql &
# Echo "/usr/local/mysql/bin/safe_mysqld -- user = mysql &">/etc/rc. local
# Cd/usr/local/mysql/bin
#./Mysqladmin-u root-p password "your-password"

B. install apache
# Cd/home/down
# Tar-zxvf httpd-2.0.43.tar.gz
# Music httpd-2.0.43 apache
# Cd apache
#./Configure -- prefix =/usr/local/apache -- with-mysql =/usr/local/mysql -- enable-shared = max -- enable-module = so
# Make
# Make install
# Mv/usr/local/apache/htdocs/index.html. en/usr/local/apache/htdocs/index.html
#/Usr/local/apache/bin/apachectl start

C. install php
# Cd/home/down
# Tar-zxvf php-4.3.0.tar.gz
# Music php-4.3.0 php
# Cd php
#./Configure -- prefix =/usr/local/php4 -- with-mysql =/usr/local/mysql -- with-apxs2 =/usr/local/apache/bin/apxs
# Make
# Make install
# Ee/usr/local/apache/conf/httpd. conf
Add the following three lines of code to make apache support php, and then save and exit.
LoadModule php4_module modules/
AddType application/x-httpd-php. php
AddType application/x-httpd-php-source. phps
Search for DirectoryIndex index.html In the httpd. conf file, and add index.htm index. php to the terminal.
Now apache + mysql + php has been configured !!

3. Install Proftpd and integrate it with mysql
The required software package is stored in/home/down.
# Cd/home/down
# Tar? Zxvf proftpd-1.2.7.tar.gz
# Mv proftpd-1.2.7 proftpd
# Cp mod_sql-4.0.8.tar.gz proftpd/contrib/
# Cd proftpd/contrib/
# Tar-zxvf mod_sql-4.0.8.tar.gz
# Ee mod_ SQL _mysql.c
Set # include Change to # include
Assume that your Mysql is installed in/usr/local/mysql
# Cd ..

Configure to make Proftpd support MySQL authentication:
#./Configure -- prefix =/usr/local/proftpd \
-- With-modules = mod_ SQL: mod_ SQL _mysql \
-- With-Primary des =/usr/local/mysql/include/mysql \
-- With-libraries =/usr/local/mysql/lib/mysql
# Make
# Make install
After installation, perform the following steps to test whether Proftpd works properly:
# Sh sample-deployments/PFTEST. install
The temporary files required for the test are placed in the/tmp/PFTEST directory. Run the following command:
#./Proftpd-n-d 5-c/tmp/PFTEST. conf
If it works properly, you can find a lot of information and the last line will show:
ProFTPD 1.2.6 (built ***) standalone mode STARTUP
It indicates that the service is started. The port number is 2021. You can use the user proftpd and password proftpd to perform a logon test. If it is normal, you can make the following preparations; otherwise, check whether the installation is correct.

Create a database and a table for the FTP service.
1. You can create a dedicated database for this service or store it in other databases. Here I create a dedicated database FTP:

> Create database proftpd;

Create a user table ftpusers in this database, which is required:

> Use proftpd;
> Create table ftpusers (
> Userid text not null,
> Passwd text not null,
> Uid int not null,
> Gid int not null,
> Home TEXT,
> Shell TEXT
> );
This table is required for user authentication. userid and passwd are essential, and userid is the username used for FTP service; passwd is the password of this user; uid is the ID of the System user, that is, the mapped system user; gid is the ID of the system group to which the user belongs; home is the HOME directory of the user; you can specify a shell for this user. Of course, you can create more fields, such as the count used to record the number of user logins, or the date of the date. If you are familiar with the configuration, you can add more features as you like. I will not talk about it here.
3. If you want to use all the functions, you can add another required table: ftpgroups, that is, the table for determining the group. Of course, you can skip this step, here is a format:
Create table ftpgroups (
Groupname text not null,
Gid smallint not null,
Groupname is the group name, gid is the system group ID, and members is a member of the group. Note: multiple members must be separated by commas (,). spaces are not allowed.

Insert record for an empty table:
Insert into ftpusers (userid, passwd, uid, gid, home, shell)
Values ('test', 'test', '000000', '000000', '/home/ftp/test ','');

In this format, you can insert a record for each user.
If you want to apply more features and create a group table, you also need to add records for it. However, you must note that multiple members in the members field must be separated by commas.

Create a system user for the FTP user.
In this example, only one valid system user ftpusers and a group ftpgroups are provided for the entire FTP service. Of course, you can also set multiple system users. For the sake of security, I only set one, use it to start FTP daemon, and map all FTP users to this user.

Create an FTPGRP group first:
# Pw groupadd ftpgroups? G 2000
Create an FTPUSR User:
# Pw adduser ftpusers? U 2000? G 2000? D/home/ftp? S/nonexistent

Create a HOME for FTPUSR and store all the FTP user active spaces in this directory:
# Mkdir/home/ftp
# Chown ftpusers/home/ftp
# Chgrp ftpgroups/home/ftp

Now you can create a disk limit data table in the mysql FTP database:

Create table quotalimits (
Name VARCHAR (30 ),
Quota_type ENUM ("user", "group", "class", "all") not null,
Per_session ENUM ("false", "true") not null,
Limit_type ENUM ("soft", "hard") not null,
Bytes_in_avail float not null,
Bytes_out_avail float not null,
Bytes_xfer_avail float not null,
Files_in_avail int unsigned not null,
Files_out_avail int unsigned not null,
Files_xfer_avail INT UNSIGNED NOT NULL

Create table quotatallies (
Name VARCHAR (30) not null,
Quota_type ENUM ("user", "group", "class", "all") not null,
Bytes_in_used float not null,
Bytes_out_used float not null,
Bytes_xfer_used float not null,
Files_in_used int unsigned not null,
Files_out_used int unsigned not null,

Note: The quotatallies table does not need to be modified. It records the user's current disk usage and is automatically recorded by the program.
Note the meaning of some fields in the quotalimits table.
Quota_type: identifies the disk quota. You can set a single user, set all users in a group, and set all users.
Bytes_in_avail the maximum number of bytes for uploading, that is, the FTP user space capacity (the unit is byte (bytes) when setting the fields). If the limit is 10 MB, It is 10240000, and the same is true below)
Bytes_out_avail indicates the maximum number of bytes to download. Note that this field records the total amount of data that can be downloaded from the server and the total amount of data.
Bytes_xfer_avail indicates the maximum number of bytes of files that can be transferred in total (upload and download traffic). Note that this field records the maximum number of bytes of files that can be transferred in total, data is accumulated.
Total number of files that can be uploaded by files_in_avail INT
Total number of files that files_out_avail INT can download from the server
Files_xfer_avail INT total number of files that can be transferred (upload and download)

Then copy the following SQL statements to proftpd. conf without modification:

# The following is an SQL CALL statement. You do not need to modify the statement and copy it directly.

SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail ,\
Bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail FROM quotalimits \
WHERE name = '% {0}' AND quota_type = '% {1 }'"

SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used ,\
Bytes_xfer_used, files_in_used, files_out_used, files_xfer_used FROM quotatallies \
WHERE name = '% {0}' AND quota_type = '% {1 }'"

SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + % {0 },\
Bytes_out_used = bytes_out_used + % {1}, bytes_xfer_used = bytes_xfer_used + % {2 },\
Files_in_used = files_in_used + % {3}, files_out_used = files_out_used + % {4 },\
Files_xfer_used = files_xfer_used + % {5 }\
WHERE name = '% {6}' AND quota_type = '% {7}' "quotatallies

SQLNamedQuery insert-quota-tally INSERT "% {0}, % {1}, % {2}, % {3}, % {4}, % {5 }, % {6}, % {7} "quotatallies

QuotaLimitTable SQL:/get-quota-limit
QuotaTallyTable SQL:/get-quota-tally/update-quota-tally/insert-quota-tally

Configure the main configuration file of proftpd.
The Proftpd configuration file proftpd. conf is in the/usr/local/etc/directory. You can use different configuration files for unnecessary authentication. With MySQL authentication, you can copy mod_ SQL .conf to/usr/local/etc and rename it proftpd. conf.
Modify the proftpd. conf file as follows:

# Set the FTP server name:
ServerName "My FTP Server"

# Set the FTP server type:
ServerType standalone
DefaultServer on

# Set the root to restrict user activity somewhere and enhance server security.
DefaultRoot ~

# Set the FTP service port number. The standard FTP service port is 21.
Port 21

# Set the permission mask when creating a new file or directory:
Umask 022

# Set the system log file:
SystemLog/var/log/ftp. syslog

# Set the log file for recording file transfer:
TransferLog/var/log/ftp. transferlog

# Set the maximum number of logon attempts. If the maximum number of logon attempts is exceeded, the connection is automatically disconnected:
MaxLoginAttempts 3

# Set resumable upload
AllowRetrieveRestart on

# IP address speed limit (in BPS, the following is 80 kb/S)
RateReadBPS 80000
RateWriteBPS 80000

# Set MySQL authentication:

# Database connection information. DatabaseName indicates the Database Name and HostName indicates the host name,
# Port indicates the Port number, UserName indicates the UserName used to connect to the database, and Password indicates the Password.
SQLConnectInfo DatabaseName @ HostName: Port UserName Password
# My instance is SQLConnectInfo FTP @ localhost: 3306 root ******
# Database Authentication Type:
SQLAuthTypes Backend Plaintext
# Specify information about the table used for user authentication.
SQLUserInfo FTPUSERS userid passwd uid gid home shell
# Set to allow users to log on If shell is empty:
RequireValidShell off
# Database Authentication. Here is the method used for users:
SQLAuthenticate users
# If the home directory does not exist, the system creates a directory based on its home item:
SQLHomedirOnDemand on

# To prevent DoS attacks, set the maximum process:
MaxInstances 30

# Set system users and groups for normal services:
User ftpusers
Group ftpgroups

# Set the information displayed during user logon and the information in each subdirectory:
DisplayLogin welcome. msg
DisplayFirstChdir. message
# Set the maximum number of logins:
# Resumable upload:
AllowRetrieveRestart on
AllowStoreRestart on

After the file configuration is completed, you can start the Proftpd service to test whether it is successful:
Modify the configuration file of apahce so that the proftpd user directory added through mysql can be browsed on the web.
Set UserDir public_html
Change to UserDir/home/ftp /*/
Restart apache to make the change take effect, and then start proftpd to log in with the test account for testing.
#/Usr/local/proftpd/sbin/proftpd? N &

Note: If you run Proftpd in FreeBSd4.7 and 5.0, the following error may be prompted.
/Usr/local/ftp/sbin/proftpd: error while loading shared libraries: libmysqlclient. so.10: cannot open shared object file:
No such file or directory
The solution is as follows:
When installing mysql, add the directory of the mysql database to the configuration file, for example
Echo "/usr/local/mysql/lib/mysql">/etc/ld. so. conf
Run ldconfig-v | grep libmysqlclient and try again!

Or copy all the files under/usr/local/mysql/lib/mysql/to/usr/lib.

If testlogin succeeds, put an index.html file in the root directory of testuser.
Http: // yourserver /~ Test.

It's not going to be continued yet. I hope it can be used as an example. You can write it later. Even the technology is too bad. I haven't played BSD for a while, 555 ~~~~
My proftpd. conf configuration file:

ServerName "white fox's FTP Server"
ServerType standalone
DefaultServer on

# Port 21 is the standard FTP port.
Port 21

# Umask 022 is a good standard umask to prevent new dirs and files
# From being group and world writable.
Umask 022

# Limit the user in his owner directory
DefaultRoot ~

# Put the proftpd log files in/var/log/ftp. syslog
SystemLog/var/log/ftp. syslog

# TransferLog log files
TransferLog/var/log/ftp. transferlog

# Set The maxtimes user Attempts times
MaxLoginAttempts 3

# Setup the Restart
AllowRetrieveRestart on

# Setup the download and upload speed
RateReadBPS 80000
RateWriteBPS 80000

# Setup the disk quota
QuotaDirectoryTally on

# Quota B "|" Kb "|" Mb "|" Gb"
# Setup the disk quota
QuotaDirectoryTally on

# Quota B "|" Kb "|" Mb "|" Gb"
QuotaDisplayUnits Kb
QuotaEngine on
QuotaLog/var/ftp/Quota. log
QuotaShowQuotas on

# We put our mod_ SQL directives in Block so they'll be
# Inherited by the block below, and any other
# Blocks we may want to add. For a simple server these don't need
# Be in Block but it won't hurt anything.

# Specify our connection information. Both mod_ SQL _mysql and
# Mod_ SQL _postgres use the same format, other backends may specify
# Different format for the first argument to SQLConnectInfo. By not
# Specifying a fourth argument, we're ululting to 'persession'
# Connections -- a connection is made to the database at the start
# The session and closed at the end. This shoshould be fine for most
# Situations.

# SQLConnectInfo dbname @ host: port username password
SQLConnectInfo ftp @ localhost: 3306 root 12345678

# Specify our authentication schemes. Assuming we're using
# Mod_ SQL _mysql, here we're re saying 'first try to authenticate using
# Mysql's password scheme, then try to authenticate the user's
# Password as plaintext '. Note that 'plaintext' isn' t a smart way
# Store passwords unless you 've got your database well secured.
SQLAuthTypes Backend Plaintext

# Specify the table and fields for user information. If you 've
# Created the database as it specifies in 'readme. mod_ SQL ', you don't
# Need to have this directive at all UNLESS you 've elected not
# Create some fields. In this case we're telling mod_ SQL to look in
# Table 'users' for the fields 'username', 'Password', 'uid', and
# 'Gid'. The 'homedir' and 'shell' fields are specified as 'null '--
# This will be explained below.

# SQLUserInfo users username password uid gid NULL
SQLUserInfo ftpusers userid passwd uid gid home shell

# Here we tell mod_ SQL that every user it authenticates showould have
# The same home directory. A much more common option wocould be
# Specify a homedir in the database and leave this directive out. Note
# That this directive is necessary in this case because we specified
# The homedir field as 'null', above. mod_ SQL needs to get homedir
# Information from * somewhere *, otherwise it will not allow access.

# SQLDefaultHomedir "/tmp"

# This is not a mod_ SQL specific ctive, but it's here because
# The way we specified 'sqluserinfo', above. By setting this
# 'Off', we're telling ProFTPD to allow users to connect even if we
# Have no (or bad) shell information for them. Since we specified
# Shell field as 'null', above, we need to tell ProFTPD to allow
# Users in even though their shell doesn' t exist.

RequireValidShell off

# Here we tell mod_ SQL how to get out group information. By leaving
# This commented out, we're telling mod_ SQL to go ahead and use
# Defaults for the tablename and all the field names.
# SQLGroupInfo groups groupname gid members

# For small sites, the following directive will speed up queries
# The cost of some memory. Larger sites shocould read the complete
# Description of the 'sqlauthenticate' directive; there are options
# Here that control the use of potentially expensive database
# Queries. NOTE: these arguments to 'sqlauthoritative 'limit the way
# You can structure your group table. Check the README for more
# Information.

SQLAuthenticate users

# Finally, some example logging directives. If you have an integer
# Field named 'Count' in your users table, these directives will
# Automatically update the field each time a user logs in and display
# Their current login count to them.
# SQLNamedQuery getcount SELECT "count, userid from users where userid = '% U '"
# SQLNamedQuery updatecount UPDATE "count = count + 1 WHERE userid = '% U'" users
# SQLShowInfo PASS "230" "You 've logged on % {getcount} times, % u"
# SQLLog PASS updatecount

SQLHomedirOnDemand on

# ...... SQL ...............

SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail, delimiter, files_in_avail, files_out_avail, files_xfer_avail FROM quotalimits WHERE name = '% {0}' AND quota_type = '% {1 }'"

SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_in_used, files_out_used, files_xfer_used FROM quotatallies WHERE name = '% {0}' AND quota_type = '% {1 }'"

SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + % {0}, bytes_out_used = bytes_out_used + % {1}, bytes = bytes + % {2 }, files_in_used = files_in_used + % {3}, files_out_used = files_out_used + % {4 }, files_xfer_used = files_xfer_used + % {5} WHERE name = '% {6}' AND quota_type = '% {7}' "quotatallies

SQLNamedQuery insert-quota-tally INSERT "% {0}, % {1}, % {2}, % {3}, % {4}, % {5 }, % {6}, % {7} "quotatallies

QuotaLimitTable SQL:/get-quota-limit
QuotaTallyTable SQL:/get-quota-tally/update-quota-tally/insert-quota-tally

# Close our Block.

# To prevent DoS attacks, set the maximum number of child processes
# To 30. If you need to allow more than 30 concurrent connections
# At once, simply increase this value. Note that this ONLY works
# In standalone mode, in inetd mode you shoshould use an inetd server
# That allows you to limit maximum number of processes per service
# (Such as xinetd)
MaxInstances 30

# Set the normal user and group permissions for the server.
User ftpusr
Group ftpgrp

# Normally, we want files to be overwriteable.

AllowOverwrite on
AllowRetrieveRestart on
AllowStoreRestart on

# A basic anonymous configuration, no upload directories. If you
# Don't want to support anonymous access, simply remove this

User ftp
Group ftp
# We want clients to be able to login with "anonymous" as well as "ftp"
UserAlias anonymous ftp

# Limit the maximum number of anonymous logins
MaxClients 10

# We want 'Welcome. msg 'displayed at login, and'. message' displayed
# In each newly chdired directory.
DisplayLogin welcome. msg
DisplayFirstChdir. message

# Limit WRITE everywhere in the anonymous chroot


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.