首页 > 其他分享 >Spring cloud 安全部署与性能优化

Spring cloud 安全部署与性能优化

时间:2024-07-20 13:28:12浏览次数:12  
标签:oscm Spring githubusercontent cloud sh com https 优化 bash

Mr. Neo Chen (陈景峯), netkiller, BG7NYT

节选自《Netkiller Spring Cloud 手札》

多维度架构 - 知乎​www.zhihu.com/club/1241768772601950208​编辑

1. 环境安装

1.1. 操作系统初始化

操作系统按完成后,使用下面脚本做一次初始化

curl -s https://raw.githubusercontent.com/oscm/shell/master/os/personalise.sh | bash
			
			

1.2. 安装 Nginx 

curl -s https://raw.githubusercontent.com/oscm/shell/master/web/nginx/stable/nginx.sh | bash
			
			

1.3. 安装数据库

1.3.1. MySQL

5.7

curl -s https://raw.githubusercontent.com/oscm/shell/master/database/mysql/5.7/mysql.server.sh | bash
			
				

安装完成会看到下面输出

2019-06-04T08:54:24.419092Z 1 [Note] A temporary password is generated for root@localhost: 8X!pE(o+urv;			
			
				

8.0

curl -s https://raw.githubusercontent.com/oscm/shell/master/database/mysql/8.0/server.sh | bash

curl -s https://raw.githubusercontent.com/oscm/shell/master/database/mysql/8.0/client.sh | bash			
			
				

1.3.2. PostgreSQL

PostgreSQL 9.4

curl -s https://raw.githubusercontent.com/oscm/shell/master/database/postgresql/postgresql94-centos7.sh | bash			
			
				

1.3.3. Redis

curl -s https://raw.githubusercontent.com/oscm/shell/master/database/redis/source/redis-5.0.5.sh | bash			
			
				

1.4. RabbitMQ

curl -s https://raw.githubusercontent.com/oscm/shell/master/queue/rabbitmq/rabbitmq-server-3.7.15.sh | bash		
		
			

1.5. OpenJDK

curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/java/openjdk/java-1.8.0-openjdk.sh | bash
			
			

1.5.1. Maven

curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/java/maven/apache-maven-3.6.1.sh | bash				
				
				

1.5.2. Gradle

curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/java/gradle/gradle-5.4.1.sh | bash				
				
				

1.6. Node

前端开发会用到Node.js

curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/node.js/binrary/node-v12.4.0.sh | bash			
			
			

1.7. Gitlab

curl -s https://raw.githubusercontent.com/oscm/shell/master/project/gitlab/gitlab.centos7.sh | bash			
			
			

Gitlab 配置请参考 《Netkiller Project 手札》

1.7.1. Gitlab runner

curl -s https://raw.githubusercontent.com/oscm/shell/master/project/gitlab/gitlab-runner.sh | bash				
				
				

java 编译环境

去 Oracle 网站下载 java 8 jdk-8u212-linux-x64.rpm

yum localinstall jdk-8u212-linux-x64.rpm

curl -s https://raw.githubusercontent.com/oscm/shell/master/project/git.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/java/maven/apache-maven-3.6.1.sh | bash
				
				

2. 操作系统配置与优化

操作系统要求 CentOS 7 Minimal ISO

2.1. 域名

2.1.1. 配置 DNS

修改 /etc/resolv.conf 配置 DNS 确保域名解析正确

echo -ne "
search example.com
nameserver 208.67.222.222
nameserver 202.67.220.220
nameserver 8.8.8.8
nameserver 4.4.4.4
" > /etc/resolv.conf
				
				

2.1.2. /etc/hosts

DNS 解析有延迟,很多不可控因素,将域名写入 /etc/hosts 更为保险

192.168.1.1		www.netkiller.cn
192.168.1.2		api.netkiller.cn
192.168.1.3		db.netkiller.cn
				
				

使用域名链接数据的例子

spring.datasource.url=jdbc:mysql://db.netkiller.cn:3306/neo				
				
				

DNS 不可靠的原因分析,因为DNS使用UDP传输,网络拥堵,电磁干扰等等都能导致丢包。

2.2. 历史记录操作留痕

定义 .history 文件格式,记录每一步操作,便于查看什么时间执行了什么命令

通过~/.bash_history文件记录系统管理员的操作记录,定制.bash_history格式

HISTSIZE=1000
HISTFILESIZE=2000
HISTTIMEFORMAT="%Y-%m-%d-%H:%M:%S "
export HISTTIMEFORMAT
			
			

看看实际效果

$ history | head
1 2012-02-27-09:10:45 do-release-upgrade
2 2012-02-27-09:10:45 vim /etc/network/interfaces
3 2012-02-27-09:10:45 vi /etc/network/interfaces
4 2012-02-27-09:10:45 ping www.163.com
			
			

2.3. 临时文件安全

临时文件不应该有执行权限

/tmp

/dev/sda3 /tmp ext4 nosuid,noexec,nodev,rw 0 
			
			

同时使用符号连接将/var/tmp 指向 /tmp

/dev/shm

none /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0
			
			

2.4. 执行权限 

以数据库为例,从安全角度考虑我们需要如下更改

chown mysql:mysql /usr/bin/mysql*
chmod 700 /usr/bin/mysql*
			
			

mysql用户是DBA专用用户, 其他用户将不能执行mysql等命令。

2.5. Linux 系统资源调配

2.5.1. /etc/security/limits.conf

很多资料上是这么写的

* soft nofile 65535
* hard nofile 65535
				
				

这样做是偷懒,会带来很多问题,如果你的服务器被攻击,由于你的设置,系统将耗光你的资源,直到没有任何响应为止,你可能键盘输入都成问题,你不得不重启服务器,但你会发现重启只能维持短暂几分钟,又会陷入无响应状态。

nobody soft nofile 4096
nobody hard nofile 8192
			
				

为什么会设置为nobody用户呢?因为root用户启动系统后web 服务器会使用nobody用户创建子进程,socket连接实际上是nobody用户在处理。root 仅仅是守护父进程。

mysql soft nofile 2048
mysql hard nofile 2048
				
				

针对 mysql 做限制

提示
关于 nofile 即打开文件数,这个跟socket有非常紧密的关系,在linux系统中任何设备都被看做是一个文件(字符设备),你连接一个鼠标,键盘,摄像头,硬盘等等都被看作打开一个设备文件,所以默认1024是远远不够的。

cat >> /etc/security/limits.conf <<EOF
root 	soft nofile 65536
root 	hard nofile 65536
www		soft nofile 65536
www 	hard nofile 65536
mysql	soft nofile 65536
mysql 	hard nofile 65536
EOF
				
				

2.5.2. /etc/sysctl.conf

内核参数调整

cat >> /etc/sysctl.conf <<EOF

net.ipv4.ip_local_port_range = 1024 65500
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 60
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 4096
EOF
			
				

2.6. 关闭 SELINUX

curl -s https://raw.githubusercontent.com/oscm/shell/master/os/selinux.sh | bash				
			
			

2.7. 关闭写磁盘I/O功能

对于某些文件没必要记录文件的访问时间,由其是在高并发的IO密集操作的环境下,通过两个参数可以实现noatime,nodiratime减少不必要的系统IO资源。

编辑/etc/fstab 添加 noatime,nodiratime 参数

/dev/sdb1 /www ext4 noatime,nodiratime 0 0
			
			

我一般分区规划是,/系统根分区,swap交换分区,/www数据分区,同时 禁止写入atime时间,因为/www频繁请求会影响IO 

临时mount

mount -o remount,noatime,nodiratime /dev/sda3 /mnt/your
			
			

LABEL 方式

LABEL=/www /www ext3 defaults,noatime,nodiratime 1 1
			
			

标签:oscm,Spring,githubusercontent,cloud,sh,com,https,优化,bash
From: https://blog.csdn.net/u010604770/article/details/140476258

相关文章

  • SpringBoot+Vue的闲一品零食交易平台(前后端分离)
    技术栈JavaSpringBootMavenMySQLmybatisVueShiroElement-UI角色对应功能网站用户管理员项目功能截图......
  • SpringBoot+Vue的进存销管理系统(前后端分离)
    技术栈JavaSpringBootMavenMySQLmybatisVueShiroElement-UI角色对应功能管理员员工项目功能截图......
  • 基于Java Springboot餐厅点餐系统
    作者介绍:✌全网粉丝10W+本平台特邀作者、博客专家、CSDN新星计划导师、软件领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于项目实战✌一、作品包含源码+数据库+设计文档万字+全套环境和工具资源+部署教程二、项目技术前端技术:Html、Css......
  • 基于Java Springboot宠物管理系统
    作者介绍:✌全网粉丝10W+本平台特邀作者、博客专家、CSDN新星计划导师、软件领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于项目实战✌一、作品包含源码+数据库+设计文档万字+全套环境和工具资源+部署教程二、项目技术前端技术:Html、Css......
  • Spring Book Club + java查询数据库 + 百万数据 + 同步Elasticsearch(ES)+ 多线程 + Fei
    @FeignClient(name="bwie-elastic")publicinterfaceEsFeign{@PostMapping("/add")publicResultadd(@RequestBodyArrayList<ResourceInfo>resourceInfo);}@RestControllerpublicclassUserControllerimplementsApplica......
  • 毕设项目:springboot+vue实现的在线求职平台
    一、前言    随着信息技术的飞速发展和互联网的普及,线上求职已成为众多求职者和企业招聘的重要渠道。为满足市场需求,我们利用SpringBoot和Vue技术栈,开发了一款功能全面、用户友好的在线求职平台。本文将对该平台的设计、实现及关键技术进行详细介绍。本文介绍基于spring......
  • 键鼠助手--FPS游戏移动优化算法
    目前FPS类游戏的宏检测机制比较严格,因此我们对此类游戏做了特殊优化图示中的参数意义如下:在180毫秒内移动[4,10]的距离(屏幕左上角是原点,向右向下移动为正,向左向上移动为负);然后总计拆分为[80/2480/11]次也就是[47]次;以后宏运行的时候随机取4到7次进行移动,移动总距离是[4,10......
  • 线段树优化建图
    为什么?什么时候用线段树优化建图例题如果此时暴力建边\(O(n^{2})\)肯定会TLE观察到题目中的“区间”此时考虑用线段树优化建图,在每个区间上连边(线段树上只有\(\log{n}\)个区间)来减少边的个数实现方法?摘抄自tzx_wk我们就拿\(2\)操作来举例吧。现在假设假如有一个点......
  • 关于线段树优化建图
    线段树优化建图引入对于这道板子题但是我不会大概意思就是:有\(n\)个点、\(q\)次操作。每一种操作为以下三种类型中的一种:连一条\(u→v\)的有向边,权值为w对于所有\(i∈[l,r]\)连一条\(u→i\)的有向边,权值为\(w\)对于所有\(i∈[l,r]\)连一条\(i→u\)的......
  • springboot公寓租赁系统-计算机毕业设计源码03822
    目 录摘要1绪论1.1研究背景与意义1.2选题背景1.3论文结构与章节安排2 公寓租赁系统系统分析2.1可行性分析2.1.1技术可行性分析2.1.2经济可行性分析2.1.3法律可行性分析2.2系统功能分析2.2.1功能性分析2.2.2非功能性分析2.3系统用例......