ubuntu LAMP配置實例+VSFTPD虛擬用戶管理網站

1、更新

    apt-get update

    2、安裝必須的包

    apt-get install php5

    apt-get install apache2 mysql-server mysql-client php5-mysql php5-curl php5-gd libapache2-mod-php5 php5-mysql

    3、/etc/apache2/httdpd.conf 添加:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps 字串6

    4、ln -s /etc/apache2/mods-available/php5.* /etc/apache2//mods-enabled 字串5

    5、apt-get install apache2-mpm-prefork

    6、/etc/init.d/apache2 restart

    網站管理(VSFTPD):

    一、安裝所需軟件包
    apt-get install vsftpd mysql-server mysql-client libpam-mysql
    libpam-mysql 這個包可以讓PAM讀取MySQL數據來驗證用戶信息,其它的軟件包就不用解譯了吧!

    二、設置FTP用戶權限與家目錄
    在操作第一步驟完後,系統會自動創建系統用戶名:ftp,這個用戶就是vsftpd默認的匿名用戶,沒有其它權限。在我的工作環境下這個用戶名的家目錄是 /home/ftp,RH系統ftp家目錄是/var/ftp。呵呵,這都是無關緊要的,可以自由設置!你也可以自定義ftp匿名用戶,並作相關修改,下載教程中用戶ftp也應修改成你自定義的用戶名。
    默認/home/ftp權限並不是用戶ftp,我們要修改下。
    #mkdir /home/ftp/temp
    #chown -R ftp.nogroup /home/ftp

    三、配置MySQL數據庫
    說起mysql我也慚愧,我對數據庫是一點也不懂!一直以來我把數據庫就簡單的理解爲一個龐大的信息倉庫的。即原是信息就不得不想起安全吧!mysql默認狀態下是很不安全的。我這裏就只能簡單的設置下口令,至於mysql優化請大家去閱讀mysql手冊吧!
    #mysqladmin -u root -p password 123456 修改mysql的root密碼,第一次修改因爲root密碼是空所以不用輸入舊密碼。
    連接數據庫:
    #mysql -h 127.1 -u root -p          使用root用戶連入本機mysql服務器
    Enter password:                          輸入root用戶密碼,注意:不是系統根用戶哦
    mysql>                                        連入成功!如果沒有出現這個提示符,則是上面兩個步驟沒有正確
    mysql>create databases vsftpd; 建立庫名。記住,在mysql環境下命令的結束必須有“;”,如果忘記了輸入“;”也不怕的,忘記了輸入“;”則是換行,在mysql裏面命令是可以分成 幾行執行的。你再輸入“;”起同樣的作用。
    mysql>show databases;                查看庫名是否建立,如果沒有則重新執行上一步。
    mysql>use vsftpd;                         打開庫vsftpd,以下操作就會針對vsftpd庫。
    mysql>create table users (name varchar(20) not null,password varchar(20) not null,primary key (name)) type=myisam;                               創建名爲users的表名,其中設置了兩個鍵name和password。這裏比較難理解,我一一解釋吧!varchar(20) not null設置鍵長度爲20,且不能爲空,primary key(name)設置表的主鍵(主鍵是不能賦相同的值,因爲ftp用戶名不能相同)。type=myisam設置表的類型(MyISAM 全新二進制可移植的表處理器),這個是默認的,可以省略。
    mysql>show tables;                       查看錶是否建立成功,沒有請退到上一步。
    mysql>insert into users values('admin','admin');               建設虛擬用戶admin,密碼爲admin。
    mysql>insert into users values('download','download');
    mysql>insert into users values('upload','upload');
    mysql>insert into users values('web','web');
    mysql>select * from users;                          驗證結果,如果看不到剛纔建立的虛擬用戶那麼請退到上一步。
    MySQL數據建好了,但是我們不能直接用root用戶吧,要給它建立個用戶供pam使用。
    mysql>grant select on vsftpd.users to vsftpd@localhost identified by 'vsftpd';
    grant 命令
    select on vsftpd.users 所有權限,這裏設置權限僅在vsftpd庫的users表使用select。
    to vsftpd@localhost 本機vsftpd用戶(mysql按照用戶名和所在IP區分用戶,root和root@%不是同一個用戶。)
    identified by 'vsftpd' 設置vsftpd@localhost用戶的口令爲vsftpd。
    mysql>quit;                                  退出mysql,mysql配置完成。

