有哪些网站可以做seo推广,阿里巴巴官网网址是多少,网页小游戏手机版,凡客诚品登录系列文章目录 
rpmbuild从入门到放弃 search-guard插件使用入门手册 文章目录 系列文章目录前言一、资源准备二、spec文件1.基础信息2.%prep3.%Install4.%file5.%post6.%postun 三、成果演示1.执行构建过程图示例2.执行安装RPM包示例3.进程检查4.访问esApi 总结 前言 
不管是源…系列文章目录 
rpmbuild从入门到放弃 search-guard插件使用入门手册 文章目录 系列文章目录前言一、资源准备二、spec文件1.基础信息2.%prep3.%Install4.%file5.%post6.%postun 三、成果演示1.执行构建过程图示例2.执行安装RPM包示例3.进程检查4.访问esApi 总结 前言 
不管是源码安装elasticsearch还是通过elastic官网的rpm包进行安装,在安装完成后都需要进行手动配置elastic的安全认证,这样不管从安装效率还是维护都比较麻烦,为了让安装和开启鉴权一起完成本篇文章就使用rpmbuild自行构建elasticsearch-7.14.2的RPM包,安全认证插件使用的是search-guard,具体构建方式看下方文章即可。阅读下方文章前请先阅读顶部的两章链接文件,先对整体知识有个大体上的了解。 提示已在本地centos 7环境执行过构建测试、安装、使用流程,目前未发现异常 
一、资源准备 1、rpmbuild工具安装此处不再描述,详情查看顶部文章链接即可2、下载elasticsearch-7.14.2的tar包[rootpython2 SOURCES]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.2-linux-x86_64.tar.gz3、下载elasticsearch版本对应的search-guard插件[rootpython2 SOURCES]# wget https://maven.search-guard.com/search-guard-suite-release/com/floragunn/search-guard-suite-plugin/7.14.2-52.3.0/search-guard-suite-plugin-7.14.2-52.3.0.zip[rootpython2 SOURCES]# https://docs.search-guard.com/latest/search-guard-installation至此源码包准备完成,下面开始编写spec文件 
二、spec文件 
1.基础信息 文件如下示例 #自定义宏相当于Linux中Key-Value变量形式
#---名称
%define Name elasticsearch
#---版本
%define Version 7.14.2
#---本rpm包中需更换的配置文件#---本rpm包默认安装的路径
%define InstallPath /export/server/elasticsearch-7.14.2
#--rpm包封装进去的脚本
%define configYaml elasticsearch.yml
%define search_guard  search-guard-suite-plugin-7.14.2-52.3.0.zip
%define search_tlstools search-guard-tlstool-1.7.tar.gz
%define __spec_install_post %{nil}
%define _build_id_links none
# 软件包的名称 
Name: %{Name}
# 软件包的版本 
Version: %{Version}
# 软件包发布序列号1表示第几次打包 %{?dist} 会再包名中添加操作系统系统
Release: 1
# 软件包的概要信息不要超过50个 
# 软件授权方式 
License: BSD# 软件分类
Group: System Middleware
# 源代码软件包的官方地址或源码包的下载地址 
URL: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.2-linux-x86_64.tar.gzSummary: The elasticsearch for centos 7.14.2 x86_64.
# 源代码软件包的名字 
Source0: %{Name}-%{Version}-linux-x86_64.tar.gz
Source3: %{configYaml}
Source4: %{search_guard}
Source5: %{search_tlstools}# install使用的虚拟目录安装后就在该目录下打包 
AutoReqProv: no
#制作过程中用到的软件包
Requires: bash#软件包详细描述信息 
%description
This is %{Name}2.%prep 
解压源码包部分 如下示例 
# 安装前的准备工作一般用于解压源码包
%prep
#解压并cd到相关目录  tar xf SOURCES/xxx.tar.gz -C BUILD  cd BUILD
%setup -q -n elasticsearch-7.14.2  #-q 静默 不输出信息  -n 指定解压后的名称3.%Install 
此部分主要用于解压后的源码安装及目录创建等工作 在该文件中主要实现目录创建、search-guard插件的安装及密钥文件的创建工作,并将准备好的文件和目录拷贝到BUILDROOT目录下 
# 源码安装
#目前还是在/export/rpmbuild/BUILD/目录中执行以下操作
#rm -rf /export/rpmbuild/BUILDROOT
%install
%{_rm} -rf %{buildroot} # 清理之前的安装
mkdir -p /tmp/search-guard-tlstool
tar -zxvf %{SOURCE5} -C /tmp/search-guard-tlstool
cd /tmp/search-guard-tlstool/config/  cp example.yml tlsconfig.yml
sed -i /^#/d; /^$/d tlsconfig.yml
sed -i /root\.ca\.example\.com/c\      dn: CNroot.ca.com.local,OUCA,Ocom,DCcom,DClocal tlsconfig.yml
sed -i /signing\.ca\.example\.com/c\      dn: CNroot.ca.com.local,OUCA,Ocom,DCcom,DClocal tlsconfig.yml
sed -i s/#nodesDn/nodesDn/ tlsconfig.yml
sed -i s/#- CN\*.example.com,OUOps,OExample Com\\\\, Inc.,DCexample,DCcom/- CN\*.com.local,OUOps,Ocom,DCcom,DClocal/ tlsconfig.yml
sed -i s/# nodeOid: 1.2.3.4.5.5/nodeOid: 1.2.3.4.5.5/ tlsconfig.yml
sed -i 88,99d tlsconfig.yml
sed -i s/- name: node1/- name: esnode/ tlsconfig.yml
sed -i /dn: CNnode1\.example\.com*/c\    dn: CNesnode.com.local,OUOps,Ocom,DCcom,DClocal tlsconfig.yml
sed -i s/dns: node1.example.com/dns: esnode/ tlsconfig.yml
sed -i /dn: CNspock\.example\.com/c\    dn: CNspock.com.local,OUOps,Ocom,DCcom,DClocal tlsconfig.yml
sed -i /dn: CNkirk\.example\.com/c\    dn: CNkirk.com.local,OUOps,Ocom,DCcom,DClocal tlsconfig.yml
sed -i s/pkPassword: auto/pkPassword: none/ tlsconfig.yml
cd /tmp/search-guard-tlstool/tools/
./sgtlstool.sh -c ../config/tlsconfig.yml -ca
./sgtlstool.sh -c ../config/tlsconfig.yml -crt
cd out/  chmod 644 root-ca.* signing-ca.* esnode* kirk.*
mkdir -p %{buildroot}%{InstallPath}/plugins/search-guard-7
mkdir -p %{buildroot}%{InstallPath}/{modules,logs,data,lib,config,bin}
cp -rp /tmp/search-guard-tlstool/tools/out/{root-ca.pem,kirk.pem,kirk.key,esnode.pem,esnode.key} %{buildroot}%{InstallPath}/config# 复制自定义的或额外的配置文件和脚本
unzip %{SOURCE4} -d %{buildroot}%{InstallPath}/plugins/search-guard-7/
cp -rp %{_builddir}/%{Name}-%{Version}/* %{buildroot}%{InstallPath}/
rm -rf %{buildroot}%{InstallPath}/jdk4.%file 
主要用于安装后目录下都包含哪些文件或子目录 
%files
%defattr(-,elasticsearch,elasticsearch,-)
%dir %{InstallPath}
%dir %{InstallPath}/bin
%dir %{InstallPath}/config
%dir %{InstallPath}/lib
%dir %{InstallPath}/logs
%dir %{InstallPath}/data
%dir %{InstallPath}/modules
%dir %{InstallPath}/plugins
%{InstallPath}/bin/*
%{InstallPath}/config/*
%{InstallPath}/lib/*
%{InstallPath}/modules/*
%{InstallPath}/plugins/*
%{InstallPath}/NOTICE.txt
%{InstallPath}/LICENSE.txt
%{InstallPath}/README.asciidoc5.%post 
主要用于安装rpm后做的相关操作,比如启动进程、创建用户等工作。在此文件中该部分主要用于替换elasticsearch.yml文件、授权、设置所需要的内核参数、初始化search-guard插件并重置es密码 
%post
#!/bin/sh
cat %{InstallPath}/config/elasticsearch.ymlEOF
cluster.name: cityosnode.name: wangyingkai-test-01path.data: %{InstallPath}/data
path.logs: %{InstallPath}/logs
# Lock the memory on startup:
#bootstrap.memory_lock: true
network.host: $local_ip
http.port: 9200discovery.seed_hosts: [$local_ip]
cluster.initial_master_nodes: [$local_ip]
#discovery.zen.minimum_master_nodes:#gateway.recover_after_nodes: 3# Search Duard Configure
action.auto_create_index: true
node.master: true
node.data: true
searchguard.ssl.transport.pemcert_filepath: esnode.pem
searchguard.ssl.transport.pemkey_filepath: esnode.key
searchguard.ssl.transport.pemtrustedcas_filepath: root-ca.pem
searchguard.ssl.transport.enforce_hostname_verification: false
searchguard.ssl.transport.resolve_hostname: false
searchguard.authcz.admin_dn:
- CNkirk.com.local,OUOps,Ocom,DCcom,DClocal
searchguard.cert.oid: 1.2.3.4.5.5
EOF# edit config file 修改yml文件
sed -i s/node.name:.*/node.name: $local_ip/g %{InstallPath}/config/elasticsearch.yml# useradd elasticsearch 创建用户
id elasticsearch  /dev/null 21
if [ $?  0 ];thenecho elasticsearch user exist.
elseuseradd -s /sbin/nologin elasticsearch
fi#chown 设置目录权限
chown -R elasticsearch:elasticsearch %{InstallPath}#设置kernel参数
if ! grep -w fs.file-max /etc/sysctl.conf |grep -v ^# /dev/null
thensed -i $a\\nfs.file-max  65536 /etc/sysctl.conf
fiif ! grep -w vm.max_map_count /etc/sysctl.conf |grep -v ^#  /dev/null
thensed -i $a\\nvm.max_map_count  262144 /etc/sysctl.conf
fi
sysctl -p  /dev/null
# 启动 Elasticsearch 服务
su elasticsearch -c %{InstallPath}/bin/elasticsearch -d -p %{InstallPath}/%{Name}.pid
# 等待 Elasticsearch 启动,修改密码
until curl -s http://$local_ip:9200  /dev/null; doecho Waiting for Elasticsearch to start...sleep 10
done# 生成哈希密码并更新配置文件
HASHED_PASSWORD$(%{InstallPath}/plugins/search-guard-7/tools/hash.sh -p 0gvzJr66iNs5)
# 转义特殊字符
ESCAPED_HASHED_PASSWORD$(echo $HASHED_PASSWORD | sed s/[\/]/\\/g)
# 更新 sg_internal_users.yml 文件
if [ -n $ESCAPED_HASHED_PASSWORD ]; thensed -i s/^  hash: .*/  hash: $ESCAPED_HASHED_PASSWORD/ %{InstallPath}/plugins/search-guard-7/sgconfig/sg_internal_users.ymlsed -i s/\r//g %{InstallPath}/plugins/search-guard-7/sgconfig/sg_internal_users.yml
fi#修改完配置文件并执行初始化
cd %{InstallPath}/plugins/search-guard-7/tools  sh sgadmin.sh -h $local_ip -cd ../sgconfig -key ../../../config/kirk.key -cert ../../../config/kirk.pem -cacert ../../../config/root-ca.pem -nhnv -icl6.%postun 
这部分主要用于卸载后需要做的任务比如:删除目录等任务工作,在该spec文件中这部分主要用于根据pid是否存在停止程序、删除目录完成相应的卸载工作 
%postun -p /bin/sh
#!/bin/bash
PID_FILE%{InstallPath}/%{Name}.pid
DIR_TO_REMOVE%{InstallPath}# Check if the PID file exists and read the PID from it
if [ -f $PID_FILE ]; thenPID$(cat $PID_FILE)# Check if a process with the given PID existsif ps -p $PID  /dev/null 21; then# Kill the process with the PID found in the PID filekill $PID# Wait a moment to allow the process to terminatesleep 1fi# Remove the PID filerm -f $PID_FILE
fi# Remove the directory
rm -rf $DIR_TO_REMOVE三、成果演示 
1.执行构建过程图示例 2.执行安装RPM包示例 3.进程检查 4.访问esApi 总结 
通过完成本篇文章已经对rombuild有了60%的理解和使用,熟能生巧希望也对大家的实际工作能起到帮助作用。加油!!!