CentOS7 list-unit-files 设置服务开机启动

[root@stark-ali-ecs ~]# systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

启用开机启动 nginx 服务

[root@stark-ali-ecs ~]# systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

启用开机启动 php-fpm 服务

[root@stark-ali-ecs ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

启用开机启动 mariadb 服务

[root@stark-ali-ecs ~]# systemctl list-unit-files | grep enabled

搜索全部已启动的服务,enabled 启用;disabled 禁用。

[root@stark-ali-ecs ~]# systemctl list-unit-files | grep nginx

搜索 nginx 的开机启动状态,nginx 可以换成其他相关服务名称,如 mariadb。

CentOS7 crontab 定时任务设置系统自动重启

[root@stark-ali-ecs ~]# service crond status

查看定时任务器状态

[root@stark-ali-ecs ~]# service crond start

如果不在启动状态则使用该命令启动

[root@stark-ali-ecs ~]# vi /etc/crontab #编辑任务

设置任务

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

00 05 * * * root reboot #使用 root 用户在 5:00 分重启系统

编辑定时任务详情

[root@stark-ali-ecs ~]# service crond restart

保存定时任务器后重启定时任务器

配置完成系统自动定时重启后,将一些服务设置开机启动,请查看详情:https://hexingxing.cn/centos7-list-unit-files/

开启 Aliyun Linux 之旅

概览

由于之前的机器系统使用比较久,是在几年前购买时安装的 CentOS 6.8 x64,如果升级核心版本需要重装系统,在此之际又想体验一下新机器和新配置网络带宽,遂重新下单了一台阿里云 ECS,经过综合比较和自身实际需求,最终选择了 Aliyun Linux 系统,Aliyun Linux 和最新 CentOS 的 Linux 内核系统版本相近以及操作模式兼容,并且可以长期支持服务,下面就我最近两天从新机到安装使用过程碰到的问题做一个记录,以备自查或可以帮助有需要的朋友。

Hello, Hunting Beagle!

Aliyun Linux 系统完整版本号是 Aliyun Linux release 2.1903 LTS (Hunting Beagle) ,Hello, Hunting Beagle!

更新公网 IP

如果对新购买 ECS 分配的公网 IP 不满意,可以在购买后的 6 小时内申请更换,可更换三次。

Nginx 域名配置

我按之前思路去配置,结果在 /etc/nginx/conf.d 是空白,没有任何配置文件或模版,后面才查到配置在 /etc/nginx/ 里面的 nginx.conf,这个跟 CentOS 6.8 x64 默认配置有点不一样,配置参数和域名绑定都默认在 /etc/nginx/里面,当然,知道了后可以自己再改成跟 CentOS 6.8 x64 一样,为了不影响其他有关配置,所以就按系统本身的路径来配置,不折腾了。后面由于配置 HTTPS 还是调整了 nginx.conf 的配置思路,将默认的 nginx.conf 域名配置注释,在 conf.d 里面单独做域名配置。

Ningx 支持 PHP

安装好了 PHP 和 PHP-FPM 后,启动服务发现还是不能正常访问 php 文件,变成下载了,这个就是没有处理 php 文件,我同样按之前思路去找配置文件,在/etc/nginx/里面的 nginx.conf 配置文件里耗费了很多时间才查到原因,以下附上常规的简洁 Nginx 配置模板。

# The default server
# conf_file in /etc/nginx/conf.d/

server {
    listen         80;
    # listen       80 default_server;
    # listen       [::]:80 default_server;
    server_name    ssl.hexingxing.cn;
    root           /myweb/ssl;
    #rewrite ^(.*)$  https://$host$1 permanent;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    index index.html index.htm index.php;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME   /myweb/ssl$fastcgi_script_name;
        include        fastcgi_params;
    }
}

配置 MySQL(MariaDB)

使用 yum install mysql mysql-server 命令安装,安装后懵了,竟然启动不了,提示 “Failed to start mysqld.service: Unit not found.”,经过多方查询,原来在安装命令 mysql mysql-server 中默认已经替换安装了 mariadb ,老早就知道 mysql 改成 mariadb 的原因,没想到命令都直接改了,当时安装了没有注意看,只注意了安装完成就去启动,才出现之前的一幕,在后面查看命令记录确认了是安装的 mariadb,使用 systemctl start mariadb.service 还是启动不了,提示 Failed to start mariadb.service: Unit not found.,估计还是前面的命令问题,看起来是服务器没有安装完整,遂使用新的命令安装,yum install mariadb mariadb-server -y,安装后启动成功。使用 mysql_secure_installation 命令配置 mariadb 安全选项,一顿萌操作后,Thanks for using MariaDB!

安装 MariaDB

yum install mariadb mariadb-server -y #安装 mariadb

Installed:
  mariadb.x86_64 1:5.5.65-1.1.al7                                                              
  mariadb-server.x86_64 1:5.5.65-1.1.al7 

Dependency Updated:
  mariadb-libs.x86_64 1:5.5.65-1.1.al7  
  perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.1.al7           perl-Compress-Raw-Zlib.x86_64 1:2.06
  perl-DBD-MySQL.x86_64 0:4.023-6.1.al7                    perl-DBI.x86_64 0:1.627-4.1.al7     
  perl-Data-Dumper.x86_64 0:2.145-3.1.al7                  perl-IO-Compress.noarch 0:2.061-2.1.
  perl-Net-Daemon.noarch 0:0.48-5.1.al7                    perl-PlRPC.noarch 0:0.2020-14.1.al7 

