#!/bin/bash
# install date
START_TIME='date +"%Y-%m-%d %H:%M:%S"'
#output
echo_yellow() {
echo -e "\e[93m$1\e[0m"
}
YEARNING_VERSION="3.1.7"
DOWNLOAD_URL="https://github.com/cookieY/Yearning/releases/download/v${YEARNING_VERSION}"
#https://github.com/cookieY/Yearning/releases/download/v3.1.7/Yearning-v3.1.7-linux-amd64.zip
FILE="Yearning-v${YEARNING_VERSION}-linux-amd64.zip"
DATA_DIR="/usr/local/Yearning"
# get mysql instance name & port
echo -n "please input Mysql instance (default 127.0.0.1) :"
read -r MYSQL_IP
MYSQL_IP=${MYSQL_IP:-127.0.0.1}
echo_yellow "MySQL Instance: ${MYSQL_IP}"
echo -n "please input MySQL port (default 3366) :"
read -r MYSQL_PORT
MYSQL_PORT=${MYSQL_PORT:-3366}
echo_yellow "MySQL PORT: ${MYSQL_PORT}"
#USER & PASSWORD
echo -n "please input MySQL root right :"
read -r MYSQL_ROOT
MYSQL_ROOT=${MYSQL_ROOT:-N}
while [ $MYSQL_ROOT == "N" ]
do
echo -n "please input MySQL root right user :"
read -r MYSQL_ROOT
done
echo -n "please input MySQL root password:"
read -s MYSQL_PW
MYSQL_PW=${MYSQL_PW:-N}
while [$MYSQL_PW == "N" ]
do
echo -n "please input MySQL root right PASSWORD:"
read -s MYSQL_PW
done
echo""
echo -n "please input Yearning user IP (default 127.0.0.1) :"
read -r YEARNING_LOGIN_IP
YEARNING_LOGIN_IP=${YEARNING_LOGIN_IP:-127.0.0.1}
echo_yellow "Yearning user login IP: ${YEARNING_LOGIN_IP}"
echo -n "please input Yearning user:"
read -r YEARNING_ACCOUNT
YEARNING_ACCOUNT=${YEARNING_ACCOUNT:-N}
while [ $YEARNING_ACCOUNT == "N" ]
do
echo -n "please input Yearning user :"
read -r YEARNING_ACCOUNT
done
echo_yellow "Yearning login user : ${YEARNING_ACCOUNT}"
echo -n "please input Yearning password :"
read -r YEARNING_PW
YEARNING_PW=${YEARNING_PW:-N}
while [ $YEARNING_PW == "N" ]
do
echo -n "please input Yearning user password :"
read -r YEARNING_PW
done
# download package
if [ ! -f "/opt/${FILE}" ]; then
echo_yellow "begin download package..."
wget ${DOWNLOAD_URL}/${FILE} -P /opt/
fi
# Install Yearning
echo_yellow "install Yearning..."
unzip -o /opt/${FILE} -d /usr/local
echo_yellow "Yearning install complete..."
# Install MySQL Client
echo_yellow "install MySQL Client..."
if [ ! -f /opt/MySQL-client-5.1.73-1.glibc23.x86_64.rpm ]; then
wget https://downloads.mysql.com/archives/get/p/23/file/MySQL-client-5.1.73-1.glibc23.x86_64.rpm -P /opt/
fi
yum install -y /opt/MySQL-client-5.1.73-1.glibc23.x86_64.rpm
echo_yellow "MySQL Client Install complete..."
# increase srver archive
cat >${DATA_DIR}/Yearning_start.sh <<EOF
#!/bin/bash
${DATA_DIR}/Yearning_stop.sh &
${DATA_DIR}/Yearning run -c ${DATA_DIR}/conf.toml 2>&1 &
EOF
chmod 755 ${DATA_DIR}/Yearning_start.sh
#Increase server stop archive
cat >${DATA_DIR}/Yearning_stop.sh <<EOF
#!/bin/bash
PID='losf -n -i :8000 | tail -n 1 | awk '{print $2}'';
kill -9 $PID
EOF
chmod 755 ${DATA_DIR}/Yearning_stop.sh
mv ${DATA_DIR}/conf.toml ${DATA_DIR}/conf.toml_bak
cat >${DATA_DIR}/conf.toml <<EOF
[Mysql]
Db = "yearning"
Host = "${MYSQL_IP}"
Port = "${MYSQL_PORT}"
Password = "${YEARNING_PW}"
User = "${YEARNING_ACCOUNT}"
[General]
SecretKey = "dbcjqheupqjsuwsm"
Hours = 4
QueryClient = true
QueryPort = 3307
LogLevel = "info" # debug,info,warn,error
Lang = "zh_CN" # en_US,zh_CN
[Oidc]
Enable = false
ClientId = "yearning"
ClientSecret = "fefehelj23jlj22f3jfjdfd"
Scope = "openid profile"
AuthUrl = "https://keycloak.xxx.ca/auth/realms/master/protocol/openid-connect/auth"
TokenUrl = "https://keycloak.xxx.ca/auth/realms/master/protocol/openid-connect/token"
UserUrl = "https://keycloak.xxx.ca/auth/realms/master/protocol/openid-connect/userinfo"
RedirectUrL = "http://127.0.0.1:8000/oidc/_token-login"
UserNameKey = "preferred_username"
RealNameKey = "name"
EmailKey = "email"
SessionKey = "session_state"
EOF
# Yearning service configure
cat >/usr/lib/systemd/system/yearning.service <<EOF
[Unit]
Description=Yearning Server
Documentation=https://guide.yearning.io/version.html
After=network.target
After=syslog.target
After=local-fs.target remote-fs.target
[Service]
Type=forking
User=root
Group=root
ExecStart=${DATA_DIR}/Yearning_start.sh -daemon 2>&1
ExecStop=${DATA_DIR}/Yearning_stop.sh
LimitNOFILE=1024000
LimitMEMLOCK=65536
[Install]
WantedBy=multi-user.target
Alias=yearning.service
EOF
# THE USER CREATE FILE FLODER
cat >/tmp/yearning_createuser.sql <<EOF
CREATE DATABASE yearning;
CREATE USER '${YEARNING_ACCOUNT}'@'${YEARNING_LOGIN_IP}' IDENTIFIED BY '${YEARNING_PW}' ;
GRANT ALL ON *.* TO '${YEARNING_ACCOUNT}'@'${YEARNING_LOGIN_IP}' WITH GRANT OPTION;
EOF
# EXEC THE USER CREATE FILE FOLDER
echo_yellow "begin create user SQL file ..."
mysql -h ${MYSQL_IP} -P ${MYSQL_PORT} -u ${MYSQL_ROOT} -p${MYSQL_PW} < /tmp/yearning_createuser.sql 2>/dev/null
rm -rf /tmp/yearning_createuser.sql
echo_yellow "the user create sql complete."
# initial Yearning
echo_yellow "initial Yearning..."
cd ${DATA_DIR};
./Yearning install
echo_yellow "initial Yearning complete."
# enable Yearning service
echo_yellow "begin start Yearning service..."
systemctl daemon-reload
systemctl start yearning.service
systemctl enable yearning.service >/dev/null 2>&1
systemctl status yearning.service
echo_yellow "Yearning service starting complete."
#install complete date
END_TIME='date +"%Y-%m-%d %H:%M:%S"'
# OUTPUT INFORMATION
echo""
echo""
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "++++++++++++++++++++++Yearning service install configure +++++++++++++++"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo_yellow "begin install date: ${START_TIME}"
echo_yellow "complete date: ${END_TIME}"
echo_yellow "Yearning server ip: ${YEARNING_LOGIN_IP}"
echo_yellow "Yearning port: 8000"
echo_yellow "Yearning (Account): ${YEARNING_ACCOUNT}"
echo_yellow "Yearning (Password): ${YEARNING_PW}"
echo_yellow "MySQL SERVER IP: ${MYSQL_IP}"
echo_yellow "MySQL SERVER Port: ${MYSQL_PORT}"
echo_yellow "Yearning version: ${YEARNING_VERSION}"
echo""
install yearing
于 2024-05-11 15:17:35 首次发布