四、配置vsftpd的PAM驗證
    #vim /etc/pam.d/vsftpd
    把以前的內容全部註釋掉,然後添加如下肉容(下面只有兩行,請注意):
    auth required pam_mysql.so user=vsftpd passwd=vsftpd host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=0
    account required pam_mysql.so user=vsftpd passwd=vsftpd host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=0
    解釋一下:
    user=vsftpd    剛纔添加的mysql用戶名
    passwd=vsftpd 剛纔添加的用戶名密碼
    host=localhost mysql服務器名,我是做在本機所以……。
    db=vsftpd      與這個對應create databases vsftpd,是存儲用戶名的mysql庫名
    table=users    存儲用戶名的mysql庫中的表名
    usercolumn=name 與mysql對應的鍵
    passwdcolumn=password 與mysql對應的鍵
    crypt=0 加密方式,0表示明文,1表示unix方式加密,2表示mysql中的password函數加密,3表示md5加密的。不過我都只有做成明文才成功了,1、2、3方法都不行! 知道的朋友告訴下哦!

 

    五、配置vsftpd,這裏很重要,請大家參考vsftpd手冊,我這裏只簡單的實現一下。
    #vim /etc/vsftpd.conf
    #接受匿名用戶
    anonymous_enable=YES
    #匿名用戶login時不詢問口令
    no_anon_password=YES
    #匿名用戶主目錄
    anon_root=(none)
    #接受本地用戶
    local_enable=YES
    #本地用戶主目錄
    local_root=(none)
    #如果匿名用戶需要密碼,那麼使用banned_email_file裏面的電子郵件地址的用戶不能登錄
    deny_email_enable=YES
    #僅在沒有pam驗證版本時有用,是否檢查用戶有一個有效的shell來登錄
    check_shell=YES
    #若啓用此選項,userlist_deny選項才被啓動
    userlist_enable=YES
    #若爲YES,則userlist_file中的用戶將不能登錄,爲NO則只有userlist_file的用戶能登錄
    userlist_deny=NO
    #如果和chroot_local_user一起開啓,那麼用戶鎖定的目錄來自/etc/passwd每個用戶指定的目錄(這個不是非常清晰,非常哪位熟悉的指點一下)
    passwd_chroot_enable=NO
    #定義匿名登入的使用者名稱。默認值爲ftp。
    ftp_username=FTP
    #################用戶權限控制###############
    #能上傳(全局控制).
    write_enable=YES
    #本地用戶上傳文件的umask
    local_umask=022
    #上傳文件的權限配合umask使用
    #file_open_mode=0666
    #匿名用戶能上傳
    anon_upload_enable=NO
    #匿名用戶能建目錄
    anon_mkdir_write_enable=NO
    匿名用戶其他的寫權利(更改權限?)
    anon_other_write_enable=NO
    如果設爲YES,匿名登入者會被允許下載可閱讀的檔案。默認值爲YES。
    anon_world_readable_only=YES
    #如果開啓,那麼所有非匿名登陸的用戶名都會被轉換成guest_username指定的用戶名
    #guest_enable=NO
    所有匿名上傳的文件的所屬用戶將會被更改成chown_username
    chown_uploads=YES
    匿名上傳文件所屬用戶名
    chown_username=lightwiter
    #如果啓動這項功能,則所有列在chroot_list_file之中的使用者不能更改根目錄
    chroot_list_enable=YES
    #允許使用"async ABOR"命令,一般不用,容易出問題
    async_abor_enable=YES
    管控是否可用ASCII 模式上傳。默認值爲NO。
    ascii_upload_enable=YES
    #管控是否可用ASCII 模式下載。默認值爲NO。
    ascii_download_enable=YES
    #這個選項必須指定一個空的數據夾且所有登入者都不能有寫入的權限,當vsftpd 不必file system 的權限時,就會將使用者限制在此數據夾中。默認值爲/usr/share/empty
    secure_chroot_dir=/usr/share/empty
    ###################超時設置##################
    #空閒連接超時
    idle_session_timeout=600
    #數據傳輸超時
    data_connection_timeout=120
    #PAVS請求超時
    ACCEPT_TIMEOUT=60
    #PROT模式連接超時
    connect_timeout=60
    ################服務器功能選項###############
    #開啓日記功能
    xferlog_enable=YES
    #使用標準格式
    xferlog_std_format=YES
    #當xferlog_std_format關閉且本選項開啓時,記錄所有ftp請求和回覆,當調試比較有用.
    #log_ftp_protocol=NO
    #允許使用pasv模式
    pasv_enable=YES
    #關閉安全檢查,小心呀.
    #pasv_promiscuous+NO
    #允許使用port模式
    #port_enable=YES
    #關閉安全檢查
    #prot_promiscuous
    #開啓tcp_wrappers支持
    tcp_wrappers=YES
    #定義PAM 所使用的名稱,預設爲vsftpd。
    pam_service_name=vsftpd
    #當服務器運行於最底層時使用的用戶名
    nopriv_user=nobody
    #使vsftpd在pasv命令回覆時跳轉到指定的IP地址.(服務器聯接跳轉?)
    pasv_address=(none)
    #################服務器性能選項##############
    #是否能使用ls -R命令以防止浪費大量的服務器資源
    #ls_recurse_enable=YES
    #是否使用單進程模式
    #one_process_model
    #綁定到listen_port指定的端口,既然都綁定了也就是每時都開着的,就是那個什麼standalone模式
    listen=YES
    #當使用者登入後使用ls -al 之類的指令查詢該檔案的管理權時,預設會出現擁有者的UID,而不是該檔案擁有者的名稱。若是希望出現擁有者的名稱,則將此功能開啓。
    text_userdb_names=NO
    #顯示目錄清單時是用本地時間還是GMT時間,能通過mdtm命令來達到相同的效果
    use_localtime=NO
    #測試平臺優化
    #use_sendfile=YES
    ################信息類設置################
    #login時顯示歡迎信息.如果設置了banner_file則此設置無效
    ftpd_banner=歡迎來到** FTP 網站.
    #允許爲目錄設置顯示信息,顯示每個目錄下面的message_file文件的內容
    dirmessage_enable=YES
    #顯示會話狀態信息,關!
    #setproctitle_enable=YES
    ############## 文件定義 ##################
    #定義不能更改用戶主目錄的文件
    chroot_list_file=/etc/vsftpd/vsftpd.chroot_list
    #定義限制/允許用戶登錄的文件
    userlist_file=/etc/vsftpd/vsftpd.user_list
    #定義登錄信息文件的位置
    banner_file=/etc/vsftpd/banner
    #禁止使用的匿名用戶登陸時作爲密碼的電子郵件地址
    banned_email_file=/etc/vsftpd.banned_emails
    #日誌文件位置
    xferlog_file=/var/log/vsftpd.log
    #目錄信息文件
    message_file=.message
    ############## 目錄定義 #################
    #定義用戶設置文件的目錄
    user_config_dir=/etc/vsftpd/userconf
    #定義本地用戶登陸的根目錄,注意定義根目錄能是相對路徑也能是絕對路徑.相對路徑是針對用戶家目錄來說的.
    local_root=webdisk #此項設置每個用戶登陸後其根目錄爲/home/username/webdisk
    #匿名用戶登陸後的根目錄
    anon_root=/var/ftp
    #############用戶連接選項#################
    #可接受的最大client數目
    max_clients=100
    #每個ip的最大client數目
    max_per_ip=5
    #使用標準的20端口來連接ftp
    connect_from_port_20=YES
    #綁定到某個IP,其他IP不能訪問
    listen_address=192.168.0.2
    #綁定到某個端口
    #listen_port=2121
    #數據傳輸端口
    #ftp_data_port=2020
    #pasv連接模式時能使用port 範圍的上界,0 表示任意。默認值爲0。
    pasv_max_port=0
    #pasv連接模式時能使用port 範圍的下界,0 表示任意。默認值爲0。
    pasv_min_port=0
    ##############數據傳輸選項#################
    #匿名用戶的傳輸比率(b/s)
    anon_max_rate=51200
    #本地用戶的傳輸比率(b/s)
    local_max_rate=5120000