Complete!
mysql_secure_installation # 配置安全选项

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): #初次配置无密码可直接回车,有密码输入密码回车
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y #是否设置 root 用户密码,输入 y 并回车或直接回车
New password: #设置 root 用户的密码
Re-enter new password: #再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y #是否删除匿名用户, 生产环境建议删除
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y #是否禁止 root 远程登录, 根据自己的需求选择 Y/n 并回车, 建议禁止
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] #是否删除 test 数据库, 直接回车
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] #是否重新加载权限表,直接回车
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB! #最后看到这个提示说明已经配置成功
service mariadb restart #重启 MariaDB //这是旧命令,可使用新命令显示操作详情
Redirecting to /bin/systemctl restart mariadb.service

https 配置(Let’s Encrypt)

wget https://dl.eff.org/certbot-auto #下载安装程序
--2020-06-05 19:41:31--  https://dl.eff.org/certbot-auto
Resolving dl.eff.org (dl.eff.org)... 151.101.228.201, 2a04:4e42:1a::201
Connecting to dl.eff.org (dl.eff.org)|151.101.228.201|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 79897 (78K) [application/octet-stream]
Saving to: ‘certbot-auto’

100%[=============================================================================================>] 79,897       240KB/s   in 0.3s   

2020-06-05 19:41:32 (240 KB/s) - ‘certbot-auto’ saved [79897/79897]
mv certbot-auto /certbot/ #移动安装程序到中意目录
chown root /certbot/certbot-auto #添加到组
chmod 0755 /certbot/certbot-auto #配置权限
/certbot/certbot-auto #安装证书程序
Bootstrapping dependencies for RedHat-based OSes... (you can skip this with --no-bootstrap)
yum is /usr/bin/yum
yum is hashed (/usr/bin/yum)
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package gcc-4.8.5-39.1.al7.x86_64 already installed and latest version
Package 1:openssl-1.0.2k-19.2.al7.x86_64 already installed and latest version
Package ca-certificates-2019.2.32-76.1.al7.noarch already installed and latest version
……
Install  9 Packages (+24 Dependent packages)
Upgrade             (  6 Dependent packages)

Total download size: 19 M
Is this ok [y/d/N]: y
……
Complete!
Creating virtual environment...
Installing Python packages...
Installation succeeded.
Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate and install certificates?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Apache Web Server plugin (apache)
2: Nginx Web Server plugin (nginx)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 #选择 apache 或 nginx 程序
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): it@hexingxing.cn #输入你常用的邮箱地址

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: a #接受协议或条款,必选 a

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: n #是否可以公开你的邮箱地址

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated) (Enter 'c' to cancel): //第一种情况:没有检测到域名配置文件,手动输入域名

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: ssl.hexingxing.cn //第二种情况,如果系统有配置文件,这里会显示你服务器已配置的域名列表
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): #选择你要创建证书的域名或者回车全选
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ssl.hexingxing.cn
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/nginx.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/nginx.conf #新版本默认重定向到 https

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://ssl.hexingxing.cn #恭喜! 您已成功启用 https://ssl.hexingxing.cn

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=ssl.hexingxing.cn #访问此链接测试你的 HTTPS 质量
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
 …… #此处省略了很多字,关于证书密钥文件的存放情况以及到期时间


   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le
{certbot 的绝对或相对路径}/certbot-auto renew --dry-run #测试手动模拟更新证书

数据内网迁移:使用 scp 命令快速传输

scp -r root@内网服务器 IP 地址:/被拷贝数据的目录或文件位置 /当前服务器的目录位置

这个功能很方便,连接成功后确认对方服务器身份以及输入密码后即可完成迁移,速度在 60MB/s 左右,但是只能针对静态数据,如果是网站还在运行,在迁移时网站产生的数据将会丢失或重复,建议在闲时停机操作。

php5.x.xx 升级 php7.x.xx

由于最新版本 Wordpess 需要较新版本 php,所以得把系统自带的 php 5.x.xx 手工升级,自带的 yum 源最新可用已经是 5.x.xx。

php -v #查看已安装的 php 版本
PHP 5.4.16 (cli) (built: Apr  2 2020 14:36:36) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
yum list installed |grep php #查看已安装的 php 程序条目
php.x86_64                            5.4.16-48.1.al7                  @updates 
php-bcmath.x86_64                     5.4.16-48.1.al7                  @updates 
php-cli.x86_64                        5.4.16-48.1.al7                  @updates 
php-common.x86_64                     5.4.16-48.1.al7                  @updates 
php-fedora-autoloader.noarch          1.0.1-2.el7                      @epel    
php-fpm.x86_64                        5.4.16-48.1.al7                  @updates 
php-gd.x86_64                         5.4.16-48.1.al7                  @updates 
php-mbstring.x86_64                   5.4.16-48.1.al7                  @updates 
php-mysql.x86_64                      5.4.16-48.1.al7                  @updates 
php-pdo.x86_64                        5.4.16-48.1.al7                  @updates 
php-php-gettext.noarch                1.0.12-1.el7                     @epel    
php-process.x86_64                    5.4.16-48.1.al7                  @updates 
php-tcpdf.noarch                      6.2.26-1.el7                     @epel    
php-tcpdf-dejavu-sans-fonts.noarch    6.2.26-1.el7                     @epel    
php-tidy.x86_64                       5.4.16-9.el7                     @epel    
php-xml.x86_64                        5.4.16-48.1.al7                  @updates 
phpMyAdmin.noarch                     4.4.15.10-4.el7                  @epel    
yum remove php* #删除所有旧版的 php 程序
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-bcmath.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-cli.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-common.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-fedora-autoloader.noarch 0:1.0.1-2.el7 will be erased
---> Package php-fpm.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-gd.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-mbstring.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-mysql.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-pdo.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-php-gettext.noarch 0:1.0.12-1.el7 will be erased
---> Package php-process.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package php-tcpdf.noarch 0:6.2.26-1.el7 will be erased
---> Package php-tcpdf-dejavu-sans-fonts.noarch 0:6.2.26-1.el7 will be erased
---> Package php-tidy.x86_64 0:5.4.16-9.el7 will be erased
---> Package php-xml.x86_64 0:5.4.16-48.1.al7 will be erased
---> Package phpMyAdmin.noarch 0:4.4.15.10-4.el7 will be erased
--> Finished Dependency Resolution

