LNMP+FTP搭建

操作环境

服务器:阿里云 CentOS7.2.1511
时间: 20170815

切换镜像源

查看当前的源镜像

#ls /etc/yum.repos.d/
CentOS-Base-Aliyun.repo  epel-Aliyun.repo

发现是阿里云的源,所以不需要备份,如果有文件 CentOS-Base.repo 那就执行下好备份的好习惯。

#cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.mybak

如果没有wget,就先安装wget

#yum install wget

下载新的源镜像,存放到/etc/yum.repos.d目录,并命名为CentOS-Base.repo

#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

源镜像缓存重新生成,然后更新

#yum clean all
#yum makecache
#yum update

安装Nginx

查找当前源镜像中是否存在ngnix的源,这里显示是存在的。

# yum list nginx
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Available Packages
nginx.x86_64                         1:1.10.2-1.el7 

如果上一步显示没有找到nginx的源,那就需要增加一个nginx的源nginx.repo

# vim /etc/yum.repos.d/nginx.repo

源文件的内容

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

再查找一次,比较而言,官网最新版本更新一点

# yum list nginx
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Available Packages
nginx.x86_64                      1:1.12.1-1.el7.ngx 

全自动安装nginx

#yum -y install nginx
······
Verifying  : 1:nginx-1.12.1-1.el7.ngx.x86_64                              1/1
Installed:
  nginx.x86_64 1:1.12.1-1.el7.ngx
Complete!

用curl查看是否安装成功,如果成功就会输出一个html页面

#curl 127.0.0.1



Welcome to nginx!



Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

开机启动设置

#systemctl enable nginx
#systemctl daemon-reload

重启服务器之后,查看是否安装成功

#systemctl status nginx

出现的一段反馈中存在绿色的文字 Active: active (running),说明服务已经启动,安装完成。

 nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-08-17 17:34:45 CST; 26s ago
     Docs: http://nginx.org/en/docs/
  Process: 9228 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 9232 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
  Process: 9231 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 9234 (nginx)
   CGroup: /system.slice/nginx.service
           ├─9234 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.c...
           └─9235 nginx: worker process

安装MySql(5.7)

访问官网https://dev.mysql.com/downloads/repo/yum/获得最新的合适链接,20170817官网适配的显示为
Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package 25.1K Download
(mysql57-community-release-el7-11.noarch.rpm)
进入下载页通过查看源码获得下载链接 http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
升级安装包

#rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

查看5.7版本是否已经启用

#yum repolist all | grep mysql
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:     39
mysql-connectors-community-source  MySQL Connectors Community -  disabled
mysql-tools-community/x86_64       MySQL Tools Community         enabled:     49
mysql-tools-community-source       MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
mysql55-community-source           MySQL 5.5 Community Server -  disabled
mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
mysql56-community-source           MySQL 5.6 Community Server -  disabled
mysql57-community/x86_64           MySQL 5.7 Community Server    enabled:    207
mysql57-community-source           MySQL 5.7 Community Server -  disabled
mysql80-community/x86_64           MySQL 8.0 Community Server    disabled
mysql80-community-source           MySQL 8.0 Community Server -  disabled

如果没有启用的话,就修改源文件

#vim /etc/yum.repos.d/mysql-community.repo

把需要的版本enabled改为1就可以了,其他的版本改为0

mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.6-community]
name=MySQL Cluster 7.6 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

修改完成之后查看可用的版本

#yum repolist enabled | grep mysql
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
mysql-connectors-community/x86_64 MySQL Connectors Community                  39
mysql-tools-community/x86_64      MySQL Tools Community                       49
mysql57-community/x86_64          MySQL 5.7 Community Server                 207

确定5.7版本启用了之后就可以安装MySql

#yum -y install mysql-community-server

安装完成之后,启动mysql

#service mysqld start

查看MySql的启动状态,启动成功

#service mysqld status
Redirecting to /bin/systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-08-17 18:16:07 CST; 12s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 9458 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 9385 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 9461 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─9461 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

开机启动设置

