更新说明:对文章排版以及内容格式做了调整。
更新时间:2022-05-04

服务器配置:
数据库rds、redis、nacos、nginx、node、git、域名、OSS、java、maven

安装Java\maven\nginx\Mysal

JAVA

  • yum install java-1.8.0-openjdk :
  • java -version
  • vim /etc/profile.d/java.sh
  • JAVA_HOME=“/usr/lib/jvm/java-1.8.0-openjdk”
  • source /etc/profile.d/java.sh
  • 验证:echo $JAVA_HOME ->输出目录即为正确

MAVEN

  • yum install -y maven
  • mvn --version
  • vim /etc/maven/setting.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
<localRepository>/opt/maven_repo</localRepository>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
<mirror>
<id>aliyun-maven</id>
<mirrorOf>*</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

Nginx

  • yum install -y nginx
  • 端口开放
  • nginx -s start

Mysql8

  • yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
  • systemctl start mysqld
  • systemctl status mysqld
  • grep ‘temporary password’ /var/log/mysqld.log(若无直接跳过)
  • mysql -uroot -p
    • use mysql;
    • ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘newpassword’;
  • create user test_user@‘%’ identified by ‘password’;
    • ·%· 表示可以在任意远程主机登录
  • grant all on databasename.tablename to ‘username’@‘%’ with grant option;
    • privileges可以为select/ insert /update/all
    • tablename可以为*
    • with grant option 【该用户可授权】
  • flush privileges; 刷新权限表
  • SET PASSWORD FOR ‘username’@‘host’ = PASSWORD(‘newpassword’);
  • SET PASSWORD = PASSWORD(“newpassword”); --当前登陆用户
  • REVOKE privilege ON databasename.tablename FROM ‘username’@‘host’; -撤销用户权限
  • drop user ‘username’@‘host’ --删除用户

安装git

  • yum install git => git --version

安装配置nacos

  • 下载 nacos-server-$version.zip 包
  • tar -xvf nacos-server-$version.tar.gz
  • 默认情况为单实例启动,本服务器设置集群

nacos集群设置

  • mysql创建数据库 nacos
  • 将nacos-mysql脚本倒入到数据库
  • 修改config/application.properties
    • If use MySQL as datasource: 注释打开

spring.datasource.platform=mysql

  • 设置用户名密码为mysql新建的用户/密码
  • 配置cluster
    • cp cluster.conf.example cluster.conf
1
2
3
172.31.0.8:8848
172.31.0.8:8850
172.31.0.8:8860
  • 将 /data/nacos/nacos 改名称 mv nacos/ nacos8848
  • cp -r nacos8848 nacos8860
  • cp -r nacos8848 nacos8850
  • 修改8860与8850端口号:application.properties
  • 然后分别启动
  • 接着看之前单实例的配置:–本地没配置,如果有配置应该先倒出然后再倒入最新启动的

image

image

  • nginx配置–直接放入到nginx.conf即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
upstream nacos_cluster{
server 127.0.0.1:8848;
server 127.0.0.1:8849;
server 127.0.0.1:8850;
}

server {
listen 8848;
server_namelocahost;
localtions / {
proxy_pass http://nacos_cluster;
proxy_set_header Host $host:$server_port;
}
}

nginx重启即可。

安装redis

  • yum install redis
  • systemctl start redis
  • systemctl enable redis [开机启动]
  • /etc/redis.conf [允许远程连接 注释掉 bind:127.0.0.1]
  • # requirepass foobared [密码登录:注释掉该行,将footbared改为 your password]
  • 修改 daemonize no(第128行) 为 daemonize yes
  • 开放安全组:6379
  • redis-server /etc/redis.conf 启动!

telnet

https://www.opss.cn/5167.html

安装NVM

安装pm2

服务器上node版本为14 安装pm2
npm i pm2 -g

安装Docker

配置mysql/redis/tomcat/nginx

Docker应用部署

  • java:8
    • docker pull java:8
  • mysql
    • cd /root
    • mkdir mysql
1
2
3
4
5
6
7
8
docker run -id \
-p 3307:3306 \
--name=c_mysql \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=****** \
mysql:5.7
  • nginx
    • cd /root
    • mkdir nginx
    • cd nginx
    • mkdir conf
    • **cd conf **
    • vim nginx.conf [内容见下方]
    • cd /root
    • 新建容器
1
2
3
4
5
6
docker run -id --name=c_nginx \
-p 8880:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// /root/nginx/conf/nginx.conf
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/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 /var/log/nginx/access.log main;

sendfile on;
`#`tcp_nopush on;

keepalive_timeout 65;

`#`gzip on;

include /etc/nginx/conf.d/*.conf;
}
  • tomcat
  • cd /root
  • mkdir tomcat
1
2
3
4
5
6
docker run -id --name=c_tomcat \
-p 8080:8080 \
-v $PWD:/usr/local/tomcat/webapps \
tomcat

// 在/root/tomcat/test/index.html,开放8080端口测试
  • redis
    • redis由于需要配置密码登录以及远程连接等,而服务器已配好.
    • **因此这里不再安装,**下面为启动命令(没有文件映射)
1
2
docker run -id --name=c_redis -p 6379:6379 redis:5.0
测试:redis-cli.exe -h 192.168.149.135 -p 6379

Docker搭建私有仓库

  • docker pull registry
  • docker run -id --name=registry -p 5000:5000 registry
  • 输入地址 http://私有仓库服务器ip:5000/v2/_catalog
  • 修改daemon.json
    • {“insecure-registries”:[“私有仓库服务器ip:5000”]}
  • systemctl restart docker
  • docker start registry

在CentOS 8上添加Jenkins存储库

由于Jenkins在CentOS 8存储库中不可用,因此我们将手动将Jenkins存储库添加到系统中。

dnf install jenkins

  • 验证状态
    # systemctl start jenkins
    # systemctl status jenkins
  • 修改端口
    # vi /etc/sysconfig/jenkins
  • 浏览
    # http://server-IP:8081 || 输入密码 || 安装插件

Tips

  1. 服务终端总是断开:
  • vi /etc/ssh/sshd_config
  • 修改 ClientAliveInterval 和 ClientAliveCountMax
  • 重启:systemctl restart sshd.service