…… #这里省略很多过程细节

Complete!
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm #添加第三方 yum 包
Retrieving https://mirror.webtatic.com/yum/el7/epel-release.rpm
warning: /var/tmp/rpm-tmp.pHwGN8: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
	package epel-release-7-12.noarch (which is newer than epel-release-7-5.noarch) is already installed
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm #添加第三方 yum 包的 webtatic 库
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.yv8wmd: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
	package webtatic-release-7-3.noarch is already installed
yum list php72* #查看 php 可用安装版本包
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * webtatic: uk.repo.webtatic.com
Available Packages
php72w-bcmath.x86_64                                                     7.2.27-1.w7                                           webtatic
php72w-cli.x86_64                                                        7.2.27-1.w7                                           webtatic
php72w-common.x86_64                                                     7.2.27-1.w7                                           webtatic
php72w-dba.x86_64                                                        7.2.27-1.w7                                           webtatic
php72w-devel.x86_64                                                      7.2.27-1.w7                                           webtatic
php72w-embedded.x86_64                                                   7.2.27-1.w7                                           webtatic
php72w-enchant.x86_64                                                    7.2.27-1.w7                                           webtatic
php72w-fpm.x86_64                                                        7.2.27-1.w7                                           webtatic
php72w-gd.x86_64                                                         7.2.27-1.w7                                           webtatic
php72w-imap.x86_64                                                       7.2.27-1.w7                                           webtatic
php72w-interbase.x86_64                                                  7.2.27-1.w7                                           webtatic
php72w-intl.x86_64                                                       7.2.27-1.w7                                           webtatic
php72w-ldap.x86_64                                                       7.2.27-1.w7                                           webtatic
php72w-mbstring.x86_64                                                   7.2.27-1.w7                                           webtatic
php72w-mysql.x86_64                                                      7.2.27-1.w7                                           webtatic
php72w-mysqlnd.x86_64                                                    7.2.27-1.w7                                           webtatic
php72w-odbc.x86_64                                                       7.2.27-1.w7                                           webtatic
php72w-opcache.x86_64                                                    7.2.27-1.w7                                           webtatic
php72w-pdo.x86_64                                                        7.2.27-1.w7                                           webtatic
php72w-pdo_dblib.x86_64                                                  7.2.27-1.w7                                           webtatic
php72w-pear.noarch                                                       1:1.10.4-1.w7                                         webtatic
php72w-pecl-apcu.x86_64                                                  5.1.9-1.w7                                            webtatic
php72w-pecl-apcu-devel.x86_64                                            5.1.9-1.w7                                            webtatic
php72w-pecl-geoip.x86_64                                                 1.1.1-1.2.w7                                          webtatic
php72w-pecl-igbinary.x86_64                                              2.0.5-1.w7                                            webtatic
php72w-pecl-igbinary-devel.x86_64                                        2.0.5-1.w7                                            webtatic
php72w-pecl-imagick.x86_64                                               3.4.3-1.2.w7                                          webtatic
php72w-pecl-imagick-devel.x86_64                                         3.4.3-1.2.w7                                          webtatic
php72w-pecl-libsodium.x86_64                                             1.0.6-1.2.w7                                          webtatic
php72w-pecl-memcached.x86_64                                             3.0.4-1.w7                                            webtatic
php72w-pecl-mongodb.x86_64                                               1.5.3-1.w7                                            webtatic
php72w-pecl-redis.x86_64                                                 3.1.6-1.w7                                            webtatic
php72w-pecl-xdebug.x86_64                                                2.6.1-1.w7                                            webtatic
php72w-pgsql.x86_64                                                      7.2.27-1.w7                                           webtatic
php72w-phpdbg.x86_64                                                     7.2.27-1.w7                                           webtatic
php72w-process.x86_64                                                    7.2.27-1.w7                                           webtatic
php72w-pspell.x86_64                                                     7.2.27-1.w7                                           webtatic
php72w-recode.x86_64                                                     7.2.27-1.w7                                           webtatic
php72w-snmp.x86_64                                                       7.2.27-1.w7                                           webtatic
php72w-soap.x86_64                                                       7.2.27-1.w7                                           webtatic
php72w-sodium.x86_64                                                     7.2.27-1.w7                                           webtatic
php72w-tidy.x86_64                                                       7.2.27-1.w7                                           webtatic
php72w-xml.x86_64                                                        7.2.27-1.w7                                           webtatic
php72w-xmlrpc.x86_64                                                     7.2.27-1.w7                                           webtatic
yum install php72w php72w-opcache  php72w-xml  php72w-mcrypt   php72w-gd php72w-devel php72w-mysqlnd  php72w-intl    php72w-mbstring   php72w-pear  php72w-pdo  php72w-fpm #安装 php7.2.xx 及插件
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * webtatic: uk.repo.webtatic.com
No package php72w-mcrypt available.
Resolving Dependencies

…… #这里省略很多安装过程

