ubuntu LAMP配置实例+VSFTPD虚拟用户管理网站

来源:互联网 发布:腾讯云域名绑定ip 编辑:程序博客网 时间:2024/04/29 07:20

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,passwordvarchar(20) not null,primary key (name))type=myisam;                              创建名为users的表名,其中设置了两个键name和password。这里比较难理解,我一一解释吧!varchar(20) notnull设置键长度为20,且不能为空,primarykey(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=localhostdb=vsftpd table=users usercolumn=name passwdcolumn=password crypt=0
   account required pam_mysql.so user=vsftpd passwd=vsftpd host=localhostdb=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

 

原创粉丝点击