当前位置:网站首页>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
边栏推荐
- 【js逆向】md5加密参数破解
- Glitch Free时钟切换技术
- 《单片机原理及应用》-片外拓展
- SPL-介绍(一)
- Matlab tips (23) matrix analysis -- simulated annealing
- Yolov5 advanced six target tracking environment construction
- Model and view of QT
- Download jackson codehaus. org jar - downloading jackson. codehaus. org jar
- factory type_id::create过程解析
- [Yu Yue education] Shandong Vocational College talking about railway reference materials
猜你喜欢

为什么LTD独立站就是Web3.0网站!

CPU設計實戰-第四章實踐任務一簡單CPU參考設計調試

factory type_id::create过程解析

Only in China! Alicloud container service enters the Forrester leader quadrant

明明设计的是高带宽,差点加工成开路?

Audio audiorecord create (I)

2022.2.15

MAVROS发送自定义话题消息给PX4
![[detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]](/img/0f/972cde8c749e7b53159c9d9975c9f5.png)
[detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]

分享2022上半年我读过的7本书
随机推荐
The data analyst will be ruined without project experience. These 8 project resources will not be taken away
SPL-安装与基本使用(二)
Matlab [function derivation]
性能提升2-3倍!百度智能云第二代昆仑芯服务器上线
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
R语言入门
[deep analysis of C language] - data storage in memory
Vscode customize the color of each area
shardingSphere
1.jetson与摄像头的对接
Manually dig XSS vulnerabilities
TypeError: __init__() got an unexpected keyword argument ‘autocompletion‘
NFT监管要点和海外政策
[Yu Yue education] Shandong Vocational College talking about railway reference materials
华为机试真题专栏订阅指引
MATLAB小技巧(16)矩阵特征向量特征值求解一致性验证--层次分析
factory type_id::create过程解析
NIO-零拷贝
What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength
yolov5训练可视化指标的含义