Installed:
  mod_php72w.x86_64 0:7.2.27-1.w7             php72w-devel.x86_64 0:7.2.27-1.w7           php72w-fpm.x86_64 0:7.2.27-1.w7             
  php72w-gd.x86_64 0:7.2.27-1.w7              php72w-intl.x86_64 0:7.2.27-1.w7            php72w-mbstring.x86_64 0:7.2.27-1.w7        
  php72w-mysqlnd.x86_64 0:7.2.27-1.w7         php72w-opcache.x86_64 0:7.2.27-1.w7         php72w-pdo.x86_64 0:7.2.27-1.w7             
  php72w-pear.noarch 1:1.10.4-1.w7            php72w-xml.x86_64 0:7.2.27-1.w7            

Dependency Installed:
  autoconf.noarch 0:2.69-11.2.al7        automake.noarch 0:1.13.4-3.2.al7               libargon2.x86_64 0:20161029-3.el7             
  libicu.x86_64 0:50.2-4.1.al7           perl-Test-Harness.noarch 0:3.28-3.1.al7        perl-Thread-Queue.noarch 0:3.02-2.1.al7       
  php72w-cli.x86_64 0:7.2.27-1.w7        php72w-common.x86_64 0:7.2.27-1.w7             php72w-process.x86_64 0:7.2.27-1.w7           

