1、安装nohup(后台进程运行java)
2、安装中文字体(防止中文乱码)
3、安装chrony(保证分布式部署时间的一致性)
4、安装mysql数据,迁移目录,并授权自启动;
5、安装redis,并设置自动动;
6、安装nginx,并设置自启动;
7、部署jar包,并设置自启动;
8、补充:数据库等高并发或高io应用,linux应调优系统;
注:如有磁盘挂在:先挂在磁盘
其他教程
1、挂载磁盘
运行,可能会遇到是否更新其他依赖,输入y,继续安装
yum install coreutils
参考教程:
参考教程
常用命令:
- #将3306转发至33006端口,并开发33306端口,供发布时使用
- firewall-cmd --add-forward-port=port=33306:proto=tcp:toport=3306:toaddr= --permanent
- firewall-cmd --reload
- firewall-cmd --list-all
-
- #发布后移除端口转发策略
- sudo firewall-cmd --remove-forward-port=port=33306:proto=tcp:toport=3306 --permanent
- firewall-cmd --reload
- firewall-cmd --list-all
1) 安装JDK
2)新建数据库,并上传备份脚本
3)上传jar并设置自启动
4)修改nginx配置并设置自启动
可根据教程生成自签名的ssl证书,来配置https,可也不生成,直接用http;
下面是单机的80自定转443端口,并可根据实际情况优化
-
- # Nginx 进程数,一般设置为和 CPU 核数一样,可设置 auto
- worker_processes 1;
-
- #error_log logs/error.log; # Nginx 的错误日志存放目录
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
-
- #pid logs/nginx.pid; # Nginx 服务启动时的 pid 存放位置
-
-
- events {
- # 每个进程允许最大并发数
- # 小规模的服务器:512或1024,中等规模的服务器:2048或4096,大规模的服务器:8192或更高
- # 考虑到内存占用和CPU的利用率,一般建议不要将worker_connections设置得过高
- worker_connections 1024;
- }
-
-
- http {
- include mime.types;# 文件扩展名与类型映射表
- default_type application/octet-stream;# 默认文件类型
-
- # 设置日志模式
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
-
- #access_log logs/access.log main; # Nginx访问日志存放位置
-
- sendfile on;# 开启高效传输模式
- #tcp_nopush on;# 减少网络报文段的数量
- keepalive_timeout 65;# 保持连接的时间,也叫超时时间,单位秒
-
- #gzip on;#表示开启压缩功能
-
- # 省去不必要的配置代码
- server {
- listen 80; # 本服务监听的端口号
- server_name localhost; # 主机名称
-
- # 把http的域名请求转成https
- rewrite ^(.*)$ https://$host$1 permanent;
-
- location / {
- root html;
- index index.html index.htm;
- }
-
- # 默认配置
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
-
- # HTTPS server
- #
- server {
- listen 443 ssl;
- server_name 192.168.1.2;
- keepalive_timeout 70;
-
- ssl_certificate cert/mycert.pem;
- ssl_certificate_key cert/privatekey.pem;
-
- ssl_session_cache shared:SSL:10m;
- ssl_session_timeout 10m;
-
- ssl_ciphers HIGH:!aNULL:!MD5;
- ssl_prefer_server_ciphers on;
-
- client_max_body_size 600m;#上传文件大小限制
- client_body_buffer_size 128k;
- proxy_connect_timeout 600;
- proxy_read_timeout 600;
- proxy_send_timeout 600;
- proxy_buffer_size 64k;
- proxy_buffers 4 32k;
- proxy_busy_buffers_size 64k;
- proxy_temp_file_write_size 64k;
-
- location / {
- # root 规定了通过监听的端口号访问的文件目录
- root D:\\comSoft\\nginx\\html\\hy-mes-ui;
- # index 规定了该目录下指定哪个文件
- index index.html index.htm;
- # 配置资源重新跳转,防止刷新后页面丢失
- try_files $uri $uri/ /index.html;
- }
-
- # 配置后端接口的跨域代理
- # 对于路径为 "prod-api 的接口,帮助他跳转到指定的地址
- location /prod-api/ {
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header REMOTE-HOST $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- # 本机上运行的后端接口
- proxy_pass http://localhost:8080/;
- }
-
-
- location /status{
- stub_status on;
- }
- }
- }
默认的最大打开文件数是1024.不满足生产环境的要求。按照如下配置:
1)修改 systemctl管理的 servie 资源限制
编辑/etc/systemd/system.conf
- # 全局的打开文件数
- DefaultLimitNOFILE=2097152
- # 全局打开进程数
- DefaultLimitNPROC=65535
2)调整系统内核参数
编辑文件/etc/sysctl.conf
- # 全局:端口最大的监听队列的长度,可为:32768
- net.core.somaxconn=32768
- # 内存分配模式:1为不限制
- vm.overcommit_memory = 1
- # 单进程打开文件句柄数
- fs.nr_open = 2097152
- # 系统打开文件句柄数
- fs.file-max = 2097152
-
- # 大i/o独立部署中间件选配,例如:redis、队列、数据库等;
- # 请求连接保存在队列中的最大数目
- net.ipv4.tcp_max_syn_backlog=16384
- # 网络接口接收数据包比内核处理速率快时,允许送到队列的数据包的最大数目。
- net.core.netdev_max_backlog=16384
- # 每个tcp连接占用内存,共三个值:最小字节数 默认值 最大字节数
- net.ipv4.tcp_mem = 786432 2097152 3145728
- # 每个tcp连接的读缓冲(接收缓冲),缓存从对端接收的数据,后续会被应用程序读取
- net.ipv4.tcp_rmem = 2048 32768 4194304
- # 每个tcp连接的写缓冲(发送缓冲),缓存应用程序的数据,有序列号被应答确认的数据会从发送缓冲区删除掉
- net.ipv4.tcp_wmem = 2048 8192 2097152
添加完成后,刷新内核参数,立即生效:执行命令
/sbin/sysctl -p
3)调整用户组的资源限制
修改limits.conf。需重启生效,vi /etc/security/limits.conf
- # 用户会话的 打开文件句柄数
- * soft nofile 1048576
- * hard nofile 1048576
- # 用户会话的 打开进程数限制
- * soft nproc 65535
- * hard nproc 65535
- # * 代表所有用户
- # nofile 在测试最大连接数时,可以设置,例如:2097152 = 2048 * 1024。
- # 在实际环境中,因为还要处理数据业务逻辑,太大的值其实没有必要,例如:1048576 = 1024 * 1024
4)查看是否生效
- #用户级别的系统配置
- ulimit -a
- #open file文件限制数
- ulimit -n
- #进程限制数
- ulimit -u
注:window也有优化系统分页大小和文件句柄数,这里不做介绍了
相应优化参考