案例1:HIS前端代码测试
Fontend主机部署Nginx
#HIS前端代码为编译后代码,可直接部署在nginx上查看效果[root@Fontend ~]# yum clean all; yum repolist -vTotal packages: 8,265[root@Fontend ~]# yum -y install nginx.x86_64 #安装nginx软件[root@Fontend ~]# vim /etc/nginx/nginx.conf[root@Fontend ~]# sed -rn '36,42p' /etc/nginx/nginx.confinclude /etc/nginx/conf.d/*.conf;server {#listen 80 default_server;#注释默认虚拟主机#listen [::]:80 default_server; #注释默认虚拟主机server_name_;root /usr/share/nginx/html;[root@Fontend ~]# [root@Fontend ~]# cat /etc/nginx/conf.d/his.conf#编写HIS项目虚拟主机配置server {listen 80 default_server;server_name __;location / {root "/opt/his/web/";index index.html index.htm;}}[root@Fontend ~]# mkdir -p /opt/his/web #创建HIS项目存放目录[root@Fontend ~]# tree /opt/his//opt/his/└── web #存放HIS前端代码2 directories, 0 files[root@Fontend ~]# [root@Fontend ~]# systemctl enable nginx.service#设置nginx服务开机自启动[root@Fontend ~]# systemctl start nginx.service #启动nginx服务[root@Fontend ~]# ss -antpul | grep nginxtcp LISTEN 01280.0.0.0:800.0.0.0:*users:(("nginx",pid=11255,fd=6),("nginx",pid=11254,fd=6),("nginx",pid=11253,fd=6))[root@Fontend ~]# #测试Nginx服务中HIS页面[root@Fontend ~]# echo "test" > /opt/his/web/index.html #创建测试页面[root@Fontend ~]# curl http://localhost/#访问测试test[root@Fontend ~]# rm -rf /opt/his/web/index.html#删除测试页面[root@Fontend ~]#
#Jenkins主机确认HIS前端代码拉取及打包情况[root@Jenkins ~]# ls /var/lib/jenkins/workspace/HIS-FONTEND/favicon.icofontend.tar.gzindex.htmlstatic[root@Jenkins ~]# #Fontend主机确认代码包推送情况[root@Fontend ~]# ls /opt/his/web/fontend.tar.gz[root@Fontend ~]# #解包HIS前端代码,访问测试[root@Fontend ~]# cd /opt/his/web/[root@Fontend web]# tar -xf fontend.tar.gz [root@Fontend web]# lsfavicon.icofontend.tar.gzindex.htmlstatic[root@Fontend web]# #访问Fontend主机测试前端页面展示效果 http://192.168.88.70/
案例2:Elasticsearch部署
Elasticsearch服务部署
#OpenJDK环境部署[root@Services ~]# yum clean all; yum repolist -v...Total packages: 8,265[root@Services ~]# yum -y install java-1.8.0-openjdk-devel.x86_64 #安装OpenJDk...Complete![root@Services ~]#[root@Services ~]# ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-1.el8_5.x86_64/ /usr/lib/jvm/jdk#创建JDK软链接[root@Services ~]# vim /etc/bashrc#配置环境变量[root@Services ~]# tail -3 /etc/bashrc export JAVA_HOME="/usr/lib/jvm/jdk/"#声明JAVA_HOME变量export CLASSPATH=.#声明类库加载目录export PATH=${JAVA_HOME}/bin/:$PATH #声明PATH变量[root@Services ~]# source /etc/bashrc #刷新bash环境[root@Services ~]# echo ${JAVA_HOME}#测试JAVA_HOME变量/usr/lib/jvm/jdk/[root@Services ~]# which java /usr/lib/jvm/jdk/bin/java[root@Services ~]# java -versionopenjdk version "1.8.0_332"OpenJDK Runtime Environment (build 1.8.0_332-b09)OpenJDK 64-Bit Server VM (build 25.332-b09, mixed mode)[root@Services ~]# #安装Elasticsearch服务[root@Services ~]# ls elasticsearch-6.8.0.rpm elasticsearch-6.8.0.rpm[root@Services ~]# yum -y localinstall ./elasticsearch-6.8.0.rpm #配置Elasticsearch服务[root@Services ~]# vim /etc/elasticsearch/elasticsearch.yml [root@Services ~]# cat /etc/elasticsearch/elasticsearch.yml | grep -Pv "^\s*(#|$)"node.name: Services #ES节点名称path.data: /var/lib/elasticsearch #ES数据存储路径path.logs: /var/log/elasticsearch #ES日志存储路径network.host: 0.0.0.0 #监听地址http.port: 9200 #HTTP端口[root@Services ~]##启动Elasticsearch服务[root@Services ~]# systemctl enable elasticsearch.service #设置服务开机自启动[root@Services ~]# systemctl start elasticsearch.service#启动Elasticsearch服务[root@Services ~]# ss -antpul | grep javatcp LISTEN 0128*:9200*:*users:(("java",pid=9847,fd=209))tcp LISTEN 0128*:9300*:*users:(("java",pid=9847,fd=196))[root@Services ~]# #测试Elasticsearch服务[root@Services ~]# curl http://localhost:9200/#访问9200端口,返回一段json数据{"name" : "Services","cluster_name" : "elasticsearch","cluster_uuid" : "1cf7N861QBC_C0RE8gm0OA","version" : {"number" : "6.8.0","build_flavor" : "default","build_type" : "rpm","build_hash" : "65b6179","build_date" : "2019-05-15T20:06:13.172855Z","build_snapshot" : false,"lucene_version" : "7.7.0","minimum_wire_compatibility_version" : "5.6.0","minimum_index_compatibility_version" : "5.0.0"},"tagline" : "You Know, for Search"}[root@Services ~]#
案例3:Elasticsearch插件部署
Elasticsearch插件安装方式
#插件安装方法#方式一:从官网下载ES插件,通常为ZIP格式,解压到/usr/share/elasticsearch/plugins/目录#方式二:使用elasticsearch-plugin命令#elasticsearch-plugin install file://path/xx.zip#elasticsearch-plugin install http://addresss/xx#elasticsearch-plugin install ftp://address/xx#方式三:容器
IK分词器插件
#本地安装IK分词器插件[root@Services ~]# /usr/share/elasticsearch/bin/elasticsearch-plugin list #查看插件列表[root@Services ~]# ls elasticsearch-analysis-ik-6.8.0.zip elasticsearch-analysis-ik-6.8.0.zip[root@Services ~]# /usr/share/elasticsearch/bin/elasticsearch-plugin installfile:///root/elasticsearch-analysis-ik-6.8.0.zip#安装插件-> Downloading file:///root/elasticsearch-analysis-ik-6.8.0.zip[=================================================] 100% @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: plugin requires additional permissions @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@* java.net.SocketPermission * connect,resolveSee http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.htmlfor descriptions of what these permissions allow and the associated risks.Continue with installation" />","position" : 0},{"token" : "为","start_offset" : 1,"end_offset" : 2,"type" : "","position" : 1},{"token" : "手","start_offset" : 2,"end_offset" : 3,"type" : "","position" : 2},{"token" : "机","start_offset" : 3,"end_offset" : 4,"type" : "","position" : 3}]}[root@Services ~]#[root@Services ~]# curl -H "Content-Type: application/json" -XPOST http://localhost:9200/_analyze?pretty -d ' {"analyzer": "ik_smart","text": "华为手机"}'#测试IK分词器{"tokens" : [{"token" : "华为","start_offset" : 0,"end_offset" : 2,"type" : "CN_WORD","position" : 0},{"token" : "手机","start_offset" : 2,"end_offset" : 4,"type" : "CN_WORD","position" : 1}]}[root@Services ~]#
HEAD插件(容器部署)
#安装podman工具[root@Services ~]# yum clean all; yum repolist -v...Total packages: 8,265[root@Services ~]# yum -y install podman#安装podmanComplete![root@Services ~]# podman --version #确认podman安装podman version 4.0.2[root@Services ~]# #导入ES-HEAD镜像[root@Services ~]# ls elasticsearch-head.tar elasticsearch-head.tar[root@Services ~]# podman images#查看本地已有镜像REPOSITORYTAG IMAGE IDCREATED SIZE[root@Services ~]# podman load -i elasticsearch-head.tar#导入ES-HEAD插件镜像Getting image source signaturesCopying blob 604c78617f34 doneCopying blob 60a0858edcd5 doneCopying blob b6ca02dfe5e6 doneCopying blob 0a5e2b2ddeaa doneCopying blob 53c779688d06 doneCopying blob fa18e5ffd316 doneCopying blob cf2eea3d6e04 doneCopying blob d556e03b8284 doneCopying blob 95ea76455b84 doneCopying blob ce5705289a91 doneCopying blob d09533ddfc0d doneCopying blob eb415bbb4658 doneCopying blob f418a5a1e636 doneCopying config d008a8ccd0 doneWriting manifest to image destinationStoring signaturesLoaded image(s): localhost/elasticsearch-head:latest[root@Services ~]# podman images#确认ES-HEAD镜像已导入REPOSITORYTAG IMAGE IDCREATEDSIZElocalhost/elasticsearch-headlatestd008a8ccd0297 weeks ago862 MB[root@Services ~]# #启动ES-HEAD容器[root@Services ~]# podman ps#查看有运行的容器,应为空CONTAINER IDIMAGE COMMAND CREATED STATUSPORTS NAMES[root@Services ~]# podman run -d --name es-head --hostname es-head -p 9100:9100 localhost/elasticsearch-head:latest #后台运行ES-HEAD容器f222cb764271574148d31b184bd0aebda419ce3ebd43843c0ff8f1f4dc6ba53c[root@Services ~]# podman ps#确认ES-HEAD容器已运行CONTAINER IDIMAGECOMMAND CREATEDSTATUSPORTS NAMESf222cb764271localhost/elasticsearch-head:latest/bin/sh -c grunt ...2 seconds agoUp 2 seconds ago0.0.0.0:9100->9100/tcpes-head[root@Services ~]# ss -antpul | grep 9100 #确认9100端口被监听tcp LISTEN 01280.0.0.0:91000.0.0.0:*users:(("conmon",pid=12651,fd=5))[root@Services ~]# #修改Elasticsearch配置,开启跨域访问[root@Services ~]# vim /etc/elasticsearch/elasticsearch.yml [root@Services ~]# sed -rn '59,61p' /etc/elasticsearch/elasticsearch.yml http.port: 9200http.cors.enabled: true #开启HTTP跨域访问支持http.cors.allow-origin: "*" #允许跨域的访问范围[root@Services ~]# systemctl restart elasticsearch.service [root@Services ~]# ss -antpul | grep javatcp LISTEN 0128*:9200*:*users:(("java",pid=12764,fd=214))tcp LISTEN 0128*:9300*:*users:(("java",pid=12764,fd=201))[root@Services ~]# #测试访问Elasticsearch-HEAD插件:http://192.168.88.50:9100/
案例4:Elasticsearch API
Elasticsearch常用API
#测试指定API[root@Services ~]# curl -H "Content-Type: application/json" -XGET http://localhost:9200/_cat/health1677142976 09:02:56 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%[root@Services ~]# curl -H "Content-Type: application/json" -XGET http://localhost:9200/_cat/health" />
#调用API批量导入数据[root@Services ~]# ls data.sh logs.jsonl accounts.json accounts.jsondata.shlogs.jsonl[root@Services ~]# cat data.sh #!/bin/bashcurl -H "Content-Type: application/json" -XPUT http://localhost:9200/account/user/_bulk --data-binary @accounts.jsoncurl -H "Content-Type: application/json" -XPUT http://localhost:9200/_bulk --data-binary @logs.jsonl[root@Services ~]# bash data.sh
案例5:RabbitMQ服务
RabbitMQ部署
#安装Erlang[root@Services ~]# yum clean all; yum repolist -v[root@Services ~]# ls erlang-25.2-1.el8.x86_64.rpm erlang-25.2-1.el8.x86_64.rpm[root@Services ~]# yum -y localinstall ./erlang-25.2-1.el8.x86_64.rpm #安装RabbitMQ[root@Services ~]# ls rabbitmq-server-3.11.5-1.el8.noarch.rpm rabbitmq-server-3.11.5-1.el8.noarch.rpm[root@Services ~]# yum -y localinstall ./rabbitmq-server-3.11.5-1.el8.noarch.rpm #启动RabbitMQ服务[root@Services ~]# systemctl enable rabbitmq-server.service #设置RabbitMQ开机自启动[root@Services ~]# systemctl start rabbitmq-server.service#启动RabbitMQ服务[root@Services ~]# ss -antpul | grep :5672#确认5672端口监听tcp LISTEN 0128*:5672 *:*users:(("beam.smp",pid=13298,fd=35))[root@Services ~]# rabbitmqctl status #查看RabbitMQ服务状态Status of node rabbit@Services ...RuntimeOS PID: 13298OS: LinuxUptime (seconds): 15Is under maintenance" />
RabbitMQ服务应用
#RabbitMQ创建用户[root@Services ~]# rabbitmqctl list_users #列出RabbitMQ已有用户Listing users ...usertagsguest [administrator][root@Services ~]# rabbitmqctl add_user admin #添加admin用户Adding user "admin" ...Password: hisadmin#密码必须设置为hisadmin,为后续项目使用Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.[root@Services ~]# rabbitmqctl list_users #列出RabbitMQ已有用户Listing users ...usertagsadmin []guest [administrator][root@Services ~]# 用户标签管理#RabbitMQ用户标签解析 #超级管理员(administrator)#可登陆管理控制台,可查看所有的信息,并且可以对用户,策略(policy)进行操作。#监控者(monitoring)#可登陆管理控制台,同时可以查看rabbitmq节点的相关信息(进程数,内存使用情况,磁盘使用情况等)#策略制定者(policymaker)#可登陆管理控制台, 同时可以对policy进行管理。但无法查看节点的相关信息(上图红框标识的部分)。#普通管理者(management)#仅可登陆管理控制台,无法看到节点信息,也无法对策略进行管理。#其他(guest)#无法登陆管理控制台,通常就是普通的生产者和消费者#给admin用户添加administrator标签[root@Services ~]# rabbitmqctl set_user_tags admin administratorSetting tags for user "admin" to [administrator] ...[root@Services ~]# rabbitmqctl list_usersListing users ...usertagsadmin [administrator]guest [administrator][root@Services ~]#
#创建/his虚拟主机[root@Services ~]# rabbitmqctl list_vhosts#列出已有虚拟主机Listing vhosts ...name/[root@Services ~]# rabbitmqctl add_vhost /his #创建/his虚拟主机,后续项目使用Adding vhost "/his" ...[root@Services ~]# rabbitmqctl list_vhosts#列出已有虚拟主机Listing vhosts ...name/his/[root@Services ~]#设置用户访问虚拟主机权限#设置admin用户对/his虚拟主机有所有权限[root@Services ~]# rabbitmqctl list_user_permissions admin#查看admin用户权限Listing permissions for user "admin" ...[root@Services ~]# rabbitmqctl set_permissions -p /his admin ".*" ".*" ".*" #设置权限Setting permissions for user "admin" in vhost "/his" ...[root@Services ~]# rabbitmqctl list_user_permissions admin#查看admin用户权限Listing permissions for user "admin" ...vhost configure write read/his.*.*.*[root@Services ~]#