第十周-2022-01-28

1、在阿里云服务器搭建openv-p-n

openvpn服务器(centos7):172.16.140.88
web服务器:172.16.200.153
配置安全组,允许外网访问openvpn服务器的tcp1194端口

#安装openvpn
[root@openvpn ~]# yum -y install openvpn

#安装证书管理工具
[root@openvpn ~]# yum -y install easy-rsa

#生成服务器配置文件
[root@openvpn ~]# cp /usr/share/doc/openvpn-2.4.11/sample/sample-config-files/server.conf /etc/openvpn/

#准备证书签发相关文件
[root@openvpn ~]# cp -r /usr/share/easy-rsa/ /etc/openvpn/easy-rsa-server

#准备签发证书相关变量的配置文件
[root@openvpn ~]# cp /usr/share/doc/easy-rsa-3.0.8/vars.example /etc/openvpn/easy-rsa-server/3/vars

#修改给CA和OpenVPN服务器颁发的证书的有效期
[root@openvpn ~]# vim /etc/openvpn/easy-rsa-server/3/vars
#CA的证书有效期为1年,可以适当延长
set_var EASYRSA_CA_EXPIRE 36500
#服务器证书默认为825天,可适当加长
set_var EASYRSA_CERT_EXPIRE 3650

#初始化PKI和CA签发机构环境
[root@openvpn ~]# cd /etc/openvpn/easy-rsa-server/3/
#初始化数据,在当前目录下生成pki目录及相关文件
[root@openvpn 3]# ./easyrsa init-pki
#创建CA机构
[root@openvpn 3]# ./easyrsa build-ca nopass
回车将使用默认名证书名
#查看证书
[root@openvpn 3]# openssl x509 -in pki/ca.crt -noout -text

#创建服务器证书申请文件,其中server是文件前缀,完成后生成server.key和server.req
[root@openvpn 3]# ./easyrsa gen-req server nopass
Common Name (eg: your user, host, or server name) [server]:openvpn
#颁发服务端证书
#第一个server指类型,第二个server指server.req
[root@openvpn 3]# ./easyrsa sign server server
  Confirm request details: yes

#创建Diffie-Hellman密钥
[root@openvpn 3]# ./esayrsa gen-dh

#准备客户端证书环境
[root@openvpn 3]# cp -r /usr/share/easy-rsa/ /etc/openvpn/easy-rsa-client
#准备签发证书相关变量的配置文件
[root@openvpn 3]# cp /usr/share/doc/easy-rsa-3.0.8/vars.example /etc/openvpn/easy-rsa-client/3/vars
[root@openvpn 3]# cd /etc/openvpn/easy-rsa-client/3
#生成证书申请所需目录pki和文件
[root@openvpn 3]# ./easyrsa init-pki

#生成客户端用户的证书申请
[root@openvpn 3]# ./easyrsa gen-req user01
设置密码

#回到原来server目录,给客户端颁发证书
cd /etc/openvpn/easy-rsa-server/3
#将客户端证书请求文件复制到CA的工作目录
[root@openvpn 3]# ./easyrsa import-req /etc/openvpn/easy-rsa-client/3/pki/reqs/user01.req user01
#修改给客户端颁发的证书的有效期
[root@openvpn 3]# vim vars
set_var EASYRSA_CERT_EXPIRE 180
#签发客户端证书
[root@openvpn 3]# ./easyrsa sign client user01

#将CA和服务器证书相关文件复制到服务器相应的目录
[root@openvpn 3]# mkdir /etc/openvpn/certs
[root@openvpn 3]# cp /etc/openvpn/easy-rsa-server/3/pki/ca.crt /etc/openvpn/certs/
[root@openvpn 3]# cp /etc/openvpn/easy-rsa-server/3/pki/issued/server.crt /etc/openvpn/certs/
[root@openvpn 3]# cp /etc/openvpn/easy-rsa-server/3/pki/private/server.key /etc/openvpn/certs/
[root@openvpn 3]# cp /etc/openvpn/easy-rsa-server/3/pki/dh.pem /etc/openvpn/certs/