Complete!
php -v #查看更新版本号
PHP 7.2.27 (cli) (built: Jan 26 2020 15:49:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.27, Copyright (c) 1999-2018, by Zend Technologies

完成 php7.x.xx 的安装。

配置 phpMyAdmin 管理数据库

cd /var/www/html #切换到 web 目录
wget https://files.phpmyadmin.net/phpMyAdmin/4.9.5/phpMyAdmin-4.9.5-all-languages.tar.gz #官网下载最新版 PMA
tar zxvf phpMyAdmin-4.9.5-all-languages.tar.gz #解压
mv phpMyAdmin-4.9.5-all-languages phpmyadminkadsfjkafdj #修改文件目录的名称

通过 https://myweb.com/phpmyadminkadsfjkafdj 访问管理数据库

导入数据库报错:没有接收到要导入的数据。

登录数据管理平台 phpMyAdmin 操作时,php 默认配置的上传文件大小是 2M,如果导入的数据库文件大于 2M 将会报错,提示 “没有接收到要导入的数据。可能是文件名没有提交,也可能是文件大小超出 PHP 限制。参见 FAQ 1.16。”,此时根据 FAQ 1.16 的文档指引,编辑 php.ini 文件,vi /etc/php.ini,编辑模式下搜索关键字段 /post_max_size,修改其值为 12M,搜索关键字段 /upload_max_filesize,修改其值为 10M,其中,该值 post_max_size 必须大于 upload_max_filesize,现在可以上传了。

以上官方文档即在自己服务器的 phpMyAdmin 目录下,https://yourdomain.com/phpMyAdmin-dirname/doc/html/faq.html#faq1-16

导入数据库报错:#1046 – No database selected

错误:MySQL 反回:#1046 – No database selected
原因:错误原因是因为导入时未选择 左侧数据库
解决方法:导入数据库正确操作顺序:点击左侧对应数据库名称(如:test)> 点击右侧顶部 “导入” 按钮。

导入 WordPress xml 数据

安装导入器插件时显示 “安装失败: 无法复制文件。 wordpress-importer/class-wp-import.php”,这个我有经验,因为 WordPress 程序没有权限创建文件,运行以下命令完成授权。

chown -R apache:apache worepress #apache 是 wordpress 程序用户名,wordpress 是程序所在目录名称

完成以上命令授权后,即可导入数据。

导入数据库和导入 WordPress 只选其一即可,不用两个都执行,否则会重复两份数据或内容重复,如果只有 WordPress 有使用数据库,建议使用 “导入 WordPress xml 数据” 方法导入即可,这样就不会出现多余数据库和无用数据,纯净的 WordPress 数据。

如果数据库还用于其他程序,那么先导入数据库,再导入 WordPress xml 数据,这样最终以 WordPress xml 的数据做最终更新,以此为最终版本数据。

如果是更换域名后导入那么可以在导入选项时勾选下载并导入附件,并保持原域名还可以正常访问,即可下载附件或导入到新的 WordPress。

如果是之前和现在更新的是同一个域名,那就无法下载附件并导入了,因为现在的域名指向的正是当前操作的 WordPress,所以从当前网站找附件是无法找到的,最好的方法就是从之前的 WordPress 目录通过之前说的内网 scp 方式或 ftp 方法将 “/wordpress/wp-content/uploads” 目录传输到当前 WordPress 程序对应目录下即可完成链接导入。

Easy Hide Login 插件事件

WordPress 迁移后,之前用的 Easy Hide Login 使用配置的方法不能登录了,遂通过 ftp 方式将插件先重命名,再通过默认的方式访问登录页面,登录进来后才发现原来默认的字段是 root,我当时有想过可能是恢复默认了,但是却没有想到是这个,现在想想也应该是这个,当时也没有查官方文档,所以就直接干脆重命名插件目录来解决。

Easy Hide Login
Slug Text :root
Login url demo: example.com?slug_text

原服务器全盘备份

其实这个标题有些过了,当时是想做全盘备份的,但想想也不是全部都要用,做全盘操作一来时间会比较久,二来即使备份好了,也不是全盘的数据以后都要用,所以还是选了备份自己确保可能后面要用的相关目录,其中包括实际数据和程序相关配置文件,方便以后参考。

  • 网站数据目录:/wwwroot
  • 网站数据备份目录:/wwwrootbackup
  • 数据库导出目录:/var/lib/phpMyAdmin/save/
  • NGINX 配置文件目录:/etc/nginx/

将通过 IP 地址访问的请求拦截或重定向

拦截到 404

#
# The default server
#

server {
    listen       80 default_server;
    #listen       [::]:80 default_server;
    server_name  _;
    #root         /usr/share/nginx/html;
    return 404; 

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

关键配置:return 404;

重定向到指定页面

#
# The default server
#

server {
    listen       80 default_server;
    #listen       [::]:80 default_server;
    server_name  _;
    #root         /usr/share/nginx/html;
    rewrite ^ https://yoursite.com$request_uri?;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

关键配置:rewrite ^ https://yoursite.com$request_uri?;

NSLookup 使用方法

NSLookup 可以指定查询的类型,可以查到 DNS 记录的生存时间还可以指定使用那个 DNS 服务器进行解释。

如何用本地计算机查询 DNS 记录?
打开命令提示符窗口 (开始– 运行— 输入 CMD– 回车)

nslookup 的语法为 nslookup –qt=类型 目标域名 (注意 qt 必须小写)

类型主要有:
A 地址记录 (Ipv4)
AAAA 地址记录(Ipv6)
CNAME 别名记录
HINFO 硬件配置记录,包括 CPU、操作系统信息
ISDN 域名对应的 ISDN 号码
MB 存放指定邮箱的服务器
MG 邮件组记录
MINFO 邮件组和邮箱的信息记录
MR 改名的邮箱记录
MX 邮件服务器记录
NS 名字服务器记录
PTR 反向记录
RP 负责人记录
SRV TCP 服务器信息记录
TXT 域名对应的文本信息
比如你要查询 baidu.com 的 MX 记录, 那在命令符提示窗口输入:nslookup -qt=mx baidu.com 则可以查到域名 baidu.com 的 mx 记录

如何使用指定 DNS 服务器查询?
语法为 nslookup -qt=类型 目标域名 指定的 DNS 服务器 IP 或域名

实际使用:

nslookup -qt=mx baidu.com 1.2.4.8


服务器:  public1.sdns.cn
Address:  1.2.4.8

非权威应答:
baidu.com       MX preference = 20, mail exchanger = mx1.baidu.com
baidu.com       MX preference = 10, mail exchanger = mx.maillb.baidu.com
baidu.com       MX preference = 20, mail exchanger = mx50.baidu.com
baidu.com       MX preference = 15, mail exchanger = mx.n.shifen.com
baidu.com       MX preference = 20, mail exchanger = jpmx.baidu.com

baidu.com       nameserver = ns2.baidu.com
baidu.com       nameserver = ns4.baidu.com
baidu.com       nameserver = ns3.baidu.com
baidu.com       nameserver = ns7.baidu.com
baidu.com       nameserver = dns.baidu.com
mx1.baidu.com   internet address = 220.181.3.85
mx1.baidu.com   internet address = 111.202.115.85
jpmx.baidu.com  internet address = 12.0.243.41
mx50.baidu.com  internet address = 180.76.13.18
dns.baidu.com   internet address = 202.108.22.220
ns2.baidu.com   internet address = 220.181.33.31
ns3.baidu.com   internet address = 112.80.248.64
ns4.baidu.com   internet address = 14.215.178.80
ns7.baidu.com   internet address = 180.76.76.92

删除 Linux 命令历史记录

1. 清除当前 Xshell 的历史纪录

  • 此操作只会当前 Xshell 或类似终端命令工具的历史记录(包含其他终端已输入的命令记录)
  • 键入命令:history -c

2. 彻底删除命令历史记录文件

  • Linux 中存放历史命令的文件是.bash_history,清空该文件 (echo > /root/.bash_history),历史命令就会彻底被清空。
  • 键入命令:echo > /root/.bash_history

3. 删除部分节点历史记录

  • 打开命令记录文件修改并保存实现删除部分记录
  • 键入命令:vim ~/.bash_history #删除所需记录后 :wd 退出;
  • 键入命令:history -r #重置并更新历史记录缓存文件。

Centos 7.x 防火墙管理

0、设置 firewall 开机自启

systemctl enable firewalld.service

 

1、查看 firewall 服务状态

systemctl status firewalld

 

2、查看 firewall 的状态

firewall-cmd --state

 

3、开启、重启、关闭、firewalld.service 服务
# 开启

service firewalld start

# 重启

service firewalld restart

# 关闭

service firewalld stop

 

4、查看防火墙规则

firewall-cmd --list-all 

 

5、查询、开放、关闭端口
# 查询端口是否开放

firewall-cmd --query-port=8080/tcp

# 开放 80 端口

firewall-cmd --permanent --add-port=80/tcp

# 移除端口

firewall-cmd --permanent --remove-port=8080/tcp

# 重启防火墙 (修改配置后要重启防火墙)

firewall-cmd --reload

 

ls – 列出文件或文件夹信息

列出当前目录的文件和文件夹

ls
bin   CloudResetPwdUpdateAgent  dev  home  lib64       media  opt   root  sbin  sys  usr
boot  CloudrResetPwdAgent       etc  lib   lost+found  mnt    proc  run   srv   tmp  var

 

查看目录所有档案及隐藏的文件,即"."和".."

ls -a
.   .autorelabel  boot                      CloudrResetPwdAgent  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
..  bin           CloudResetPwdUpdateAgent  dev                  home  lib64  media       opt  root  sbin  sys  usr

 

列出排除"."和".."以外的所有文件

ls -A
.autofsck     bin   data  etc   lib    lost+found  mnt  proc  run   selinux  sys  usr
.autorelabel  boot  dev   home  lib64  media       opt  root  sbin  srv      tmp  var

 

按最近修改排序显示文件

ls -lt
total 68
drwxr-xr-x. 77 root root  4096 Aug  8 20:10 etc
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
drwx------.  2 root root 16384 Feb 27 14:58 lost+found
drwxr-xr-x.  2 root root  4096 Apr 11  2018 media
drwxr-xr-x.  2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x.  2 root root  4096 Apr 11  2018 opt
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv

 

以列表的形式整齐的列出所有文件

ls -al
total 76
dr-xr-xr-x. 20 root root  4096 Aug  8 20:08 .
dr-xr-xr-x. 20 root root  4096 Aug  8 20:08 ..
-rw-r--r--   1 root root     0 Feb 27 15:09 .autorelabel
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
drwxr-xr-x. 77 root root  4096 Aug  8 20:20 etc
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
drwx------.  2 root root 16384 Feb 27 14:58 lost+found
drwxr-xr-x.  2 root root  4096 Apr 11  2018 media
drwxr-xr-x.  2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x.  2 root root  4096 Apr 11  2018 opt
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var

 

将当前或指定目录信息写入文件

ls -al > mydirectorylist.txt

 

递归列出子目录

ls -R /etc/nginx/
/etc/nginx/:
conf.d        fastcgi.conf.default    koi-utf     mime.types.default  scgi_params          uwsgi_params.default
default.d     fastcgi_params          koi-win     nginx.conf          scgi_params.default  win-utf
fastcgi.conf  fastcgi_params.default  mime.types  nginx.conf.default  uwsgi_params

/etc/nginx/conf.d:
default.conf  ssl.conf  virtual.conf

/etc/nginx/default.d:

 

以文件的大小进行排序

ls -S
lost+found  lib64  sbin  bin  boot  data  etc  home  lib  media  mnt  opt  root  run  selinux  srv  tmp  usr  var  dev  proc  sys

 

列出并区分文件和目录类型

ls -F 
bin@                       dev/   lib64@       opt/   sbin@  usr/
boot/                      etc/   lost+found/  proc/  srv/   var/
CloudResetPwdUpdateAgent/  home/  media/       root/  sys/
CloudrResetPwdAgent/       lib@   mnt/         run/   tmp/

// "@" 表示符号链接、"|" 表示 FIFOS、"/" 表示目录、"=" 表示套接字。

列出某个非当前目录的文件或文件夹

ls /boot
config-3.10.0-957.21.3.el7.x86_64
config-3.10.0-957.5.1.el7.x86_64
config-3.10.0-957.el7.x86_64
efi
grub
grub2
initramfs-0-rescue-4284cfe27c5b48c38adde30f33b4bb60.img
initramfs-3.10.0-957.21.3.el7.x86_64.img
initramfs-3.10.0-957.21.3.el7.x86_64kdump.img
initramfs-3.10.0-957.5.1.el7.x86_64.img
initramfs-3.10.0-957.5.1.el7.x86_64kdump.img
initramfs-3.10.0-957.el7.x86_64.img
symvers-3.10.0-957.21.3.el7.x86_64.gz
symvers-3.10.0-957.5.1.el7.x86_64.gz
symvers-3.10.0-957.el7.x86_64.gz
System.map-3.10.0-957.21.3.el7.x86_64
System.map-3.10.0-957.5.1.el7.x86_64
System.map-3.10.0-957.el7.x86_64
vmlinuz-0-rescue-4284cfe27c5b48c38adde30f33b4bb60
vmlinuz-3.10.0-957.21.3.el7.x86_64
vmlinuz-3.10.0-957.5.1.el7.x86_64
vmlinuz-3.10.0-957.el7.x86_64

//列出 boot 文件夹

当前目录搜索某个文件

ls lib*
lib:
binfmt.d   firmware  kdump       modules         rpm               systemd
cpp        games     kernel      modules-load.d  sendmail          tmpfiles.d
debug      gcc       locale      NetworkManager  sendmail.postfix  tuned
dracut     grub      lsb         polkit-1        sse2              udev
firewalld  kbd       modprobe.d  python2.7       sysctl.d          yum-plugins

lib64:
audit                         libmpc.so.3.0.0
cracklib_dict.hwm             libmpfr.so.4
cracklib_dict.pwd             libmpfr.so.4.1.1
cracklib_dict.pwi             libm.so
crt1.o                        libm.so.6
crti.o                        libncurses.so.5
...

//列出所有以 lib 开头的文件或文件夹

列出以.txt 结尾的文件

ls *.txt
test.txt

 

列出当前目录的文件和文件夹详细信息

ll
total 68
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
drwxr-xr-x. 77 root root  4096 Aug  8 20:10 etc
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
drwx------.  2 root root 16384 Feb 27 14:58 lost+found
drwxr-xr-x.  2 root root  4096 Apr 11  2018 media
drwxr-xr-x.  2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x.  2 root root  4096 Apr 11  2018 opt
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var 

//功能相同于 ls -l

按文件大小(以 KB、MB、GB 模式)显示文件

ls -lhS
total 68K
drwx------.  2 root root  16K Feb 27 14:58 lost+found
dr-xr-xr-x.  5 root root 4.0K Jun 24 10:17 boot
drwxr-xr-x   7 root root 4.0K Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root 4.0K Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x. 77 root root 4.0K Aug  8 20:10 etc
drwxr-xr-x.  3 root root 4.0K Aug  7 16:39 home
drwxr-xr-x.  2 root root 4.0K Apr 11  2018 media
drwxr-xr-x.  2 root root 4.0K Apr 11  2018 mnt
drwxr-xr-x.  2 root root 4.0K Apr 11  2018 opt
dr-xr-x---.  6 root root 4.0K Jun 24 10:39 root
drwxr-xr-x.  2 root root 4.0K Apr 11  2018 srv
drwxrwxrwt.  9 root root 4.0K Aug  8 03:36 tmp
drwxr-xr-x. 13 root root 4.0K Feb 27 14:58 usr
drwxr-xr-x. 19 root root 4.0K Feb 27 15:09 var
drwxr-xr-x  19 root root 3.0K Aug  7 15:09 dev
drwxr-xr-x  23 root root  640 Aug  7 16:43 run
lrwxrwxrwx.  1 root root    9 Feb 27 14:58 lib64 -> usr/lib64
lrwxrwxrwx.  1 root root    8 Feb 27 14:58 sbin -> usr/sbin
lrwxrwxrwx.  1 root root    7 Feb 27 14:58 bin -> usr/bin
lrwxrwxrwx.  1 root root    7 Feb 27 14:58 lib -> usr/lib
dr-xr-xr-x  89 root root    0 Aug  7 15:08 proc
dr-xr-xr-x  13 root root    0 Aug  7 15:12 sys

//功能相同于 ll -h

按修改时间排序

ls -lt
total 68
-rw-r--r--   1 root root     0 Aug  8 19:52 test.txt
drwxr-xr-x. 77 root root  4096 Aug  8 19:50 etc
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
drwx------.  2 root root 16384 Feb 27 14:58 lost+found
drwxr-xr-x.  2 root root  4096 Apr 11  2018 media
drwxr-xr-x.  2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x.  2 root root  4096 Apr 11  2018 opt
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv

 

按创建时间排序

ls -lc
total 68
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Jun 24 10:17 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x  19 root root  3040 Aug  7 15:09 dev
drwxr-xr-x. 77 root root  4096 Aug  8 19:50 etc
drwxr-xr-x.  3 root root  4096 Aug  7 16:39 home
lrwxrwxrwx.  1 root root     7 Feb 27 14:58 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Feb 27 14:58 lib64 -> usr/lib64
drwx------.  2 root root 16384 Feb 27 14:58 lost+found
drwxr-xr-x.  2 root root  4096 Feb 27 14:58 media
drwxr-xr-x.  2 root root  4096 Feb 27 14:58 mnt
drwxr-xr-x.  2 root root  4096 Feb 27 14:58 opt
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Jun 24 10:39 root
drwxr-xr-x  23 root root   640 Aug  7 16:43 run
lrwxrwxrwx.  1 root root     8 Feb 27 14:58 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Feb 27 14:58 srv
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
-rw-r--r--   1 root root     0 Aug  8 19:52 test.txt
drwxrwxrwt.  9 root root  4096 Aug  8 03:36 tmp
drwxr-xr-x. 13 root root  4096 Feb 27 14:58 usr
drwxr-xr-x. 19 root root  4096 Feb 27 15:09 var

 

按访问时间排序

ls -lu
total 68
lrwxrwxrwx.  1 root root     7 Aug  8 16:01 bin -> usr/bin
dr-xr-xr-x.  5 root root  4096 Aug  8 19:47 boot
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudResetPwdUpdateAgent
drwxr-xr-x   7 root root  4096 Jun  3 14:40 CloudrResetPwdAgent
drwxr-xr-x  19 root root  3040 Aug  8 19:47 dev
drwxr-xr-x. 77 root root  4096 Aug  7 18:10 etc
drwxr-xr-x.  3 root root  4096 Aug  8 19:47 home
lrwxrwxrwx.  1 root root     7 Aug  8 19:25 lib -> usr/lib
lrwxrwxrwx.  1 root root     9 Aug  8 15:24 lib64 -> usr/lib64
drwx------.  2 root root 16384 Feb 27 14:58 lost+found
drwxr-xr-x.  2 root root  4096 Apr 11  2018 media
drwxr-xr-x.  2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x.  2 root root  4096 Aug  7 18:10 opt
dr-xr-xr-x  89 root root     0 Aug  7 15:08 proc
dr-xr-x---.  6 root root  4096 Aug  8 19:25 root
drwxr-xr-x  23 root root   640 Aug  7 15:08 run
lrwxrwxrwx.  1 root root     8 Aug  8 16:01 sbin -> usr/sbin
drwxr-xr-x.  2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Aug  7 15:12 sys
-rw-r--r--   1 root root     0 Aug  8 19:52 test.txt
drwxrwxrwt.  9 root root  4096 Jun 24 10:39 tmp
drwxr-xr-x. 13 root root  4096 Aug  8 19:26 usr
drwxr-xr-x. 19 root root  4096 Apr 11  2018 var

 

追加 r 为反序排序,追加 a 为显示隐藏文件

CentOS 6.8 Nginx 配置文件详解

Nginx 配置文件:/etc/nginx/nginx.conf

#定义 nginx 运行的用户和用户组
user  www www;
 
#设置 nginx 进程数,一般设置为 cpu 核心数,auto 为自动检测
worker_processes  auto;
 
#全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
 
#守护进程 pid 文件
pid        logs/nginx.pid;
 
#events 模块中包含 nginx 中所有处理连接的设置
events {
    #单个进程最大连接数(最大连接数=连接数*进程数)
    worker_connections  2048;
    #设置 nginx 收到一个新链接通知后接受尽可能多的链接
    multi_accept on;
    #设置用于复用客户端线程的轮训方法
    use epoll;
}
 
#http 模块控制着 nginx http 处理的所有核心特性
http {
    #文件扩展名与文件类型映射表
    include       mime.types;
 
    #默认文件类型
    default_type  application/octet-stream;
 
    #打开或关闭错误页面中的 nginx 版本号 deng
    server_tokens on;
 
    #设置 nginx 是否存储访问日志,关闭这个可以让读取磁盘 IO 操作更快
    access_log on;
 
    #服务器名字的 hash 表大小
    #保存服务器名字的 hash 表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size
    #所控制的。参数 hash bucket size 总是等于 hash 表的大小,并且是一路处理器缓存大小的倍数。
    #在减少了在内存中的存取次数后,使在处理器中加速查找 hash 表键值成为可能。
    #如果 hash bucket size 等于一路处理器缓存的大小,那么在查找键的时候,
    #最坏的情况下在内存中查找的次数为 2。第一次是确定存储单元的地址,第二次是在存储单元中查找键 值。
    #因此,如果 Nginx 给出需要增大 hash max size 或 hash bucket size 的提示,
    #那么首要的是增大前一个参数的大小.
    server_names_hash_bucket_size 128;
 
    #客户请求头缓冲大小。nginx 默认会用 client_header_buffer_size 这个 buffer 来读取 header 值,
    #如果 header 过大,它会使用 large_client_header_buffers 来读取。
    large_client_header_buffers 4 64k;
 
    #设定通过 nginx 上传文件的大小
    client_max_body_size 8M;
 
    #缓冲区代理缓冲用户端请求的最大字节数,
    #如果把它设置为比较大的数值,例如 256k,那么,无论使用 firefox 还是 IE 浏览器,
    #来提交任意小于 256k 的图片,都很正常。如果注释该指令,使用默认的 client_body_buffer_size 设置,
    #也就是操作系统页面大小的两倍,8k 或者 16k,问题就出现了。
    
    client_body_buffer_size 128k;
 
    #开启高效文件传输模式,优化磁盘 IO 设置
    sendfile        on;
 
    #设置 nginx 在一个数据包里发送所有头文件,而不是一个接一个的发送
    tcp_nopush     on;
 
    # HTTP1.1 支持持久连接 alive
    # 降低每个连接的 alive 时间可在一定程度上提高可响应连接数量,所以一般可适当降低此值
    keepalive_timeout  60;
 
    #设置代理服务器(nginx)保存用户头信息的缓冲区大小
    #设置从被代理服务器读取的第一部分应答的缓冲区大小,通常情况下这部分应答中包含一个小的应答头,
    #默认情况下这个值的大小为指令 proxy_buffers 中指定的一个缓冲区的大小,不过可以将其设置为更小
    proxy_buffer_size 4k;
 
    #proxy_buffers 缓冲区,网页平均在 32k 以下的设置
    #设置用于读取应答(来自被代理服务器)的缓冲区数目和大小,默认情况也为分页大小,
    #根据操作系统的不同可能是 4k 或者 8k
    proxy_buffers 4 32k;
 
    #高负荷下缓冲大小(proxy_buffers*2)
    proxy_busy_buffers_size 64k;
 
    #设置在写入 proxy_temp_path 时数据的大小,预防一个工作进程在传递文件时阻塞太长
    #设定缓存文件夹大小,大于这个值,将从 upstream 服务器传
    proxy_temp_file_write_size 64k;
 
    gzip  on;
    #加 vary 给代理服务器使用,针对有的浏览器支持压缩,有个不支持,
    #根据客户端的 HTTP 头来判断是否需要压缩
    #gzip_vary on;
 
    # 过短的内容压缩效果不佳,压缩过程还会浪费系统资源
    gzip_min_length 1000;
 
    #允许或禁止压缩基于请求和相应的响应流,any 代表压缩所有请求
    gzip_proxied any;
 
    #==设置数据压缩等级,1-9 之间,9 最慢压缩比最大
    gzip_comp_level 9;
 
    #设置需要压缩的数据格式
    gzip_types text/plain text/css text/xml text/javascript application/json 
    application/x-javascript application/xml application/xml+rss;
 
    # 静态文件缓存
    # 最大缓存数量,文件未使用存活期
    open_file_cache max=65535 inactive=20s;
    # 验证缓存有效期时间间隔
    open_file_cache_valid 30s;
    # 有效期内文件最少使用次数
    open_file_cache_min_uses 3;
 
    #虚拟主机配置
    server {
        listen       80;
 
        #多域名用空格隔开
        server_name  localhost zixuephp.net www.zixuephp.net;
 
        #设置默认访问首页
        index index.php index.html;
 
        #默认编码
        charset utf-8;
 
 
        #定义本虚拟主机的访问日志
        access_log  logs/access.log;
 
        #错误也设置
        error_page   500 502 503 504  /404.html;
        location = /404.html {
            root   html;
        }
 
        #图片缓存
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
            expires       7d;
        }
 
 
        #网站伪静态
        location / {
            rewrite "^/index.html$" /index.php last;
            rewrite "^/iphp.html$" /iphp.php last;
            rewrite "^/login.html$" /login.php last;
            rewrite "^/post.html$" /post.php last;
            rewrite "^/article.html$" /article.php last;
            rewrite "^/article-([0-9]+).html$" /article.php?aid=$1 last;
            rewrite "^/iphp-([0-9]+)-([0-9]+).html$" /iphp.php?mid=$1&cid=$2 last;
            rewrite "^/iphp-([0-9]+)-page([0-9]+).html$" /iphp.php?mid=$1&page=$2;
            rewrite "^/iphp-c([0-9]+)-page([0-9]+).html$" /iphp.php?cid=$1&page=$2;
            rewrite "^/search.html$" /search.php;
        }
 
 
        #nginx 解析 php 脚本
        location ~ .php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
            index          index.php index.html;
 
        }
    }
 
}