#systemctl enable mysqld
#systemctl daemon-reload

获得LOG文件(/var/log/mysqld.log)中自动生成的MySql的root默认密码

#grep 'temporary password' /var/log/mysqld.log
2017-08-15T10:16:02.549119Z 1 [Note] A temporary password is generated for root@localhost: /#LJyLPj-2kv

本次的默认密码为 /#LJyLPj-2kv ,这是随机的,每次安装都不同的。
接下来用这个默认密码登录MySql并修改root密码。

#mysql -uroot -p
Enter password:

这里输入上面的默认密码,输入后按回车,linux输入密码不显示的,注意大小写不要输错。

mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY '$Password0';

$Password0为你自己定义的密码,这里一般默认是至少要一个大写字母,一个小写字母,一个数字,一个特殊符号,长度至少8位,不然会提示密码太简单不予通过。
离开mysql

mysql> quit;
Bye

用vim在/etc/my.cnf配置文件的[mysqld]下添加编码配置,以修改默认编码。

character_set_server=utf8
init_connect='SET NAMES utf8'

重启mysql,使修改生效

#systemctl restart mysqld

安装PHP7

更新yum源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

直接yum安装php7.0,一般安装的扩展如下

#yum install php70w php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring  php70w-pecl-redis php70w-pecl-memcached php70w-devel

其余还有很多可用扩展

安装包         提供的拓展
php70w          mod_php , php70w-zts
php70w-bcmath       
php70w-cli      php-cgi, php-pcntl, php-readline
php70w-common   php-api, php-bz2, php-calendar, php-ctype, php-curl, php-date, php-exif, php-fileinfo, php-filter, php-ftp, php-gettext, php-gmp, php-hash, php-iconv, php-json, php-libxml, php-openssl, php-pcre, php-pecl-Fileinfo, php-pecl-phar, php-pecl-zip, php-reflection, php-session, php-shmop, php-simplexml   , php-sockets, php-spl, php-tokenizer, php-zend-abi, php-zip, php-zlib
php70w-dba      
php70w-devel        
php70w-embedded     php-embedded-devel
php70w-enchant      
php70w-fpm      
php70w-gd       
php70w-imap     
php70w-interbase        php_database, php-firebird
php70w-intl     
php70w-ldap     
php70w-mbstring     
php70w-mcrypt       
php70w-mysql        php-mysqli, php_database
php70w-mysqlnd      php-mysqli, php_database
php70w-odbc     php-pdo_odbc, php_database
php70w-opcache      php70w-pecl-zendopcache
php70w-pdo      php70w-pdo_sqlite, php70w-sqlite3
php70w-pdo_dblib        php70w-mssql
php70w-pear     
php70w-pecl-apcu    
php70w-pecl-imagick 
php70w-pecl-memcached   
php70w-pecl-mongodb 
php70w-pecl-redis   
php70w-pecl-xdebug  
php70w-pgsql        php-pdo_pgsql, php_database
php70w-phpdbg       
php70w-process      php-posix, php-sysvmsg, php-sysvsem, php-sysvshm
php70w-pspell       
php70w-recode       
php70w-snmp     
php70w-soap     
php70w-tidy     
php70w-xml      php-dom, php-domxml, php-wddx, php-xsl
php70w-xmlrpc   

启动php-fpm

#systemctl start php-fpm

开机启动设置

#systemctl enable php-fpm
#systemctl daemon-reload

修改nginx的根目录

 vim /etc/nginx/conf.d/default.conf