#将客户端私钥于证书相关文件复制到服务器相关的目录
[root@openvpn 3]# mkdir /etc/openvpn/client/user01/
[root@openvpn 3]# find /etc/openvpn/ \( -name "user01.key" -o -name "user01.crt" -o -name ca.crt \) -exec cp {} /etc/openvpn/client/user01/ \

#修改服务器端配置文件
[root@openvpn 3]# vim /etc/openvpn/server.conf
#清空后使用以下配置:
port 1194
proto tcp
dev tun
ca /etc/openvpn/certs/ca.crt
cert /etc/openvpn/certs/server.crt
key /etc/openvpn/certs/server.key
dh /etc/openvpn/certs/dh.pem
server 10.8.0.0 255.255.255.0
push "route 172.16.0.0 255.255.0.0"
keepalive 10 120
cipher AES-256-CBC
compress lz4-v2
push "compress lz4-v2"
max-clients 2048
user openvpn
group openvpn
status /var/log/openvpn/openvpn-status.log
log-append /var/log/openvpn/openvpn.log
verb 3
mute 20

#准备日志相关目录
[root@openvpn 3]# mkdir /var/log/openvpn
[root@openvpn 3]# chown openvpn.openvpn /var/log/openvpn

#在服务器开启ip_forward转发功能
[root@openvpn 3]# echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
[root@openvpn 3]# sysctl -p
#添加SNAT规则
[root@openvpn 3]# echo 'iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j MASQUERADE' >> /etc/rc.d/rc.local 
[root@openvpn 3]# chmod +x /etc/rc.d/rc.local
[root@openvpn 3]# /etc/rc.d/rc.local

#启用安全增强功能
[root@openvpn 3]# openvpn --genkey --secret /etc/openvpn/certs/ta.key
[root@openvpn 3]# vim /etc/openvpn/server.conf
添加:tls-auth /etc/openvpn/certs/ta.key 0 #客户端为1,服务器端为0
#将ta.key复制到用户证书目录中
[root@openvpn 3]# cp /etc/openvpn/certs/ta.key /etc/openvpn/client/user01/

#启动OpenVPN服务
[root@openvpn 3]# systemctl enable --now openvpn@server

#生成客户端文件,文件后缀必须为.ovpn
[root@openvpn 3]# vim /etc/openvpn/client/user01/client.ovpn
client
dev tun
proto tcp
remote <openvpn服务器的公网IP>
resolv-retry infinite
nobind
#persist-key
#persist-tun
ca ca.crt
cert user01.crt
key user01.key
remote-cert-tls server
tls-auth ta.key 1
cipher AES-256-CBC
verb 3
compress lz4-v2

#官网客户端下载地址:
#https://openvpn.net/community-downloads/](https://openvpn.net/community-downloads/
#将客户端文件打包后给到用户
[root@openvpn 3]# cd /etc/openvpn/client/user01/
[root@openvpn user01]# tar cf /root/user01.tar ./

安装配置后客户端成功访问后端web服务器


image.png

2、通过编译、二进制安装MySQL5.7

二进制安装mysql5.7:

#安装相关包
[root@centos01 ~]# yum  -y install libaio numactl-libs

#创建用户和组
[root@centos01 ~]# groupadd mysql
[root@centos01 ~]# useradd -r -g mysql -s /bin/false mysql

#创建数据目录
[root@centos01 local]#  mkdir -pv /data/mysql && chown -R mysql.mysql /data/mysql

#下载安装包
[root@centos01 ~]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
[root@centos01 ~]# tar xf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@centos01 ~]# cd /usr/local/
[root@centos01 local]# mv mysql-5.7.36-linux-glibc2.12-x86_64/ mysql
[root@centos01 local]# chown -R mysql.mysql /usr/local/mysql/

#添加环境变量
[root@centos01 local]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos01 local]# . /etc/profile.d/mysql.sh

