当前位置:网站首页>Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting
Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting
2022-07-01 08:38:00 【Say yes, say yes】
The following scripts are original , Summed up in actual work !
One 、 initialization
Install common commands , image ifconfig、zip、unzip、wget、vim、yum-plugin-downloadonly
#!/usr/bin/env bash
set -e
# Replace yum Source , Reference resources [centos Mirror image -centos Download address -centos Installation tutorial - Alibaba open source mirror site ](https://developer.aliyun.com/mirror/centos)
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# Basics repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# spare repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# Empty old cache 、 Generate new cache
yum clean all
yum makecache
yum -y install net-tools vim zip unzip wget yum-plugin-downloadonly
echo " Replace yum base、epel The source is Ali repo"
echo " Install common tools "
Two 、 One click script
2.1 vsftpd
A key to install vsftpd
#!/usr/bin/env bash
# install vsftp
installVsftpd() {
yum -y install vsftpd ftp
status=$?
if [ ${status} != 0 ]; then
echo " Please check whether you can connect to the network or Can I connect to yum Warehouse or Forced exit "
exit 1
fi
# > Indicates coverage >> Indicates append
cat >> /etc/vsftpd/vsftpd.conf <<EOF
#FTP Access directory
local_root=/data/ftp/
# Configuration can only access the specified directory ,chroot_list Users listed in the file , You can switch to another directory ; Users not listed in the file , Cannot switch to another directory .
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
allow_writeable_chroot=YES
# Configure time zone
use_localtime=YES
EOF
mkdir -p /etc/vsftpd/chroot_list
mkdir -p /data
useradd -d /data/ftp/ ftpadmin
chown -R ftpadmin /data/ftp
systemctl restart vsftpd
echo "vsftpd Installation successful "
echo " adopt systemctl [status|start|stop|restart|enable|disable] vsftpd To operate "
echo " Successfully created user ftpadmin, adopt passwd ftpadmin Configure the password "
}
# close selinux
disableSeLinux(){
# -s file The file size is not 0 Time is true
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
# take SELINUX=enforcing Replace with SELINUX=disabled
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo " close selinux"
fi
}
ls /usr/lib/systemd/system/vsftpd.service
status=$?
# 0 Indicates that the service has been found Not 0 It means there is no service Judge equality with spaces
if [ $status == 0 ]; then
echo "vsftpd Installation successful "
echo " adopt systemctl [status|start|stop|restart|enable|disable] vsftpd To operate "
else
disableSeLinux
installVsftpd
fi
Then use the following command , Configure a password .
passwd ftpadmin
Then you can connect directly .
# Connect
ftp 127.0.0.1
# Upload
put Local files Remote files
2.2 openjdk
A key to install jdk11
#!/user/bin/env bash
set -e
# install jdk Parameter is jdk edition
function installJdk() {
yum -y install java-$1-openjdk java-$1-openjdk-devel
cat > /etc/profile.d/java$1.sh <<EOF
# readlink Read javac Soft connection , Then read the soft connection to get the real link , Then go to the superior directory twice , Go once yes java/bin, Another walk is java
export JAVA_HOME=\$(dirname \$(dirname \$(readlink \$(readlink \$(which javac)))))
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar
EOF
# Refresh environment variable
source /etc/profile.d/java$1.sh
java -version
javac -version
echo $JAVA_HOME
}
echo " Optional java-openJdk Version as follows :"
echo "java-1.8.0-openjdk 1"
echo "java-11-openjdk 2"
printf " Enter what you want to install openJdk edition "
# Read keyboard input information
read -p "(Default: 1):" select
# Default assignment
[ -z "${select}" ]&&select=1
# Judge options
if [ "${select}" == 1 ];then
select="1.8.0"
else
select="11"
fi
installJdk ${
select}
2.3 mongo
A key to install mongo4.4.14
#!/usr/bin/env bash
set -e
# > Full coverage write \ You can escape
cat > /etc/yum.repos.d/mongodb-org-4.4.repo <<EOF
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
EOF
yum install -y mongodb-org-4.4.14 mongodb-org-server-4.4.14 mongodb-org-shell-4.4.14 mongodb-org-mongos-4.4.14 mongodb-org-tools-4.4.14
if [ -s /etc/mongod.conf ] && grep '127.0.0.1' /etc/mongod.conf; then
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mongod.conf
fi
systemctl restart mongod
echo "=================================================================================================================================="
echo "mongo The database has been started , Command line input mongo Can connect "
2.4 kafka
A key to install kafka
#!/usr/bin/env bash
set -e
# Get LAN ip The value of the existing function is $(getIp)
function getIp() {
ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"
}
# download kafka
function downKafka() {
wget --no-check-certificate http://mirrors.ustc.edu.cn/apache/kafka/3.2.0/kafka_2.13-3.2.0.tgz -O kafka.tgz
}
# decompression kafka
function decompressKafka() {
if [ -s $1 ]; then
tar -zxvf kafka.tgz > tar.log
cat tar.log|head -n 1|tr -d "/"
fi
}
# initialization kafka To configure
function initKafkaConfig() {
if [ -s $1 ]&&grep "localhost" $1 ; then
sed -i "s/localhost/$(getIp)/g" $1
echo "kafka Monitor address :$(getIp):9092"
fi
}
# establish shell Script
function createShell() {
# The value of existing function variables is $(), Custom variable values are used ${}
cat > ${root}/kafka-start <<EOF
${root}/$1/bin/kafka-storage.sh format -t T1CYXg2DQPmdSYSUI-FNFw -c ${root}/$1/config/kraft/server.properties
nohup ${root}/$1/bin/kafka-server-start.sh ${root}/$1/config/kraft/server.properties >kafka-without-zk.log 2>&1 &
echo "kafka start-up pid:$$ kafka The execution log is saved in kafka-without-zk.log"
EOF
chmod +x ${root}/kafka-start
echo " Start command : sh ${root}/kafka-start "
cat > ${root}/kafka-stop <<EOF
${root}/$1/bin/kafka-server-stop.sh -c ${root}/$1/config/kraft/server.properties
EOF
chmod +x ${root}/kafka-stop
echo " The shutdown command : sh ${root}/kafka-stop"
}
root=$(pwd)
downKafka
kafkaPackage=$(decompressKafka "${root}/kafka.tgz")
initKafkaConfig "${root}/${kafkaPackage}/config/kraft/server.properties"
createShell "${kafkaPackage}"
2.5 postgresql
A key to install psql
#!/usr/bin/env bash
set -e
# install postgis
function installPostGis() {
yum -y install epel-release
yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum -y install postgis30_11
}
# install pgRouting
function installPgRouting() {
yum -y install pgrouting_11 osm2pgrouting_11
}
# install postgresql
function installPsql() {
# install RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# install PostgreSQL:
sudo yum install -y postgresql11-server
# Initialize the database and set the boot auto start
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl enable postgresql-11
# Turn on Remote Access
psqlConf="/var/lib/pgsql/11/data/postgresql.conf"
if [ -s ${psqlConf} ];then
cat >> ${psqlConf} <<EOF
# Turn on postgresql Is remotely accessible
listen_addresses = '*'
EOF
else
echo "psql There is no such profile ${psqlConf}, Maybe the script is no longer applicable !"
echo " The greatest thing about cannon is that he can achieve his perfection !"
exit 1
fi
pghbaConf="/var/lib/pgsql/11/data/pg_hba.conf";
if [ -s ${pghbaConf} ]; then
cat >> ${pghbaConf} <<EOF
host all all 0.0.0.0/0 md5
EOF
else
echo "psql There is no such profile ${pghbaConf}, Maybe the script is no longer applicable !"
echo " The greatest thing about cannon is that he can achieve his perfection !"
exit 1
fi
sudo systemctl restart postgresql-11
}
echo " Optional installations are as follows :"
echo "postgresql 1"
echo "postgis 2"
echo "pgrouting 3"
# Read keyboard input information
printf " Enter what you want to install , Do not select input n"
read -p "(Default: n):" select
# Default assignment
[ -z "${select}" ]&&select="n"
# install
# Judge options
case ${select} in
"n")
echo " Don't install this time "
exit 0
;;
"1")
echo " This installation postgresql"
installPsql
;;
"2")
echo " This installation postgis"
installPostGis
;;
"3")
echo " This installation pgrouting"
installPgRouting
;;
esac
2.6 history Display time
Add environment variables temporarily history Take time
export HISTTIMEFORMAT='%F %T '
Temporarily cancel environment variables
unset HISTTIMEFORMAT
View environment variables
env
3、 ... and 、 thank
shell in set Instruction usage _ Cao Huihui's blog -CSDN Blog _set shell
fengyuhetao/shell: Linux Command line and shell Script programming complete case
hi-dhl/fast_guides: 10 Minute introduction Shell scripting
stay IDEA To write Shell Script _1024GB The blog of -CSDN Blog _idea To write shell Script
Linux shell conditional if Medium -a To -z It means - Simple books
shell local command _qq_28391549 The blog of -CSDN Blog _local command
shell Order tr_ Not a lever blog -CSDN Blog _shell command tr
linux shell in ’',"" and `` The difference between Actually `` Follow $() It works the same
liunx How to delete export Set environment variables _weixin_33775582 The blog of -CSDN Blog
history Command with time display - Simple books
Linux Shell case sentence _zh521zh The blog of -CSDN Blog
Linux shell Script ( Twelve )case sentence _ Green soya beans 1113 The blog of -CSDN Blog
边栏推荐
- 基于Gazebo的无人机管道检测
- 深度学习训练样本扩增同时修改标签名称
- Provincial selection + noi Part II string
- Anddroid text to speech TTS implementation
- DID的使用指南,原理
- 如何招到适合自己店铺的淘宝主播
- What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength
- How to use OKR as the leadership framework of marketing department
- 挖财打新股安全吗
- P4 installation bmv2 detailed tutorial
猜你喜欢
shardingSphere
The era of low threshold programmers is gone forever behind the sharp increase in the number of school recruitment for Internet companies
NIO-零拷贝
公网集群对讲+GPS可视追踪|助力物流行业智能化管理调度
CPU design practice - Chapter 4 practical tasks - simple CPU reference design and debugging
Audio audiorecord create (I)
What is the material of 15CrMoR, mechanical properties and chemical analysis of 15CrMoR
Model and view of QT
【无标题】
"Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis
随机推荐
1.jetson与摄像头的对接
Embedded-c language-10-enumeration / (function) pointer (function) / multi-level pointer /malloc dynamic allocation / file operation
To prevent "activation" photos from being muddled through, databao "live detection + face recognition" makes face brushing safer
Audio audiorecord create (I)
2022 examination summary of quality controller civil engineering direction post skills (quality controller) and reexamination examination of quality controller civil engineering direction post skills
C语言指针的进阶(上篇)
3、Modbus通讯协议详解
Matlab tips (23) matrix analysis -- simulated annealing
Provincial selection + noi Part II string
【js逆向】md5加密参数破解
Provincial election + noi part I dynamic planning DP
Centos7 shell脚本一键安装jdk、mongo、kafka、ftp、postgresql、postgis、pgrouting
嵌入式工程师常见面试题2-MCU_STM32
MD文档中插入数学公式,Typora中插入数学公式
Leetcode t40: combined sum II
Agrometeorological environment monitoring system
《单片机原理及应用》-片外拓展
【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】
手工挖XSS漏洞
我想知道手机注册股票开户的流程?另外,手机开户安全么?