记录搭建一个T大树洞的过程
在购买全新的服务器后,我首先选择绑定秘钥对的方式链接 SSH,这种方式相比于普通的密码登陆更加安全
由于并不熟悉 iptables 或者 firewalld (惭愧),需要使用防火墙的部分都通过配置云服务提供商的安全策略来完成了。
1. 配置交换空间
按照 doc 上给出的建议,首先安装 swap 空间
请注意,若未特殊注明,使用的用户都是 root, 相信我,如果你知道你每一步都在干什么,使用 root 是一个不太安全但会减少很多麻烦的选择。同样你也可以选择建立一个拥有 sudo 权限的普通账户,配置公钥并禁止 SSH 访问 root 账户。
swapon -s
# nothing...
free -m
# total used free shared buff/cache available
# Mem: 3789 237 3365 0 185 3336
# Swap: 0 0 0
df -h
# /dev/vda1 79G 2.9G 73G 4% /
dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
我希望配置 4G 的交换空间,这是按照教程的建议所选择的
ls -lh /swapfile
# -rw-r--r-- 1 root root 4.0G Nov 11 07:20 /swapfile
chmod 600 /swapfile
mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=26196ec7-82ff-49b2-a5d8-2b006ce27b99
swapon /swapfile
此时再执行 swapon -s
可以报告交换空间
我们还需要默认启动它
vim /etc/fstab
vim 的操作不会赘述,我们需要在底部追加一行
/swapfile swap swap sw 0 0
使用其他的方法或者编辑器也是可行的
swappiness
项规定了系统使用 swap 空间的频率,使用 swap 空间的时间代价是比较高的,我们希望将其调整的更低一点,CentOS 7 默认值为 30, 我们将其调整至 10
cat /proc/sys/vm/swappiness
# 30
sysctl vm.swappiness=10
# vm.swappiness = 10
2. 安装 Nginx
Nginx 的配置实在是老生常谈,这里只记录配置过程中使用了的命令,不再赘述每一步的目的
在我的博客建设中,选择了自己编译使用 Nginx, 编译运行更稳定,可自由选择扩展。但是安装软件包也已经暂时足够满足我们的使用场景
yum install epel-release
yum update && yum upgrade
# ...
yum install nginx
systemctl start nginx
至此,可以通过直接访问服务器的 ip 的方式获取到 "Welcome to CentOS" 的页面,这意味着 Nginx 正常运作了。
但是,由于新域名的备案未完成,我们无法通过解析域名的方式访问该网站。关于 CDN 与 Nginx 配置的问题,会在后文详细说明
3. 安装SQL, Redis, Go
数据库的大小实在是让我头疼的一个问题,在搭建时无法预料到我们将迎来多大规模的数据冲击,仍不可知 80G 的云硬盘能否满足要求。无论如何,先着手做吧!
按照 T 大树洞提供的教程,我们首先安装 MySQL
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo
yum --enablerepo=mysql80-community install mysql-community-server
service mysqld start
grep "A temporary password" /var/log/mysqld.log
# 2021-11-11T04:46:43.765294Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /fY,lt<Or7xk
mysql_secure_installation
# Securing the MySQL server deployment.
# Enter password for user root:
# Temp_passwd
# The existing password for the user account root has expired. Please set a new password.
# New password:
# Ur passwd
# Re-enter new password:
# Ur passwd
下面的内容,不想看的话就是 5 个 y
--------------------------------------------------------------------------------------
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.
---------------------------------------------------------------------------------------
service mysqld restart
# Redirecting to /bin/systemctl restart mysqld.service
chkconfig mysqld on
# Note: Forwarding request to 'systemctl enable mysqld.service'.
mysql -u root -p
# Enter password:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
Redis
yum install redis
systemctl start redis.service
redis-cli ping
# PONG
vim /etc/redis.conf
# 在 # requirepass foobared 中去掉 # 并更换为你自己的密码
# 推荐使用一个长的 SHA256SUM
systemctl restart redis.service
redis-cli
127.0.0.1:6379> set key1 10
# (error) NOAUTH Authentication required.
127.0.0.1:6379> auth Yourpasswd
# OK
Go
我先把 Go 的 tar 包下到了本地,然后sFTP传了上去
tar xzf go1.17.3.linux-amd64.tar.gz
cd go
我还以为是 src, 结果是 bin 包
mv ./go /usr/local
export PATH=$PATH:/usr/local/go/bin
go version
# go version go1.17.3 linux/amd64
4. reCAPTCHA
很简单,注册获取一个 site token 即可
考虑到是 Google 的,顺便研究了一下国内如何正常访问之
只需要把 www.google.com 换成 www.recaptcha.net 即可,暂时未经验证
5. 邮件服务器
我选择买 Aliyun 的邮件推送
真贵啊 ...
6. 配置 Nginx
暂时似乎卡在了这里,因为 CDN 要求域名备案,但是域名备案还得一段 ..
评论 (0)