#准备配置文件
[root@centos01 local]# cp /etc/my.cnf{,.bak}
[root@centos01 local]# cat > /etc/my.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client] 
socket=/data/mysql/mysql.sock
EOF

#生成 root 空密码
[root@centos01 local]# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

#准备服务脚本和启动
[root@centos01 local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos01 local]# chkconfig --add mysqld
[root@centos01 local]# service mysqld start

#修改root口令
[root@centos01 local]# mysqladmin -uroot password 123456

#连接mysql
[root@centos01 local]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

编译安装mysql5.7:

#安装依赖包
[root@centos01 ~]# yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper

#创建mysql用户
[root@centos01 ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql

#创建数据库目录
[root@centos01 ~]# mkdir /data/mysql
[root@centos01 ~]# chown mysql.mysql /data/mysql

#下载并解压源码包
[root@centos01 ~]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.36.tar.gz
[root@centos01 ~]# tar xf mysql-5.7.36.tar.gz -C /usr/local/src/

#下载boost库
[root@centos01 ~]# wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
[root@centos01 ~]# tar xf boost_1_59_0.tar.gz -C /usr/local/

#编译安装
#如果出错,执行rm -f CMakeCache.txt
[root@centos01 ~]# cd /usr/local/src/mysql-5.7.36/
cmake . \
-DCMAKE_INSTALL_PREFIX=/apps/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0

[root@centos01 ~]# make -j 12 && make install

#修改环境变量
[root@centos01 mysql-5.7.36]# echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos01 mysql-5.7.36]# . /etc/profile.d/mysql.sh

#生成数据库文件
[root@centos01 mysql-5.7.36]# cd /apps/mysql/
[root@centos01 mysql-5.7.36]# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql/

#准备配置文件
[root@centos01 mysql-5.7.36]# vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
character-set-server=utf8mb4
[client]
socket=/data/mysql/mysql.sock
[mysql]
default-character-set=utf8mb4

#准备启动脚本,并启动服务
[root@centos01 mysql-5.7.36]# cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos01 mysql-5.7.36]# chkconfig --add mysqld
[root@centos01 mysql-5.7.36]# service mysqld start
Starting MySQL.Logging to '/data/mysql/mysql.log'.
 SUCCESS!

#进行安全初始化
[root@centos01 mysql-5.7.36]# mysql_secure_installation 

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y
 - 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? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

#测试连接mysql
[root@centos01 mysql-5.7.36]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.36 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

3、二进制安装mariadb10.4

#配置yum仓库
[root@centos01 ~]# vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

#安装mariadb
[root@centos01 ~]# yum -y install MariaDB-server

#启动mariadb
[root@centos01 ~]# systemctl start --now mariadb

#登录修改密码
[root@logstash1 ~]# mysql
MariaDB [(none)]> alter user 'root'@'localhost' identified by '123456';

#安全设置
[root@centos01 ~]# mysql_secure_installation


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343

推荐阅读更多精彩内容

  • 1、在阿里云服务器搭建openv-p-n 服务器已销毁,下面是自动化Openv-p-n的脚本,一直到第一个客户端为...
    yabao11阅读 330评论 0 0
  • 第十周 1、在阿里云服务器搭建openv-p-n(有条件的同学再做) 搭建失败,用的腾讯云。配置都核对过(不然报错...
    如是我闻_17e6阅读 221评论 0 0
  • 1、在阿里云服务器搭建openv-p-n(有条件的同学再做) 略 2、通过编译、二进制安装MySQL5.7 二进制...
    johndoewy阅读 171评论 0 0
  • 1、简述DNS服务器原理,并搭建主-辅服务器。DNS(Domain Name Service的缩写)的作用就是根据...
    马晖阅读 175评论 0 0
  • 一、简述DNS服务器原理,并搭建主务器。 DNS:Domain Name System 域名系统,应用层协议,是互...
    亨利阅读 131评论 1 0