定位location / { 并修改,添加index.php,修改后如下

location / {
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
}

定位location ~ .php$ 并修改,把注释去掉并且替换路径,修改后如下

location ~ \.php$ {
    root           /usr/share/nginx/html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

重启Nginx

#systemctl restart nginx

测试LAMP是否正常

 vim  /usr/share/nginx/html/index.php

在nginx的配置文件中显示的目录下新建一个index.php并且写入


打开对应网址,浏览器显示为


LNMP+FTP搭建_第1张图片

搭建ftp

首先要查看是否安装vsftp

# rpm -q vsftpd
package vsftpd is not installed

没有则安装vsftpd

#yum install -y vsftpd

完成后再检查一遍

#rpm -q vsftpd
vsftpd-3.0.2-21.el7.x86_64
#whereis vsftpd
vsftpd: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz

查看vsftpd服务的状态

#systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

发现默认是安装后是没有启动服务的(如果是激活状态,会有绿色的active标记),
手动启动vsftpd服务

#systemctl start vsftpd

再次查看vsftpd服务的状态

#systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-08-18 11:47:23 CST; 3s ago
  Process: 17727 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 17728 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─17728 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

发现服务已经启动,最后设置vsftpd服务开机自启

#systemctl enable vsftpd
#systemctl daemon-reload

配置vsftpd.conf,配置前先备份,这是好习惯。

#cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.mybak
#vim /etc/vsftpd/vsftpd.conf

配置文件vsftpd.conf修改如下

anonymous_enable=NO  # 禁用匿名登录
ascii_upload_enable=YES
ascii_download_enable=YES
chroot_local_user=YES  # 启用限定用户在其主目录下

之后添加下列内容到vsftpd.conf末尾

use_localtime=YES
listen_port=21
chroot_local_user=YES
idle_session_timeout=300
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd/vconf
data_connection_timeout=1
virtual_use_local_privs=YES
pasv_min_port=10060
pasv_max_port=10090
accept_timeout=5
connect_timeout=1

建立用户文件

#vim /etc/vsftpd/virtusers

添加内容(第一行用户名,第二行密码,不能使用root为用户名)

test
123456

安装db_load命令,安装之前先查询一下,如果已经有db_load,那就省略后面两步,如果没有db_load,先检查yum源是否有资源,没有资源需要自己配置源,有资源就直接yum源安装

#rpm –q  db  
package db is not installed

#yum search compat-db4
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * webtatic: us-east.repo.webtatic.com
=========================== N/S matched: compat-db4 ============================
compat-db47.i686 : The Berkeley DB database 4.7.25 compatibility library
compat-db47.x86_64 : The Berkeley DB database 4.7.25 compatibility library

#yum install -y compat-db47

生成用户数据文件

#db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db

设定PAM验证文件,并指定对虚拟用户数据库文件进行读取(权限r,w即可)

#chmod 600 /etc/vsftpd/virtusers.db 

修改/etc/pam.d/vsftpd文件,记得先备份下

#cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.mybak
#vim /etc/pam.d/vsftpd

将auth及account的所有配置行均注释掉,在里面添加下面两句(如果系统为32位,lib64改为lib)

#auth  sufficient  /lib64/security/pam_userdb.so  db=/etc/vsftpd/virtusers 
#account  sufficient  /lib64/security/pam_userdb.so  db=/etc/vsftpd/virtusers

新建系统用户vsftpd,用户目录为/home/vsftpd(我们访问的空间),用户登录终端设为/bin/false(即:使之不能登录系统)

#mkdir -p /home/vsftpd
#useradd vsftpd -d /home/vsftpd -s /bin/false
#chown -R vsftpd:vsftpd /home/vsftpd

建立用户根目录

mkdir -p /home/vsftpd/test/

在/etc/vsftpd下建立目录vconf,进入并建立虚拟用户个人配置文件

#mkdir /etc/vsftpd/vconf
#cd /etc/vsftpd/vconf
#touch test
#vim test

编辑test用户配置文件,内容如下,其他用户类似

local_root=/home/vsftpd/test/
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES

重启vsftpd服务器

#systemctl restart vsftpd.service
#systemctl status vsftpd.service

在/home/vsftpd/test/下面件几个文件夹用来测试

mkdir /home/vsftpd/test/test{1..3}

接下来在电脑浏览器中输入ftp://127.0.0.1/即可访问(把127.0.0.1替换成自己的网站地址)
用filezilla等软件也可以连接成功(需要使用主动模式)。

你可能感兴趣的:(LNMP+FTP搭建)