月度归档:2018年02月

利用Apache htaccess文件创建密码保护网站隐私目录

在生产环境中,各种各样的网站目录限制场景非常之多,这时就可能需要用到Apache htpasswd工具来实现,下面我将一一讲解如何使用。

先使用Apache htpasswd命令创建一个密码文件,htpasswd的命令用法如下:

-c # 创建密码文件,若该文件已存在,它会重写并删除原有内容;
-n # 不更新密码文件,直接显示密码;
-m # 使用MD5加密(默认);
-d # 使用CRYPT加密(默认);
-p # 使用普通文本格式的密码;
-s # 使用SHA加密;
-b # 命令行中一并输入用户和密码,而交互性,生成时可见密码明文;
-D # 删除指定的用户;

创建添加一个用户名为:renwole 密码为:renwole 的密码文件:

$ htpasswd -c .accpasswd renwole
New password:
Re-type new password:
Adding password for user renwole

注意:创建的密码 .accpasswd 文件名可自定义。

使用cat查看生成的内容:

$ cat .accpasswd
renwole:$apr1$4owQhqtn$ElCDIh0sfR.ZFzeaY9sDw0

注意:生成的密码是已经加密过的,所以别弄混掉了。

添加多个账号:

$ htpasswd -b .accpasswd renwolecom password-renwolecom
Adding password for user renwolecom

查看生成的多个账号和密码:

$ cat .accpasswd
renwole:$apr1$4owQhqtn$ElCDIh0sfR.ZFzeaY9sDw0
renwolecom:$apr1$3zzGmKtR$jKKCbU2nVEQZFz9mtEXE./

删除用户:

$ htpasswd -D .accpasswd renwolecom
Deleting password for user renwolecom

查看删除后的密码文件:

$ cat .accpasswd
renwole:$apr1$4owQhqtn$ElCDIh0sfR.ZFzeaY9sDw0

创建密码保护区域

有了密码文件之后,我们可以使用.htaccess文件创建保护区域。

将以下内容保存为 .htaccess 文件,这样我们就可以使用该文件建立保护区域。

$ vim /apps/web/renwolecom/phpMyadmin/.htaccess

AuthType Basic
AuthName "restricted area"
AuthUserFile /usr/local/apache/conf/.accpasswd
require valid-user

将该文件放在需要保护的目录下即可。因此我放在了网站根目录的phpMyadmin目录,这样访问此目录,就会出现弹窗验证,输入生成的用户名和密码即可。

SQL Server 2008 R2 评估期过期 安装序列号

以下序列号支持安装使用,关于评估过期,具体操作如下:

配置工具-安装中心-安装-维护-版本升级-填入序列号即可。

亲测99.9999有效。

数据中心版32位:PTTFM-X467G-P7RH2-3Q6CG-4DMYB
数据中心版64位:DDT3B-8W62X-P9JD6-8MX7M-HWK38

CentOS Linux 7.7 1908 x86 64 ISO 官方原版镜像下载

适用于 x86_64 架构:
CentOS-7-x86_64-DVD-1908.iso                       11-Sep-2019 18:51      4G
CentOS-7-x86_64-DVD-1908.torrent                   17-Sep-2019 12:39     87K
CentOS-7-x86_64-Everything-1908.iso                09-Sep-2019 19:09     10G
CentOS-7-x86_64-Everything-1908.torrent            17-Sep-2019 12:38    103K
CentOS-7-x86_64-LiveGNOME-1908.iso                 16-Sep-2019 18:57      1G
CentOS-7-x86_64-LiveGNOME-1908.torrent             17-Sep-2019 12:39     29K
CentOS-7-x86_64-LiveKDE-1908.iso                   16-Sep-2019 19:27      2G
CentOS-7-x86_64-LiveKDE-1908.torrent               17-Sep-2019 12:39     38K
CentOS-7-x86_64-Minimal-1908.iso                   11-Sep-2019 19:04    942M
CentOS-7-x86_64-Minimal-1908.torrent               17-Sep-2019 12:39     37K
CentOS-7-x86_64-NetInstall-1908.iso                06-Sep-2019 11:49    552M
CentOS-7-x86_64-NetInstall-1908.torrent            17-Sep-2019 12:39     22K
版本说明:

DVD:        # 标准安装镜像,一般常用。
Minimal:    # 最小安装镜像,自带的软件最少。
Everything: # 标准的基础上集成所有软件,镜像最大。
NetInstall: # 网络安装镜像,包小,但需联网才能安装。
更多版本请参阅下载 CentOS ISO》。

如何使用Lsyncd复制并实时同步到远程服务器

何为Lsyncd?

Lsyncd 官网 //axkibe.github.io/

Lsyncd监视本地目录树事件监视器接口(inotify或fsevents)。它聚合并将事件组合在一起几秒钟,然后生成一个(或多个)进程来同步这些更改。默认情况下,由rsync实现同步。因此,Lsyncd是一种轻量级的实时镜像解决方案,相对容易安装,不需要新的文件系统或块设备,也不会妨碍本地文件系统的性能。

Rsync+ssh是一种高级操作配置,它使用ssh来执行文件和目录直接在目标上移动,而不是在线路上重新传输移动目标。细粒度的定制可以通过配置文件实现。自定义动作configs甚至可以从头编写,从shell脚本到Lua语言编写的代码。这种方法简单,强大,灵活的配置可以被解决。

Lsyncd 2.2.2要求在所有源和目标机器上rsync >= 3.1

系统环境:

RenwoleServer:10.28.204.65 服务端
RenwoleClient:10.28.204.66 客户端
OS:CentOS Linux release 7.4.1708 (Core) x64

1.rsync的安装

请参阅:《CentOS 7配置Rsync数据文件同步服务器》。

2.安装扩展依赖包

$ yum install -y gcc gcc-c++ lua lua-devel cmake libxml2 libxml2-devel

3.源代码编译安装lsyncd

$ wget //github.com/axkibe/lsyncd/archive/release-2.2.2.tar.gz
$ tar xvf release-2.2.2.tar.gz
$ cd lsyncd-release-2.2.2
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lsyncd
$ make && make install
$ ln -s /usr/local/lsyncd/bin/lsyncd /usr/bin/lsyncd

安装过程可能报错:

-- Configuring incomplete, errors occurred!

安装lua-devel即可。

4.设置无密码SSH登录

因为这里使用rsyncssh进行同步,所以还需要配置root账号无密码ssh登录。详细配置请参阅:

如何在Linux中设置SSH无密码登录

5.配置lsyncd

以下是三种常用配置案例

1.远程同步rsyncssh模式配置方案:

$ vim /etc/lsyncd.conf
settings {
    logfile = "/var/log/lsyncd.log",          --日志路径
    statusFile = "/var/log/lsyncd.status",    --状态文件
    pidfile = "/var/run/lsyncd.pid",          --pid文件路径
    statusInterval = 1,                       --状态文件写入最短时间
    nodaemon = false,                         --daemon运行
    maxProcesses = 1,                         --最大进程
    maxDelays = 1,                            --最大延迟
}
sync {
    default.rsyncssh,      --默认rsync+ssh,rsync版本需要升级3以上版本
    source = "/apps/www/renwoleblog/",        --源目录
    delete = true,                            --保持完全同步        
    host = "root@10.28.204.66",         
    targetdir = "/apps/www/renwoleblog/bak/", --目标目录
    exclude={                 
             ".txt"            --需排除的文件
    },
rsync = {
    binary = "/usr/bin/rsync", --需先安装好rsync
    archive = true,            --归档
    compress = false,          --压缩
    owner = true,              --属主
    perms = true,              --权限
    whole_file = false
    },
ssh = {
    port = 22
    }
}

2.本地目录同步配置方案:

sync {
    default.rsync,
    source = "/apps/www/renwoleblog/",
    target = "/apps/www/renwoleblog/bak/",
}

3.远程同步rsync-daemon模式配置方案

sync {
    default.rsync,
    source    = "/apps/www/renwoleblog/",
    target    = "renwole@10.28.204.65::renwolecom",
    delete="true",
    exclude = { ".bak*" },
    delay = 30,
    init = false,
    rsync = {
    binary = "/usr/bin/rsync",
    archive = true,
    compress = true,
    verbose   = true,
    perms = true,
    password_file = "/etc/rsync.password",
    _extra    = {"--bwlimit=200"}
    }
}

重点参数说明:

--        # 注释符
settings  # 是全局配置
sync      # 定义同步参数
rsync     # 定义同步文件参数
ssh       # 定义服务器远程端口

lsyncd配置文件允许多个sync互不影响。

说明:如果是一对多,请参阅本地同步,修改目标目录即可。

6.创建systemctl系统单元文件

为了实现systemctl进行管理,请创建配置文件以及脚本启动文件,命令如下:

$ vim /etc/sysconfig/lsyncd

添加如下内容:

LSYNCD_OPTIONS="/etc/lsyncd.conf"

创建启动文件:

$ vim /usr/lib/systemd/system/lsyncd.service

添加如下内容:

[Unit]
Description=Live Syncing (Mirror) Daemon
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/lsyncd
ExecStart=/usr/local/lsyncd/bin/lsyncd -nodaemon $LSYNCD_OPTIONS

[Install]
WantedBy=multi-user.target

7.启动lsyncd并加入开机自启动

$ systemctl start lsyncd
$ systemctl enable lsyncd

接下来你就可以往源服务器/apps/www/renwoleblog/内上传任意文件,完成后立刻就会同步到客户端 10.28.204.66 /apps/www/renwoleblog/bak/目录内,也可以查看服务端的lsyncd日志文件分析是否同步成功。例如:

[root@RenwoleServer ~] $ cat /var/log/lsyncd.log
...
Fri Dec 22 01:19:22 2017 Normal: Calling rsync with filter-list of new/modified files/dirs
/PCHunter_renwole.com.tar.gz
/
Fri Dec 22 01:19:24 2017 Normal: Finished (list): 0
Fri Dec 22 01:19:32 2017 Normal: Calling rsync with filter-list of new/modified files/dirs
/PCHunter_renwole.com.tar.gz
/
Fri Dec 22 01:19:34 2017 Normal: Finished (list): 0
Fri Dec 22 01:19:34 2017 Normal: Calling rsync with filter-list of new/modified files/dirs
/PCHunter_renwole.com.tar.gz
/
Fri Dec 22 01:19:36 2017 Normal: Finished (list): 0

日志内容显示PCHunter_renwole.com.rar文件成功同步。

另外lsyncd是基于inotify + rsync的开源同步软件,相对于其他同步软件更加安全可靠,占用资源更少,但配置略麻烦。
lsyncd 还支持当监控到某个指定事件时就执行什么样的命令,由于是通过时间延迟和累计事件命中次数来触发同步,在设计上要优于inotify,另外他的同步速度完全取决于你的网络质量。