附錄:我自己設置的vsftpd.conf

    # Example config file /etc/vsftpd.conf
    #
    # The default compiled in settings are fairly paranoid. This sample file
    # loosens things up a bit, to make the ftp daemon more usable.
    # Please see vsftpd.conf.5 for all compiled in defaults.
    #
    # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
    # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
    # capabilities.
    #
    #
    # Run standalone? vsftpd can run either from an inetd or as a standalone
    # daemon started from an initscript.
    listen=YES
    #
    # Run standalone with IPv6?
    # Like the listen parameter, except vsftpd will listen on an IPv6 socket
    # instead of an IPv4 one. This parameter and the listen parameter are mutually
    # exclusive.
    #listen_ipv6=YES
    #
    # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
    anonymous_enable=NO
    #
    # Uncomment this to allow local users to log in.
    local_enable=YES
    #
    # Uncomment this to enable any form of FTP write command.
    write_enable=YES
    #
    # Default umask for local users is 077. You may wish to change this to 022,
    # if your users expect that (022 is used by most other ftpd's)
    local_umask=011
    #
    # Uncomment this to allow the anonymous FTP user to upload files. This only
    # has an effect if the above global write enable is activated. Also, you will
    # obviously need to create a directory writable by the FTP user.
    anon_upload_enable=YES
    #
    # Uncomment this if you want the anonymous FTP user to be able to create
    # new directories.
    anon_mkdir_write_enable=YES
    #
    # Activate directory messages - messages given to remote users when they
    # go into a certain directory.
    dirmessage_enable=YES
    #
    # Activate logging of uploads/downloads.
    xferlog_enable=YES
    #
    # Make sure PORT transfer connections originate from port 20 (ftp-data).
    connect_from_port_20=YES
    #
    # If you want, you can arrange for uploaded anonymous files to be owned by
    # a different user. Note! Using "root" for uploaded files is not
    # recommended!
    #chown_uploads=YES
    #chown_username=whoever
    #
    # You may override where the log file goes if you like. The default is shown
    # below.
    #xferlog_file=/var/log/vsftpd.log
    #
    # If you want, you can have your log file in standard ftpd xferlog format
    #xferlog_std_format=YES
    #
    # You may change the default value for timing out an idle session.
    #idle_session_timeout=600
    #
    # You may change the default value for timing out a data connection.
    #data_connection_timeout=120
    #
    # It is recommended that you define on your system a unique user which the
    # ftp server can use as a totally isolated and unprivileged user.
    #nopriv_user=ftpsecure
    #
    # Enable this and the server will recognise asynchronous ABOR requests. Not
    # recommended for security (the code is non-trivial). Not enabling it,
    # however, may confuse older FTP clients.
    #async_abor_enable=YES
    #
    # By default the server will pretend to allow ASCII mode but in fact ignore
    # the request. Turn on the below options to have the server actually do ASCII
    # mangling on files when in ASCII mode.
    # Beware that on some FTP servers, ASCII support allows a denial of service
    # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
    # predicted this attack and has always been safe, reporting the size of the
    # raw file.
    # ASCII mangling is a horrible feature of the protocol.
    #ascii_upload_enable=YES
    #ascii_download_enable=YES
    #
    # You may fully customise the login banner string:
    #ftpd_banner=Welcome to blah FTP service.
    #
    # You may specify a file of disallowed anonymous e-mail addresses. Apparently
    # useful for combatting certain DoS attacks.
    #deny_email_enable=YES
    # (default follows)
    #banned_email_file=/etc/vsftpd.banned_emails
    #
    # You may restrict local users to their home directories. See the FAQ for
    # the possible risks in this before using chroot_local_user or
    # chroot_list_enable below.
    chroot_local_user=YES
    #
    # You may specify an explicit list of local users to chroot() to their home
    # directory. If chroot_local_user is YES, then this list becomes a list of
    # users to NOT chroot().
    #chroot_list_enable=YES
    # (default follows)
    #chroot_list_file=/etc/vsftpd.chroot_list
    #
    # You may activate the "-R" option to the builtin ls. This is disabled by
    # default to avoid remote users being able to cause excessive I/O on large
    # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
    # the presence of the "-R" option, so there is a strong case for enabling it.
    #ls_recurse_enable=YES
    #
    #
    # Debian customization
    #
    # Some of vsftpd's settings don't fit the Debian filesystem layout by
    # default. These settings are more Debian-friendly.
    #
    # This option should be the name of a directory which is empty. Also, the
    # directory should not be writable by the ftp user. This directory is used
    # as a secure chroot() jail at times vsftpd does not require filesystem
    # access.
    secure_chroot_dir=/var/run/vsftpd
    #
    # This string is the name of the PAM service vsftpd will use.
    pam_service_name=vsftpd
    #
    # This option specifies the location of the RSA certificate to use for SSL
    # encrypted connections.
    rsa_cert_file=/etc/ssl/certs/vsftpd.pem
    guest_enable=YES #允許虛擬用戶
    guest_username=ftp #把虛擬用戶映射成本地用戶
    user_config_dir=/etc/vsftpd/vsftpd_user_conf #虛擬用戶的權限設置目錄

    設置文件範例如下,文件名就是虛擬用戶的名字

    local_root=/var/www #網站目錄
    anon_world_readable_only=NO
    write_enable=YES
    anon_upload_enable=YES
    anon_mkdir_write_enable=YES
    anon_other_write_enable=YES
    virtual_use_local_privs=YES
    chmod_enable=YES
    local_umask=011 #umask


    六、啓動服務
    #/etc/init.d/vsftpd stop
    #etc/init.d/mysql stop
    #etc/init.d/mysql start
    #etc/init.d/vsftpd start

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章