添加防火墙操作
启动: systemctl start firewalld
重启: systemctl restart firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld
查看开放的端口:firewall-cmd --list-ports
添加端口:firewall-cmd --add-port=8080/tcp --permanent (–permanent永久生效,没有此参数重启后失效)
准备环境
1.CentOS
2.vim(vi也行)
yum -y install vim*
Linux中部署Docker(yum和安装包)
1.更新yum
yum update
2.安装软件包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
3.设置yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4.安装docker
yum install -y docker-ce
5.验证
docker version
ps -aux|grep docker
6.安装包安装docker
6.1 转载:
https://www.cnblogs.com/kingsonfu/p/11576797.html
6.2 安装包官方地址:
https://download.docker.com/linux/static/stable/x86_64/
6.3 在线下载或者使用ftp上传到linux
wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
6.4 解压缩
tar -zxvf docker-18.06.3-ce.tgz
6.5 将解压出来的docker文件复制到 /usr/bin/ 目录下
cp docker/* /usr/bin/
6.6 在/etc/systemd/system/目录下新增docker.service文件,内容如下,这样可以将docker注册为service服务
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
6.7 给docker.service文件添加执行权限
chmod +x /etc/systemd/system/docker.service
重新加载配置文件
systemctl daemon-reload
6.8 启动
systemctl start docker
设置开机启动
systemctl enable docker.service
systemctl status docker
Linux中部署JDK
1.上传jdk-8u291-linux-x64.tar.gz到cd /usr/local
cd /usr/local
上传jdk.tar.gz,并解压
tar -xzvf jdk-8u291-linux-x64.tar.gz
2.配置环境变量
vi /etc/profile
vim /etc/profile
在最底下添加
export JAVA_HOME=/usr/local/jdk1.8.0_291
export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
保存退出后,执行source /etc/profile使修改的环境变量生效
source /etc/profile
3.验证java是否安装成功
java -version
java
javac
Linux中部署Redis
1.上传redis-6.2.2.tar.gz到/usr/local下,并解压-更名
cd /usr/local
上传tar.gz
tar -zvxf redis-6.2.2.tar.gz
mv redis-6.2.2 redis
2.安装gcc环境
yum install gcc-c++
3.进入到/usr/local/redis目录下,make编译
make
如果报错:
安装gcc
yum -y install gcc automake autoconf libtool make
make
安装c编译器并编译
yum install gcc-c++
make
解决“jemalloc/jemalloc.h:没有那个文件或目录“问题,在进行编译(因为上次编译失败,有残留的文件)
make distclean
make && make install
4.安装
make PREFIX=/usr/local/redis install
5.替换redis.conf文件
6.检查防火墙端口是否开放
firewall-cmd --zone=public --list-ports
如果没有6379,则开启
firewall-cmd --permanent --add-port=6379/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
7.启动redis
cd /usr/local/redis/bin
./redis-server /usr/local/redis/redis.conf
Linux中部署Nacos
1.上传并解压缩
安装unzip
yum install unzip
cd /usr/local
上传nacos.zip包并解压
unzip nacos-server-1.2.0.zip
2.创建nacos数据库
数据库中执行nacos-mysql.sql脚本
3. 上传覆盖Nacos的配置文件(application.properties)
如果有需要,自己更改数据库连接
cd /usr/local/nacos/conf/application.properties
4.检查防火墙端口是否开放
firewall-cmd --zone=public --list-ports
如果没有8848,则开启
firewall-cmd --permanent --add-port=8848/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
5.启动nacos
cd /usr/local/nacos/bin
./startup.sh -m standalone
Linux中部署jar
1.上传jar文件到/usr/local/jar下
cd /usr/local
上传jar文件夹,所有jar包和application.yml(配置文件)和finance.sh(执行脚本)
2.执行脚本
1.backend
java -jar backend-1.0.0-release.jar --spring.config.location=/usr/local/jar/backend.yml &
后面加&,代表在后台运行,运行完第一个考验Ctrl+C退出,然后运行下面的regular
2.regular
java -jar regular-1.0.0-release.jar --spring.config.location=/usr/local/jar/regular.yml &
3.fund
java -jar fund-1.0.0-release.jar --spring.config.location=/usr/local/jar/fund.yml &
4.current
java -jar current-1.0.0-release.jar --spring.config.location=/usr/local/jar/current.yml &
5.gold
java -jar gold-1.0.0-release.jar --spring.config.location=/usr/local/jar/gold.yml &
6.gateway
java -jar gateway-1.0-SNAPSHOT.jar --spring.config.location=/usr/local/jar/gateway.yml &
Docker中部署Nginx
1.拉取nginx 最新镜像
docker pull nginx:latest
2.新建立一个资源文件夹
mkdir -p /usr/finance_woniuxy/nginx
3.创建2个配置文件
第一个(Dockerfile):
vi /usr/finance_woniuxy/nginx/Dockerfile
注意!!! : 粘粘的时候要改成编辑模式,否则可能会缺失
#Base Image设置基础镜像
FROM nginx
#Define Author 定义作者
LABEL maintaniner="Jaime"
# 将文件中的内容复制到 /usr/share/nginx/html/ 这个目录下面
COPY dist/ /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/nginx.conf
第二个(nginx.conf):
vi /usr/finance_woniuxy/nginx/nginx.conf
worker_processes auto;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
client_max_body_size 20m;
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
4.上传dist文件夹
注意:
1.dist文件中的BaseUrl(src/utils/request.js)必须是服务器的名字
2.必须在build/utils.js
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
publicPath: '../../', //必须要加上这行
fallback: 'vue-style-loader'
})
}
然后打包
npm run build
切换到nginx下
cd /usr/finance_woniuxy/nginx
上传dist文件夹
nginx下有3个文件:
dist Dockerfile nginx.conf
5.构建自定义镜像(在nginx文件夹下)
docker build -t nginx:v1 .
Successfully built …
6.启动容器
docker run -p 80:80 -d nginx:v1
Docker中部署mysql5.7
docker pull mysql:5.7
docker run -d -p 3306:3306 --privileged=true -v /docker/mysql/conf/my.cnf:/etc/my.cnf -v /docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --lower_case_table_names=1
转:https://www.cnblogs.com/wjw1014/p/12149399.html
run run 是运行一个容器
-d 表示后台运行
-p 表示容器内部端口和服务器端口映射关联
--privileged=true 设值MySQL 的root用户权限, 否则外部不能使用root用户登陆
-v /docker/mysql/conf/my.cnf:/etc/my.cnf 将服务器中的my.cnf配置映射到docker中的/docker/mysql/conf/my.cnf配置
-v /docker/mysql/data:/var/lib/mysql 同上,映射数据库的数据目录, 避免以后docker删除重新运行MySQL容器时数据丢失
-e MYSQL_ROOT_PASSWORD=123456 设置MySQL数据库root用户的密码
--name mysql 设值容器名称为mysql
mysql:5.7 表示从docker镜像mysql:5.7中启动一个容器
--character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci 设值数据库默认编码
lower_case_table_names 表示mysql镜像忽略表名大小写
记得开防火墙!!!!!!
docker exec -it mysql bash
mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY 'test123' WITH GRANT OPTION;