# Server 01
# Network
Device | Hostname | System | FQDN | IP Adress | Service |
---|---|---|---|---|---|
Server01 | Server01 | Linux server | Server01.sdskills.com | 172.16.100.201 | RAID5、DNS(bind) Webserver(apache) SSH、DBMS |
修改 /etc/network/interfaces
文件,增加如下语句
auto ens36
iface ens35 inet static
address 172.16.100.201/25
gateway 172.16.100.254
2
3
4
环境不同,网卡号不同,根据环境修改,使用命令 ip link 可以查看
修改 /etc/hosts
文件,将 127.0.0.1 debain
修改为如下语句
127.0.0.1 Server01
172.16.100.201 Server01.sdskills.com Server01
2
修改 /etc/hostname
文件,将内容改为对应主机名
Server01
新建 /etc/resolv.conf
文件,添加如下内容
nameserver 172.16.100.201
# DISK
在虚拟机上添加 4 个 1G 的硬盘
- 创建 raid5,其中一个作为热备盘,设备名为 md0
- 将 md0 设置为 LVM,设备为/dev/vg01/lg01
- 格式化为 ext4 文件系统
- 开机自动挂载到 /data 目录
安装 mdadm
软件
apt install -y mdadm
检查硬盘
root@Server01:~# fdisk -l | grep /dev/sd
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
/dev/sda1 * 2048 102762495 102760448 49G 83 Linux
/dev/sda2 102764542 104855551 2091010 1021M 5 Extended
/dev/sda5 102764544 104855551 2091008 1021M 82 Linux swap / Solaris
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 sectors
Disk /dev/sdd: 1 GiB, 1073741824 bytes, 2097152 sectors
Disk /dev/sde: 1 GiB, 1073741824 bytes, 2097152 sectors
Disk /dev/sdc: 1 GiB, 1073741824 bytes, 2097152 sectors
2
3
4
5
6
7
8
9
创建 raid5 热备
mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sd[b-e]
安装逻辑卷管理工具
apt install -y lvm2
创建卷组与逻辑卷
vgcreate /dev/vg01 /dev/md0
lvcreate -l 510 -n lv01 /dev/vg01
lvcreate -L 1G -n lv01 /dev/vg01
2
3
格式化
mkfs.ext4 /dev/vg01/lv01
创建挂载目录
mkdir /data
编辑 /etc/fstab
文件实现开机自动挂载
/dev/vg01/lv01 /data ext4 defaults 0 0
执行挂载
mount -a
# DNS(bind)
安装 bind 服务
apt install -y bind9
建立 sdskills 域,为所有的出 Internet 区域的主机或服务器建立正\反的域名解析 当出现无法解析的域名时,向域 skills.com 申请跟高层次的解析
修改 /etc/bind/named.conf.options
文件,取消第 13 - 15 行并根据需求修改
options {
forwarders {
192.168.10.4;
};
allow-recursion { any; };
allow-query-cache { any; };
allow-query { any; };
dnssec-validation no;
dnssec-enable no;
};
2
3
4
5
6
7
8
9
10
编辑 /etc/bind/named.conf.default-zones
文件,创建域
zone "sdskills.com" {
type master;
file "/etc/bind/db.sdskills.com";
};
zone "100.16.172.in-addr.arpa" {
type master;
file "/etc/bind/db.172.16.100";
};
2
3
4
5
6
7
8
9
复制 local 域数据库文件,并修改
cp /etc/bind/db.local /etc/bind/db.sdskills.com
cp /etc/bind/db.127 /etc/bind/db.172.16.100
2
db.sdskills.com:
@ IN SOA sdskills.com. ns.sdskills.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.sdskills.com.
ns IN A 172.16.100.201
www IN A 172.16.100.201
mail IN A 172.16.100.202
* IN A 172.16.100.201
2
3
4
5
6
7
8
9
10
11
12
db.172.16.100:
$TTL 604800
@ IN SOA sdskills.com. ns.sdskills.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.sdskills.com.
201 IN PTR ns.sdskills.com.
201 IN PTR www.sdskills.com.
202 IN PTR mail.sdskills.com.
2
3
4
5
6
7
8
9
10
11
12
# Webserver(apache)
安装 apache 服务
- 由 Server01 提供 www.sdskills.com
apt install -y apache2
使用 apache 服务
- 网页文件放在 /data/share/htdocs/skills
- 服务以用户 webuser 运行
- 首页内容为 “This is the front page of sdskills's website.”
- /htdocs/skills/staff.html 内容为 “Staff Information”
- 该页面需要员工的账号 Basic 认证才能访问
- 员工账号存储在文件 /etc/apache2/.htpasswd 中,账号为 zsuser、lsus
创建网页文件目录
mkdir -p /data/share/htdocs/skills
修改内容
echo "This is the front page of sdskills's website." > /data/share/htdocs/skills/index.html
echo "Staff Information" > /data/share/htdocs/skills/staff.html
2
创建 webuser 用户
useradd webuser
修改 /etc/apache2/apache2.conf
文件的第 115、116行
User webuser
Group webuser
2
创建认证用户
htpasswd -c /etc/apache2/.htpasswd zsuser
htpasswd /etc/apache2/.htpasswd lsus
2
修改 /etc/apache2/apache2.conf
文件,配置站点路径,将/var/www
修改为/data/share/htdocs/skills
<Directory /data/share/htdocs/skills>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /data/share/htdocs/skills/staff.html>
authtype basic
authname "passoword"
authuserfile /etc/apache2/.htpasswd
Require valid-user
</Directory>
2
3
4
5
6
7
8
9
10
11
将 /etc/apache2/apache2.conf
文件中第 202 - 204 行修改为如下语句
<FilesMatch "^\.ht">
Require all granted
</FilesMatch>
2
3
修改 /etc/apache2/sites-enabled/000-default.conf
配置虚拟主机,取消第 9 行注释
ServerAlias *.sdskills.com
ServerName www.sdskills.com
ServerAdmin webmaster@localhost
DocumentRoot /data/share/htdocs/skills
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/%1 [L,R=301]
2
3
4
5
6
7
8
网站使用 https 协议
- SSL 使用 Rserver 颁发的证书,颁发给: C = CN ST = China L = ShanDong O = skills OU = Operations Departments CN = *.sdskills.com
- Server01 的证书路径:/CA/cacert.pem
- 签发数字证书,颁发者: C = CN O = Inc OU = www.sdskills.com CN = skills Global Root CA
- 客户端访问 https 时应无浏览器(含终端)安全警告信息
- 当用户使用 http 访问时自动跳转到 https 安全协议
- 当用户使用 sdskills.com 或 any.sdskills.com(any 代表任意网址前缀)访问时,自动跳转到 www.sdskills.com
复制 SSL 虚拟主机配置文件
cp -a /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/001-default.conf
编辑 /etc/apache2/sites-enabled/001-default.conf
文件
ServerAdmin webmaster@localhost
ServerName www.sdskills.com
DocumentRoot /data/share/htdocs/skills
ServerAlias *.skills.com
SSLCertificateFile /CA/sdskills.crt
SSLCertificateKeyFile /CA/sdskills.key
SSLCertificateChainFile /CA/cacert.pem
2
3
4
5
6
7
8
9
新建 /data/share/htdocs/skills/.htaccess
文件,并添加如下内容
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.sdskills.com [L,NE,R=301]
2
3
4
创建 CA 文件夹,并进入该文件夹
mkdir /CA && cd /CA
生成 SSL 证书密钥
openssl genrsa -out sdskills.key 4096
生成 SSL 证书请求
root@Server01:/CA# openssl req -new -key sdskills.key -out sdskills.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:China
Locality Name (eg, city) []:ShangDong
Organization Name (eg, company) [Internet Widgits Pty Ltd]:skills
Organizational Unit Name (eg, section) []:Operations Departments
Common Name (e.g. server FQDN or YOUR name) []:*.sdskills.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
通过 SCP 将证书请求上传至 Rserver
scp sdskills.csr 172.16.100.254:/CA
如下操作在 Rserver 上操作
# 签发证书
openssl x509 -req -in sdskills.csr -CA /CA/cacert.pem -CAkey /CA/private/cakey.pem -CAcreateserial -out sdskills.crt
# 通过 SCP 将证书上传至 Server01
scp sdskills.crt 172.16.100.201:/CA
scp cacert.pem 172.16.100.201:/CA
2
3
4
5
在 Server01 上启动 apache 重写及SSL模块
a2enmod rewrite
a2enmod ssl
2
重启 apache2
systemctl restart apache2
# SSH
安装 SSH
仅允许 client 客户端进行 ssh 访问,其余所有主机的请求都应该拒绝
配置 client 只能在 a1 用户环境下可以免密钥登录,端口号为 1122,并有用 root 控制权限
安装 SSH
apt install -y openssh-server
编辑 /etc/ssh/sshd_config
文件,修改至如下内容
Port 1122
PermitRootLogin yes
AllowUsers *@10.10.100.*
2
3
如下操作在 Client
上用户 a1
上进行
ssh-keygen
ssh-copy-id root@172.16.100.201 -p 1122
2
# DBMS(MariaDB)
在 Server01 上完成 MariaDB 数据库的安装,添加数据库 root 用户密码为 Skill21! 安装 MariaDB 数据库服务器组件 MariaDB 数据库管理员信息:User:root/ Password:Skill21!
安装 MariaDB 数据库服务器组件
apt install -y mariadb-server
进入数据库
mysql -uroot -p
# 直接回车即可
2
修改 root 密码
MariaDB[(none)]> use mysql;
MariaDB[mysql]> update user set password=password("Skill21!") where user='root';
MariaDB[mysql]> update user set plugin='' where user='root';
2
3
数据库刷新权限
MariaDB[mysql]> flush privileges;
退出数据库
MariaDB[mysql]> exit;
安装 MariaDB WEB 管理面板 “phpMyAdmin”,通过 apache 进行发布 安装 phpMyAdmin,MariaDB 的 web 管理面板组件 安装 apache,配置 php 环境,用于发布 phpMyAdmin
安装php
apt install -y php php-mysql
通过软件将 phpMyAdmin 文件夹上传至 Server01 的/data/share/htdocs/skills
目录下
root@Server01:/data/share/htdocs/skills# ls
index.html phpmyadmin staff.html
2