二、《浪潮云服务器》部署JenkinsDockerNginxTomcatNodejsMaven

浪潮云服务器部署(二)

1. Jenkins 安装

1. 准备好最新的jenkins.war和配置文件如下:

#!/bin/bash

# 导入环境变量

export JENKINS_HOME=/home/jenkins

export JAVA_HOME=/home/java/jdk1.8.0_191

cd $JENKINS_HOME

pid=`ps -ef | grep jenkins.war | grep -v grep| awk {print $2}`

if [ "$1" = "start" ];then

if [ -n "$pid" ];then

echo jenkins is running...

else

### java启动服务 配置java安装根路径,和启动war包存的根路径

nohup $JAVA_HOME/bin/java -Xms512m -Xmx768m -jar $JENKINS_HOME/jenkins.war --ajp13Port=-1 --httpPort=8801 >/dev/null 2>&1 &

fi

elif [ "$1" = "stop" ];then

exec ps -ef | grep jenkins | grep -v grep | awk {print $2}| xargs kill -9

echo jenkins is stop...

else

echo "Please input like this:"./jenkins.sh start" or "./jenkins stop""

fi

2.开启防火墙

firewall-cmd --zone=public --add-port=8801/tcp --permanent

firewall-cmd --reload

firewall-cmd --list-ports

2. docker 部署安装

yum update

Docker安装官方地址:

以下命令都是在root账号权限下执行的

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo

安装最新版本的Docker CE和containerd

yum install docker-ce docker-ce-cli containerd.io

启动Docker

systemctl start docker

ip addr查看docker是否成功安装

启动docker命令

systemctl start docker.service

设置开机启动docker

systemctl enable docker

修改镜像地址

vi /etc/docker/daemon.json

3. 拉取nginx和tomcat 镜像

docker pull nginx

docker pull tomcat:8.5

1. 启动 nginx容器

docker run -d -p 80:80 --restart=always -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx --name nginx nginx

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" "$upstream_addr" "$request_time";

access_log /var/log/nginx/access.log main;

sendfile on;

#tcp_nopush on;

#用于tomcat反向代理,解决nginx 504错误

proxy_connect_timeout 600; #单位秒

proxy_send_timeout 600; #单位秒

proxy_read_timeout 600; #单位秒

proxy_buffer_size 16k;

proxy_buffers 4 64k;

proxy_busy_buffers_size 128k;

proxy_temp_file_write_size 128k;

# ps:以timeout结尾配置项时间要配置大点

keepalive_timeout 65;

client_max_body_size 10m;

#gzip on;

upstream tomcat {

server 172.17.0.4:8080;

}

server {

listen 80;

server_name localhost;

location / {

proxy_pass ;

proxy_connect_timeout 300;

proxy_redirect off;

index index.html index.htm;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Real-Port $remote_port;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

# location /static/ {

# alias /usr/share/nginx/html/;

#}

}

include /etc/nginx/conf.d/*.conf;

}

2.开启防火墙

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --reload

firewall-cmd --list-ports

4. Nodejs安装配置

tar xvf node-v14.16.1-linux-x64.tar.xz

cd /home/nodejs/node-v14.16.1-linux-x64

ln -s /home/nodejs/node-v14.16.1-linux-x64/bin/node /usr/bin/node

ln -s /home/nodejs/node-v14.16.1-linux-x64/bin/npm /usr/bin/npm

node -v

npm -v

5. Maven 安装配置

export MAVEN_HOME=/home/maven/apache-maven-3.6.2

export PATH=${MAVEN_HOME}/bin:$PATH

mvn -version