update docs and scripts

pull/11/head
Zhang Peng 2020-04-03 15:15:02 +08:00
parent db7bccdc68
commit 097cfb45ef
31 changed files with 634 additions and 388 deletions

View File

@ -59,8 +59,8 @@
- [Nodejs 安装](docs/linux/soft/nodejs-install.md)
- 开发工具
- [Nexus 运维](docs/linux/soft/nexus-ops.md)
- [Gitlab 运维](docs/linux/soft/kafka-install.md)
- [Jenkins 运维](docs/linux/soft/jenkins.md)
- [Gitlab 运维](docs/linux/soft/gitlab-ops.md)
- [Jenkins 运维](docs/linux/soft/jenkins-ops.md)
- [Svn 运维](docs/linux/soft/svn-ops.md)
- [YApi 运维](docs/linux/soft/yapi-ops.md)
- 中间件服务

View File

@ -1,154 +0,0 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------------------------------
# 数据库操作脚本
# @author Zhang Peng
# -----------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ 1. env
## 数据库IP
#ENV_MYSQL_HOST="127.0.0.1"
## 数据库用户名
#ENV_MYSQL_USERNAME="root"
## 数据密码
#ENV_MYSQL_PASSWORD="Tw#123456"
if [[ ! ${ENV_MYSQL_HOST} ]] || [[ ! ${ENV_MYSQL_USERNAME} ]] || [[ ! ${ENV_MYSQL_PASSWORD} ]]; then
logError "执行本脚本前必须先 export 环境变量: ENV_MYSQL_HOST, ENV_MYSQL_USERNAME, ENV_MYSQL_PASSWORD."
exit ${ENV_FAILED}
fi
# 备份模式:备份所有数据库(--all-databases|备份指定数据库列表
MYSQL_DATABASES="${ENV_MYSQL_DATABASES:---all-databases}"
#备份路径
MYSQL_BACKUP_DIR="${ENV_MYSQL_BACKUP_DIR:-/var/lib/mysql/backup}"
#备份日志路径
export ENV_LOG_PATH="${MYSQL_BACKUP_DIR}/mysql-backup.log"
# ------------------------------------------------------------------------------ 2. libs
# 装载其它库
LINUX_SCRIPTS_LIB_DIR=`dirname ${BASH_SOURCE[0]}`
if [[ ! -x ${LINUX_SCRIPTS_LIB_DIR}/utils.sh ]]; then
logError "${LINUX_SCRIPTS_LIB_DIR}/utils.sh not exists!"
exit 1
fi
source ${LINUX_SCRIPTS_LIB_DIR}/utils.sh
# ------------------------------------------------------------------------------ 3. global var
# 备份文件最大数量
BACKUP_ARTIFACTS_MAX_NUM=7
# ------------------------------------------------------------------------------ 4. functions
backupAllDatabase() {
#时间戳
local timestamp=$(date +"%Y%m%d")
#备份所有数据库
logInfo "正在备份所有数据库"
mysqldump -h ${ENV_MYSQL_HOST} -P${ENV_MYSQL_PORT} -u${ENV_MYSQL_USERNAME} -p${ENV_MYSQL_PASSWORD} --all-databases > "${MYSQL_BACKUP_DIR}/all-${timestamp}.sql" 2>> ${ENV_LOG_PATH};
#检查备份结果是否成功
if [[ "$?" != 0 ]]; then
logError "<<<< 备份所有数据库失败"
return ${ENV_FAILED}
fi
# 压缩备份sql文件删除旧的备份文件
cd "${MYSQL_BACKUP_DIR}"
if [[ ! -f "${MYSQL_BACKUP_DIR}/all-${timestamp}.sql" ]]; then
logError "备份文件 ${MYSQL_BACKUP_DIR}/all-${timestamp}.sql 不存在"
return ${ENV_FAILED}
fi
#为节约硬盘空间,将数据库压缩
sudo tar zcf "all-${timestamp}.tar.gz" "all-${timestamp}.sql" > /dev/null
#删除原始文件,只留压缩后文件
sudo rm -f "all-${timestamp}.sql"
#删除七天前备份也就是只保存7天内的备份
find "${MYSQL_BACKUP_DIR} -name all-*.tar.gz -type f -mtime +${BACKUP_ARTIFACTS_MAX_NUM} -exec rm -rf {} \;" > /dev/null 2>&1
logInfo "<<<< 备份所有数据库成功"
return ${ENV_SUCCEED}
}
backupSelectedDatabase() {
#时间戳
local timestamp=$(date +"%Y%m%d")
#数据库,如有多个库用空格分开
databaseList="${MYSQL_DATABASES}"
#备份指定数据库列表
for database in ${databaseList}; do
logInfo "正在备份数据库:${database}"
mysqldump -h ${ENV_MYSQL_HOST} -P${ENV_MYSQL_PORT} -u${ENV_MYSQL_USERNAME} -p${ENV_MYSQL_PASSWORD} "${database}" > "${MYSQL_BACKUP_DIR}/${database}-${timestamp}.sql" 2>> ${ENV_LOG_PATH};
if [[ "$?" != 0 ]]; then
logError "<<<< 备份 ${database} 失败"
return ${ENV_FAILED}
fi
# 压缩备份sql文件删除旧的备份文件
cd "${MYSQL_BACKUP_DIR}"
if [[ ! -f "${MYSQL_BACKUP_DIR}/${database}-${timestamp}.sql" ]]; then
logError "备份文件 ${MYSQL_BACKUP_DIR}/${database}-${timestamp}.sql 不存在"
return ${ENV_FAILED}
fi
#为节约硬盘空间,将数据库压缩
sudo tar zcf "${database}-${timestamp}.tar.gz" "${database}-${timestamp}.sql" > /dev/null
#删除原始文件,只留压缩后文件
sudo rm -f "${database}-${timestamp}.sql"
#删除七天前备份也就是只保存7天内的备份
find "${MYSQL_BACKUP_DIR} -name ${database}-*.tar.gz -type f -mtime +${BACKUP_ARTIFACTS_MAX_NUM} -exec rm -rf {} \;" > /dev/null 2>&1
done
logInfo "<<<< 备份数据库 ${MYSQL_DATABASES} 成功"
return ${ENV_SUCCEED}
}
backupMysql() {
#日志记录头部
sudo mkdir -p ${MYSQL_BACKUP_DIR}
touch ${ENV_LOG_PATH}
logInfo "------------------------------------------------------------------"
logInfo ">>>> 备份数据库开始"
#正式备份数据库
if [[ ${MYSQL_DATABASES} == "--all-databases" ]]; then
backupAllDatabase
else
backupSelectedDatabase
fi
}
recoveryMysql() {
logInfo "------------------------------------------------------------------"
logInfo ">>>> 恢复数据库开始"
if [[ ! -f ${ENV_SQL_FILE_PATH} ]]; then
logError "sql 文件 ${ENV_SQL_FILE_PATH} 不存在"
return ${ENV_FAILED}
fi
mysql -h ${ENV_MYSQL_HOST} -P${ENV_MYSQL_PORT} -u${ENV_MYSQL_USERNAME} -p${ENV_MYSQL_PASSWORD} < ${ENV_SQL_FILE_PATH}
if [[ "$?" != 0 ]]; then
logError "<<<< 恢复数据库失败"
return ${ENV_FAILED}
fi
logInfo "<<<< 恢复数据库成功"
return ${ENV_SUCCEED}
}

View File

@ -18,9 +18,9 @@ collation_server = utf8mb4_0900_ai_ci
# LOG
# -------------------------------------------------------------------------------
log_error = /var/log/mysql/mysql-error.log
log_error = /var/log/mysql/mysql.log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
slow_query_log_file = /var/log/mysql/mysql_slow_query_log.log
long_query_time = 3
min_examined_row_limit = 100
expire_logs_days = 7

View File

@ -1,25 +1,112 @@
#!/usr/bin/env bash
###################################################################################
# -----------------------------------------------------------------------------------------------------
# 安装 Gitlab 脚本
# 仅适用于 CentOS7 发行版本
# @author: Zhang Peng
###################################################################################
# -----------------------------------------------------------------------------------------------------
echo -e "\n>>>>>>>>> install gitlab"
# ------------------------------------------------------------------------------ env
echo -e "\n>>>>>>>>> 安装和配置必要依赖"
sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
# Regular Color
export ENV_COLOR_BLACK="\033[0;30m"
export ENV_COLOR_RED="\033[0;31m"
export ENV_COLOR_GREEN="\033[0;32m"
export ENV_COLOR_YELLOW="\033[0;33m"
export ENV_COLOR_BLUE="\033[0;34m"
export ENV_COLOR_MAGENTA="\033[0;35m"
export ENV_COLOR_CYAN="\033[0;36m"
export ENV_COLOR_WHITE="\033[0;37m"
# Bold Color
export ENV_COLOR_B_BLACK="\033[1;30m"
export ENV_COLOR_B_RED="\033[1;31m"
export ENV_COLOR_B_GREEN="\033[1;32m"
export ENV_COLOR_B_YELLOW="\033[1;33m"
export ENV_COLOR_B_BLUE="\033[1;34m"
export ENV_COLOR_B_MAGENTA="\033[1;35m"
export ENV_COLOR_B_CYAN="\033[1;36m"
export ENV_COLOR_B_WHITE="\033[1;37m"
# Reset Color
export ENV_COLOR_RESET="$(tput sgr0)"
echo -e "\n>>>>>>>>> 安装和配置邮件服务"
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
# status
export ENV_YES=0
export ENV_NO=1
export ENV_SUCCEED=0
export ENV_FAILED=1
echo -e "\n>>>>>>>>> 通过 yum 安装 gitlab"
curl -o- https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce
# ------------------------------------------------------------------------------ functions
# 显示打印日志的时间
SHELL_LOG_TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
# 那个用户在操作
USER=$(whoami)
redOutput() {
echo -e "${ENV_COLOR_RED} $@${ENV_COLOR_RESET}"
}
greenOutput() {
echo -e "${ENV_COLOR_B_GREEN} $@${ENV_COLOR_RESET}"
}
yellowOutput() {
echo -e "${ENV_COLOR_YELLOW} $@${ENV_COLOR_RESET}"
}
blueOutput() {
echo -e "${ENV_COLOR_BLUE} $@${ENV_COLOR_RESET}"
}
magentaOutput() {
echo -e "${ENV_COLOR_MAGENTA} $@${ENV_COLOR_RESET}"
}
cyanOutput() {
echo -e "${ENV_COLOR_CYAN} $@${ENV_COLOR_RESET}"
}
whiteOutput() {
echo -e "${ENV_COLOR_WHITE} $@${ENV_COLOR_RESET}"
}
printInfo() {
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
}
printWarn() {
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
}
printError() {
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
}
callAndLog () {
$*
if [[ $? -eq ${ENV_SUCCEED} ]]; then
printInfo "$@"
return ${ENV_SUCCEED}
else
printError "$@ EXECUTE FAILED"
return ${ENV_FAILED}
fi
}
# ------------------------------------------------------------------------------ main
printInfo ">>>> 安装 gitlab"
printInfo ">>>> 安装和配置必要依赖"
yum install -y curl policycoreutils-python openssh-server
systemctl enable sshd
systemctl start sshd
printInfo ">>>> 关闭防火墙"
firewall-cmd --permanent --add-service=http
systemctl reload firewalld
printInfo ">>>> 安装和配置邮件服务"
yum install postfix
systemctl enable postfix
systemctl start postfix
printInfo ">>>> 通过 yum 安装 gitlab"
curl -o- https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
EXTERNAL_URL="http://gitlab.transwarp.io" yum install -y gitlab-ce

View File

@ -0,0 +1,233 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------------------------------
# 数据库操作脚本
# 支持操作:
# 备份 Mysql
# 恢复 Mysql
# @author: Zhang Peng
# -----------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ env
# Regular Color
export ENV_COLOR_BLACK="\033[0;30m"
export ENV_COLOR_RED="\033[0;31m"
export ENV_COLOR_GREEN="\033[0;32m"
export ENV_COLOR_YELLOW="\033[0;33m"
export ENV_COLOR_BLUE="\033[0;34m"
export ENV_COLOR_MAGENTA="\033[0;35m"
export ENV_COLOR_CYAN="\033[0;36m"
export ENV_COLOR_WHITE="\033[0;37m"
# Bold Color
export ENV_COLOR_B_BLACK="\033[1;30m"
export ENV_COLOR_B_RED="\033[1;31m"
export ENV_COLOR_B_GREEN="\033[1;32m"
export ENV_COLOR_B_YELLOW="\033[1;33m"
export ENV_COLOR_B_BLUE="\033[1;34m"
export ENV_COLOR_B_MAGENTA="\033[1;35m"
export ENV_COLOR_B_CYAN="\033[1;36m"
export ENV_COLOR_B_WHITE="\033[1;37m"
# Reset Color
export ENV_COLOR_RESET="$(tput sgr0)"
# status
export ENV_YES=0
export ENV_NO=1
export ENV_SUCCEED=0
export ENV_FAILED=1
# ------------------------------------------------------------------------------ functions
# 显示打印日志的时间
SHELL_LOG_TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
# 那个用户在操作
USER=$(whoami)
redOutput() {
echo -e "${ENV_COLOR_RED} $@${ENV_COLOR_RESET}"
}
greenOutput() {
echo -e "${ENV_COLOR_B_GREEN} $@${ENV_COLOR_RESET}"
}
yellowOutput() {
echo -e "${ENV_COLOR_YELLOW} $@${ENV_COLOR_RESET}"
}
blueOutput() {
echo -e "${ENV_COLOR_BLUE} $@${ENV_COLOR_RESET}"
}
magentaOutput() {
echo -e "${ENV_COLOR_MAGENTA} $@${ENV_COLOR_RESET}"
}
cyanOutput() {
echo -e "${ENV_COLOR_CYAN} $@${ENV_COLOR_RESET}"
}
whiteOutput() {
echo -e "${ENV_COLOR_WHITE} $@${ENV_COLOR_RESET}"
}
printInfo() {
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
}
printWarn() {
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
}
printError() {
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
}
callAndLog () {
$*
if [[ $? -eq ${ENV_SUCCEED} ]]; then
printInfo "$@"
return ${ENV_SUCCEED}
else
printError "$@ EXECUTE FAILED"
return ${ENV_FAILED}
fi
}
# ------------------------------------------------------------------------------ env
# Mysql 操作的环境变量,使用方法:
# 可以在执行本脚本之前export 以下环境变量,否则将按照默认配置执行
# Mysql HOST默认为 127.0.0.1
ENV_MYSQL_HOST="${ENV_MYSQL_HOST:-127.0.0.1}"
# Mysql 端口(默认为 3306
ENV_MYSQL_PORT=${ENV_MYSQL_PORT:-3306}
# Mysql 用户名(默认为 root
ENV_MYSQL_USERNAME=${ENV_MYSQL_USERNAME:-root}
# Mysql 密码(默认为 root
ENV_MYSQL_PASSWORD=${ENV_MYSQL_PASSWORD:-root}
# Mysql 备份文件最大数量(默认为 7 天)
ENV_BACKUP_MAX_NUM=${ENV_BACKUP_MAX_NUM:-7}
# 备份模式:备份所有数据库(--all-databases|备份指定数据库列表
ENV_MYSQL_DATABASES="${ENV_MYSQL_DATABASES:---all-databases}"
# 备份路径
ENV_MYSQL_BACKUP_DIR="${ENV_MYSQL_BACKUP_DIR:-/var/lib/mysql/backup}"
# 备份日志路径
export ENV_LOG_PATH="${ENV_MYSQL_BACKUP_DIR}/mysql-backup.log"
magentaOutput "------------------------------------------------------------------------------"
magentaOutput "Mysql 脚本操作环境变量:"
magentaOutput "ENV_MYSQL_HOST${ENV_MYSQL_HOST}"
magentaOutput "ENV_MYSQL_PORT${ENV_MYSQL_PORT}"
magentaOutput "ENV_MYSQL_USERNAME${ENV_MYSQL_USERNAME}"
magentaOutput "ENV_MYSQL_PASSWORD${ENV_MYSQL_PASSWORD}"
magentaOutput "ENV_BACKUP_MAX_NUM${ENV_BACKUP_MAX_NUM}"
magentaOutput "ENV_MYSQL_DATABASES${ENV_MYSQL_DATABASES}"
magentaOutput "ENV_MYSQL_BACKUP_DIR${ENV_MYSQL_BACKUP_DIR}"
magentaOutput "ENV_LOG_PATH${ENV_LOG_PATH}"
magentaOutput "------------------------------------------------------------------------------"
# ------------------------------------------------------------------------------ functions
# 备份所有 database(schema)
backupAllDatabase() {
#时间戳
local timestamp=$(date +"%Y%m%d")
#备份所有数据库
printInfo ">>>> 备份所有数据库开始"
mysqldump -h ${ENV_MYSQL_HOST} -P${ENV_MYSQL_PORT} -u${ENV_MYSQL_USERNAME} -p${ENV_MYSQL_PASSWORD} --all-databases > "${ENV_MYSQL_BACKUP_DIR}/all-${timestamp}.sql" 2>> ${ENV_LOG_PATH};
#检查备份结果是否成功
if [[ "$?" != ${ENV_SUCCEED} ]]; then
printError "<<<< 备份所有数据库失败"
return ${ENV_FAILED}
fi
# 压缩备份sql文件删除旧的备份文件
cd "${ENV_MYSQL_BACKUP_DIR}"
if [[ ! -f "${ENV_MYSQL_BACKUP_DIR}/all-${timestamp}.sql" ]]; then
printError "备份文件 ${ENV_MYSQL_BACKUP_DIR}/all-${timestamp}.sql 不存在"
return ${ENV_FAILED}
fi
#为节约硬盘空间,将数据库压缩
tar zcf "all-${timestamp}.tar.gz" "all-${timestamp}.sql" > /dev/null
#删除原始文件,只留压缩后文件
rm -f "all-${timestamp}.sql"
#只保存期限内的备份文件,其余删除
find "${ENV_MYSQL_BACKUP_DIR} -name all-*.tar.gz -type f -mtime +${ENV_BACKUP_MAX_NUM} -exec rm -rf {} \;" > /dev/null 2>&1
printInfo "<<<< 备份所有数据库成功\n"
return ${ENV_SUCCEED}
}
# 备份指定的 database(schema)
backupSelectedDatabase() {
#时间戳
local timestamp=$(date +"%Y%m%d")
#数据库,如有多个库用空格分开
databaseList="${ENV_MYSQL_DATABASES}"
#备份指定数据库列表
printInfo ">>>> 备份指定数据库开始"
for database in ${databaseList}; do
printInfo "正在备份数据库:${database}"
mysqldump -h ${ENV_MYSQL_HOST} -P${ENV_MYSQL_PORT} -u${ENV_MYSQL_USERNAME} -p${ENV_MYSQL_PASSWORD} "${database}" > "${ENV_MYSQL_BACKUP_DIR}/${database}-${timestamp}.sql" 2>> ${ENV_LOG_PATH};
if [[ "$?" != 0 ]]; then
printError "<<<< 备份 ${database} 失败"
return ${ENV_FAILED}
fi
# 压缩备份sql文件删除旧的备份文件
cd "${ENV_MYSQL_BACKUP_DIR}"
if [[ ! -f "${ENV_MYSQL_BACKUP_DIR}/${database}-${timestamp}.sql" ]]; then
printError "备份文件 ${ENV_MYSQL_BACKUP_DIR}/${database}-${timestamp}.sql 不存在"
return ${ENV_FAILED}
fi
#为节约硬盘空间,将数据库压缩
tar zcf "${database}-${timestamp}.tar.gz" "${database}-${timestamp}.sql" > /dev/null
#删除原始文件,只留压缩后文件
rm -f "${database}-${timestamp}.sql"
#只保存期限内的备份文件,其余删除
find "${ENV_MYSQL_BACKUP_DIR} -name ${database}-*.tar.gz -type f -mtime +${ENV_BACKUP_MAX_NUM} -exec rm -rf {} \;" > /dev/null 2>&1
done
printInfo "<<<< 备份数据库 ${ENV_MYSQL_DATABASES} 成功\n"
return ${ENV_SUCCEED}
}
# 备份 Mysql
backupMysql() {
#创建备份目录及日志文件
mkdir -p ${ENV_MYSQL_BACKUP_DIR}
if [[ ! -f ${ENV_LOG_PATH} ]]; then
touch ${ENV_LOG_PATH}
fi
#正式备份数据库
if [[ ${ENV_MYSQL_DATABASES} == "--all-databases" ]]; then
backupAllDatabase
else
backupSelectedDatabase
fi
}
# 恢复 Mysql
recoveryMysql() {
#创建备份目录及日志文件
mkdir -p ${ENV_MYSQL_BACKUP_DIR}
if [[ ! -f ${ENV_LOG_PATH} ]]; then
touch ${ENV_LOG_PATH}
fi
printInfo ">>>> 恢复数据库开始"
mysql -h ${ENV_MYSQL_HOST} -P${ENV_MYSQL_PORT} -u${ENV_MYSQL_USERNAME} -p${ENV_MYSQL_PASSWORD} < ${ENV_LOG_PATH}
if [[ "$?" != 0 ]]; then
printError "<<<< 恢复数据库失败"
return ${ENV_FAILED}
fi
printInfo "<<<< 恢复数据库成功\n"
return ${ENV_SUCCEED}
}

View File

@ -71,18 +71,38 @@ createLogFileIfNotExists() {
fi
}
redOutput() {
echo -e "${ENV_COLOR_RED} $@${ENV_COLOR_RESET}"
}
greenOutput() {
echo -e "${ENV_COLOR_B_GREEN} $@${ENV_COLOR_RESET}"
}
yellowOutput() {
echo -e "${ENV_COLOR_YELLOW} $@${ENV_COLOR_RESET}"
}
blueOutput() {
echo -e "${ENV_COLOR_BLUE} $@${ENV_COLOR_RESET}"
}
magentaOutput() {
echo -e "${ENV_COLOR_MAGENTA} $@${ENV_COLOR_RESET}"
}
cyanOutput() {
echo -e "${ENV_COLOR_CYAN} $@${ENV_COLOR_RESET}"
}
whiteOutput() {
echo -e "${ENV_COLOR_WHITE} $@${ENV_COLOR_RESET}"
}
logInfo() {
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
createLogFileIfNotExists
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [INFO] [$0] $@" >> "${LOG_PATH}"
}
logWarn() {
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
createLogFileIfNotExists
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [WARN] [$0] $@" >> "${LOG_PATH}"
}
logError() {
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
createLogFileIfNotExists
@ -92,11 +112,9 @@ logError() {
printInfo() {
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
}
printWarn() {
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
}
printError() {
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
}

View File

@ -1,70 +1,39 @@
#!/usr/bin/env bash
#数据库IP
dbServer="127.0.0.1"
#数据库用户名
dbUser="root"
#数据密码
dbPassword="Tw#123456"
# 备份模式备份所有数据库ALL|备份指定数据库列表CUSTOM
backupMode="ALL"
#backupMode="CUSTOM"
#数据库,如有多个库用空格分开
databaseList="mysql sys"
#备份日期
backupDate=`date +"%Y%m%d"`
#备份路径
backupPath="/var/lib/mysql/backup"
#备份日志路径
logPath="${backupPath}/mysql-backup.log"
# -----------------------------------------------------------------------------------------------------
# Mysql 备份脚本
# 可以通过 crond 服务,设置称为定时执行脚本:
# 1执行 crontab -e 编辑定时执行任务59 23 * * * /home/scripts/mysql-backup.sh
# 2vi /etc/crontab编辑 crontab 文件后保存,可以通过 crontab -l 查看
# @author Zhang Peng
# -----------------------------------------------------------------------------------------------------
#日志记录头部
mkdir -p ${backupPath}
touch ${logPath}
echo "------------------------------------------------------------------" >> ${logPath}
beginTime=`date +"%Y-%m-%d %H:%M:%S"`
echo "备份数据库开始,时间:${beginTime}" >> ${logPath}
# ------------------------------------------------------------------------------ env
# Mysql Host
export ENV_MYSQL_HOST="127.0.0.1"
# Mysql 端口
export ENV_MYSQL_PORT=3306
# Mysql 用户名
export ENV_MYSQL_USERNAME=root
# Mysql 密码
export ENV_MYSQL_PASSWORD=root
# Mysql 备份文件最大数量
export ENV_BACKUP_MAX_NUM=7
# 备份模式:备份所有数据库(--all-databases|备份指定数据库列表
export ENV_MYSQL_DATABASES=--all-databases
# 备份路径
export ENV_MYSQL_BACKUP_DIR=/var/lib/mysql/backup
# 备份日志路径
export ENV_LOG_PATH="${ENV_MYSQL_BACKUP_DIR}/mysql-backup.log"
#正式备份数据库
if [[ ${backupMode} == "ALL" ]];then
filename="all-${backupDate}"
#备份所有数据库
source=`mysqldump -h ${dbServer} -u ${dbUser} -p${dbPassword} --all-databases > ${backupPath}/${filename}.sql`
2>> ${logPath};
#备份成功以下操作
if [[ "$?" == 0 ]];then
cd ${backupPath}
#为节约硬盘空间,将数据库压缩
tar zcf ${filename}.tar.gz ${filename}.sql > /dev/null
#删除原始文件,只留压缩后文件
rm -f ${backupPath}/${filename}.sql
#删除七天前备份也就是只保存7天内的备份
find ${backupPath} -name "*.tar.gz" -type f -mtime +7 -exec rm -rf {} \; > /dev/null 2>&1
echo ">>>> 备份所有数据库成功!" >> ${logPath}
else
#备份失败则进行以下操作
echo ">>>> 备份所有数据库失败!" >> ${logPath}
fi
else
#备份指定数据库列表
for database in ${databaseList}; do
filename="${database}-${backupDate}"
source=`mysqldump -h ${dbServer} -u ${dbUser} -p${dbPassword} ${database} > ${backupPath}/${filename}.sql` 2>> ${logPath};
#备份成功以下操作
if [[ "$?" == 0 ]];then
cd ${backupPath}
#为节约硬盘空间,将数据库压缩
tar zcf ${filename}.tar.gz ${filename}.sql > /dev/null
#删除原始文件,只留压缩后文件
rm -f ${backupPath}/${filename}.sql
#删除七天前备份也就是只保存7天内的备份
find ${backupPath} -name "*.tar.gz" -type f -mtime +7 -exec rm -rf {} \; > /dev/null 2>&1
echo ">>>> 备份数据库 ${database} 成功!" >> ${logPath}
else
#备份失败则进行以下操作
echo ">>>> 备份数据库 ${database} 失败!" >> ${logPath}
fi
done
# ------------------------------------------------------------------------------ libs
LINUX_SCRIPTS_LIB_DIR=`dirname ${BASH_SOURCE[0]}`
if [[ ! -x ${LINUX_SCRIPTS_LIB_DIR}/lib/mysql.sh ]]; then
echo "${LINUX_SCRIPTS_LIB_DIR}/lib/mysql.sh not exists!"
exit 1
fi
endTime=`date +"%Y-%m-%d %H:%M:%S"`
echo "备份数据库结束,时间:${endTime}" >> ${logPath}
source ${LINUX_SCRIPTS_LIB_DIR}/lib/mysql.sh
# ------------------------------------------------------------------------------ main
# 执行备份方法
backupMysql

View File

@ -1,71 +1,143 @@
#!/usr/bin/env bash
###################################################################################
# 控制台颜色
BLACK="\033[1;30m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
PURPLE="\033[1;35m"
CYAN="\033[1;36m"
RESET="$(tput sgr0)"
###################################################################################
printf "${BLUE}"
cat << EOF
###################################################################################
# 安装 mysql 脚本
# @system: 适用于 Centos7 发行版本。
# -----------------------------------------------------------------------------------------------------
# 安装 Mysql 脚本
# 仅适用于 CentOS7 发行版本
# @author: Zhang Peng
###################################################################################
# -----------------------------------------------------------------------------------------------------
EOF
printf "${RESET}"
# ------------------------------------------------------------------------------ env
printf "${GREEN}>>>>>>>> install mysql begin.${RESET}\n"
# Regular Color
export ENV_COLOR_BLACK="\033[0;30m"
export ENV_COLOR_RED="\033[0;31m"
export ENV_COLOR_GREEN="\033[0;32m"
export ENV_COLOR_YELLOW="\033[0;33m"
export ENV_COLOR_BLUE="\033[0;34m"
export ENV_COLOR_MAGENTA="\033[0;35m"
export ENV_COLOR_CYAN="\033[0;36m"
export ENV_COLOR_WHITE="\033[0;37m"
# Bold Color
export ENV_COLOR_B_BLACK="\033[1;30m"
export ENV_COLOR_B_RED="\033[1;31m"
export ENV_COLOR_B_GREEN="\033[1;32m"
export ENV_COLOR_B_YELLOW="\033[1;33m"
export ENV_COLOR_B_BLUE="\033[1;34m"
export ENV_COLOR_B_MAGENTA="\033[1;35m"
export ENV_COLOR_B_CYAN="\033[1;36m"
export ENV_COLOR_B_WHITE="\033[1;37m"
# Reset Color
export ENV_COLOR_RESET="$(tput sgr0)"
# status
export ENV_YES=0
export ENV_NO=1
export ENV_SUCCEED=0
export ENV_FAILED=1
# ------------------------------------------------------------------------------ functions
# 显示打印日志的时间
SHELL_LOG_TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
# 那个用户在操作
USER=$(whoami)
redOutput() {
echo -e "${ENV_COLOR_RED} $@${ENV_COLOR_RESET}"
}
greenOutput() {
echo -e "${ENV_COLOR_B_GREEN} $@${ENV_COLOR_RESET}"
}
yellowOutput() {
echo -e "${ENV_COLOR_YELLOW} $@${ENV_COLOR_RESET}"
}
blueOutput() {
echo -e "${ENV_COLOR_BLUE} $@${ENV_COLOR_RESET}"
}
magentaOutput() {
echo -e "${ENV_COLOR_MAGENTA} $@${ENV_COLOR_RESET}"
}
cyanOutput() {
echo -e "${ENV_COLOR_CYAN} $@${ENV_COLOR_RESET}"
}
whiteOutput() {
echo -e "${ENV_COLOR_WHITE} $@${ENV_COLOR_RESET}"
}
printInfo() {
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
}
printWarn() {
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
}
printError() {
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
}
callAndLog () {
$*
if [[ $? -eq ${ENV_SUCCEED} ]]; then
printInfo "$@"
return ${ENV_SUCCEED}
else
printError "$@ EXECUTE FAILED"
return ${ENV_FAILED}
fi
}
# ------------------------------------------------------------------------------ main
printInfo ">>>> install mysql begin"
command -v wget > /dev/null 2>&1 || {
printf "${RED}Require wget but it's not installed.${RESET}\n";
printError "Require wget but it's not installed"
exit 1;
}
command -v rpm > /dev/null 2>&1 || {
printf "${RED}Require rpm but it's not installed.${RESET}\n";
printError "Require rpm but it's not installed"
exit 1;
}
command -v yum > /dev/null 2>&1 || {
printf "${RED}Require yum but it's not installed.${RESET}\n";
printError "Require yum but it's not installed"
exit 1;
}
# 使用 rpm 安装 mysql
printf "${CYAN}>>>> yum install mysql${RESET}\n"
printInfo ">>>> install mysql by rpm"
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
sudo yum install mysql-community-server
printf "${CYAN}>>>> replace settings${RESET}\n"
printInfo ">>>> modify my.cnf"
cp /etc/my.cnf /etc/my.cnf.bak
wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/mysql/my.cnf -O /etc/my.cnf
# 创建空的慢查询日志文件
printInfo ">>>> create mysql log file"
mkdir -p /var/log/mysql
touch /var/log/mysql/mysql-slow.log
chmod 777 /var/log/mysql/mysql-slow.log
chown -R mysql:mysql /var/log/mysql
# 设置开机启动
printf "${CYAN}>>>> start mysqld${RESET}\n"
systemctl enable mysqld
systemctl start mysqld
systemctl daemon-reload
printInfo ">>>> modify limits.conf"
cat >> /etc/security/limits.conf << EOF
mysql soft nofile 65536
mysql hard nofile 65536
EOF
password=$(grep "password" /var/log/mysqld.log | awk '{print $NF}')
printf "临时密码为:${PURPLE}${password}${RESET},请登录 mysql 后重置新密码\n"
printInfo ">>>> start mysqld"
systemctl enable mysqld
systemctl start mysqld
systemctl daemon-reload
printf "${GREEN}<<<<<<<< install mysql end.${RESET}\n"
printInfo ">>>> 管理员密码如下,请登录 mysql 后重置新密码:"
password=$(grep "password" /var/log/mysql/mysql.log | awk '{print $NF}')
blueOutput "${password}"
printInfo "<<<< install mysql success"

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------------------------------
# MYSQL 恢复脚本
# @author Zhang Peng
# -----------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------ env
# Mysql Host
export ENV_MYSQL_HOST="127.0.0.1"
# Mysql 端口
export ENV_MYSQL_PORT=3306
# Mysql 用户名
export ENV_MYSQL_USERNAME=root
# Mysql 密码
export ENV_MYSQL_PASSWORD=root
# Mysql 备份文件最大数量
export ENV_BACKUP_MAX_NUM=7
# 备份模式:备份所有数据库(--all-databases|备份指定数据库列表
export ENV_MYSQL_DATABASES=--all-databases
# 备份路径
export ENV_MYSQL_BACKUP_DIR=/var/lib/mysql/backup
# 备份日志路径
export ENV_LOG_PATH="${ENV_MYSQL_BACKUP_DIR}/mysql-backup.log"
# ------------------------------------------------------------------------------ libs
LINUX_SCRIPTS_LIB_DIR=`dirname ${BASH_SOURCE[0]}`
if [[ ! -x ${LINUX_SCRIPTS_LIB_DIR}/lib/mysql.sh ]]; then
echo "${LINUX_SCRIPTS_LIB_DIR}/lib/mysql.sh not exists!"
exit 1
fi
source ${LINUX_SCRIPTS_LIB_DIR}/lib/mysql.sh
# ------------------------------------------------------------------------------ main
# 执行备份方法
recoveryMysql

View File

@ -49,7 +49,7 @@ Kubernetes 主要由以下几个核心组件组成:
K8S 包含若干抽象用来表示系统状态,包括:已部署的容器化应用和负载、与它们相关的网络和磁盘资源以及有关集群正在运行的其他操作的信息。
<br>![img](http://dunwu.test.upcdn.net/cs/os/kubernetes/pod.svg!zp)<br>
![img](http://dunwu.test.upcdn.net/cs/os/kubernetes/pod.svg!zp)
- `Pod` - K8S 使用 Pod 来管理容器,每个 Pod 可以包含一个或多个紧密关联的容器。Pod 是一组紧密关联的容器集合,它们共享 PID、IPC、Network 和 UTS namespace是 K8S 调度的基本单位。Pod 内的多个容器共享网络和文件系统,可以通过进程间通信和文件共享这种简单高效的方式组合完成服务。
- `Node` - Node 是 Pod 真正运行的主机,可以是物理机,也可以是虚拟机。为了管理 Pod每个 Node 节点上至少要运行 container runtime比如 docker 或者 rkt、`kubelet` 和 `kube-proxy` 服务。

View File

@ -8,7 +8,7 @@
linux 目录结构是树形结构,其根目录是 `/` 。一张思维导图说明各个目录的作用:
<br>![img](http://dunwu.test.upcdn.net/cs/os/linux/linux-folders.png!zp)<br>
![img](http://dunwu.test.upcdn.net/cs/os/linux/linux-folders.png!zp)
### 1.2. Linux 文件属性
@ -35,7 +35,7 @@ dr-xr-xr-x 4 root root 4096 Apr 19 2012 boot
每个文件的属性由左边第一部分的 10 个字符来确定(如下图)。
<br>![img](http://dunwu.test.upcdn.net/snap/20180920180927171909.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20180920180927171909.png!zp)
从左至右用 0-9 这些数字来表示。

View File

@ -4,7 +4,7 @@ _[Čeština](README-cs.md) ∙ [Deutsch](README-de.md) ∙ [Ελληνικά](RE
# 命令行的艺术
<br>![img](https://gitter.im/jlevy/the-art-of-command-line?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)<br>
![img](https://gitter.im/jlevy/the-art-of-command-line?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
- [前言](#前言)
- [基础](#基础)
@ -18,7 +18,7 @@ _[Čeština](README-cs.md) ∙ [Deutsch](README-de.md) ∙ [Ελληνικά](RE
- [更多资源](#更多资源)
- [免责声明](#免责声明)
<br>![img](https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/cowsay.png)<br>
![img](https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/cowsay.png)
熟练使用命令行是一种常常被忽视,或被认为难以掌握的技能,但实际上,它会提高你作为工程师的灵活性以及生产力。本文是一份我在 Linux 上工作时,发现的一些命令行使用技巧的摘要。有些技巧非常基础,而另一些则相当复杂,甚至晦涩难懂。这篇文章并不长,但当你能够熟练掌握这里列出的所有技巧时,你就学会了很多关于命令行的东西了。
@ -616,6 +616,6 @@ mkdir empty && rsync -r --delete empty/ some-dir && rmdir some-dir
## 授权条款
<br>![img](http://creativecommons.org/licenses/by-sa/4.0/)<br>
![img](http://creativecommons.org/licenses/by-sa/4.0/)
本文使用授权协议 [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/)。

View File

@ -149,7 +149,7 @@ Windows
访问:`\\<你的ip>\<你的共享路径>`
<br>![img](http://dunwu.test.upcdn.net/snap/20180920180928161334.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20180920180928161334.png!zp)
Mac

View File

@ -147,7 +147,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
>
> \> 如果你认为单词是由 blank 字符分隔符,那么你需要使用大写的 E 和 W。程序语句
>
> <br>![img](http://upload-images.jianshu.io/upload_images/3101171-46f752c581d79057.jpg)<br>
> ![img](http://upload-images.jianshu.io/upload_images/3101171-46f752c581d79057.jpg)
下面,让我来说说最强的光标移动:
@ -196,7 +196,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
> - `t,` → 到逗号前的第一个字符。逗号可以变成其它字符。
> - `3fa` → 在当前行查找第三个出现的 a。
> - `F``T` → 和 `f``t` 一样,只不过是相反方向。
> <br>![img](http://upload-images.jianshu.io/upload_images/3101171-00835b8316330c58.jpg)<br>
> ![img](http://upload-images.jianshu.io/upload_images/3101171-00835b8316330c58.jpg)
还有一个很有用的命令是 `dt"` → 删除所有的内容,直到遇到双引号—— `"。`
@ -218,7 +218,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
> - `v2i)` → 会选择 `map (+) ("foo")`
> - `v2a)` → 会选择 `(map (+) ("foo"))`
<br>![img](http://upload-images.jianshu.io/upload_images/3101171-0b109d66a6111c83.png)<br>
![img](http://upload-images.jianshu.io/upload_images/3101171-0b109d66a6111c83.png)
#### 2.4.3. 块操作: `<C-v>`
@ -229,7 +229,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
- `<C-d>` → 向下移动 (你也可以使用 hjkl 来移动光标,或是使用%,或是别的)
- `I-- [ESC]` → I 是插入,插入“`--`”,按 ESC 键来为每一行生效。
<br>![img](http://upload-images.jianshu.io/upload_images/3101171-8b093a0f65707949.gif?imageMogr2/auto-orient/strip)<br>
![img](http://upload-images.jianshu.io/upload_images/3101171-8b093a0f65707949.gif?imageMogr2/auto-orient/strip)
在 Windows 下的 vim你需要使用 `<C-q>` 而不是 `<C-v>` `<C-v>` 是拷贝剪贴板。
@ -237,7 +237,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
在 Insert 模式下,你可以输入一个词的开头,然后按 `<C-p>或是<C-n>,自动补齐功能就出现了……`
<br>![img](http://upload-images.jianshu.io/upload_images/3101171-e2ae877e67880ff7.gif?imageMogr2/auto-orient/strip)<br>
![img](http://upload-images.jianshu.io/upload_images/3101171-e2ae877e67880ff7.gif?imageMogr2/auto-orient/strip)
#### 2.4.5. 宏录制: `qa` 操作序列 `q`, `@a`, `@@`
@ -266,7 +266,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
>
> - 现在做 `100@@` 会创建新的 100 行,并把数据增加到 103.
<br>![img](http://upload-images.jianshu.io/upload_images/3101171-f1889f8bca723964.gif?imageMogr2/auto-orient/strip)<br>
![img](http://upload-images.jianshu.io/upload_images/3101171-f1889f8bca723964.gif?imageMogr2/auto-orient/strip)
#### 2.4.6. 可视化选择: `v`,`V`,`<C-v>`
@ -276,7 +276,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
- `<``>` → 左右缩进
- `=` → 自动给缩进 (注:这个功能相当强大,我太喜欢了)
<br>![img](http://upload-images.jianshu.io/upload_images/3101171-fe1e19983fca213f.gif?imageMogr2/auto-orient/strip)<br>
![img](http://upload-images.jianshu.io/upload_images/3101171-fe1e19983fca213f.gif?imageMogr2/auto-orient/strip)
在所有被选择的行后加上点东西:
@ -285,7 +285,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
- `$` 到行最后
- `A`, 输入字符串,按 `ESC。`
<br>![img](http://upload-images.jianshu.io/upload_images/3101171-b192601247334c4e.gif?imageMogr2/auto-orient/strip)<br>
![img](http://upload-images.jianshu.io/upload_images/3101171-b192601247334c4e.gif?imageMogr2/auto-orient/strip)
#### 2.4.7. 分屏: `:split``vsplit`.
@ -296,7 +296,7 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
> - `<C-w>_` (或 `<C-w>|`) : 最大化尺寸 (<C-w>| 垂直分屏)
> - `<C-w>+` (或 `<C-w>-`) : 增加尺寸
<br>![img](http://upload-images.jianshu.io/upload_images/3101171-f329d01e299cb366.gif?imageMogr2/auto-orient/strip)<br>
![img](http://upload-images.jianshu.io/upload_images/3101171-f329d01e299cb366.gif?imageMogr2/auto-orient/strip)
## 3. Vim Cheat Sheet
@ -308,33 +308,33 @@ Vim 是从 vi 发展出来的一个文本编辑器。代码补完、编译及错
此外,[这里](http://blog.ngedit.com/vi-vim-cheat-sheet-sch.gif)还有简体中文版。
<br>![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet.png!zp)<br>
![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet.png!zp)
### 3.2. 入门版
基本操作的入门版。[原版出处](https://github.com/ahrencode/Miscellaneous)还有 keynote 版本可供 DIY 以及其他相关有用的 cheatsheet。
<br>![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/basic-vim-cheat-sheet.png!zp)<br>
![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/basic-vim-cheat-sheet.png!zp)
### 3.3. 进阶版
下图是 300DPI 的超清大图,另外[查看原文](http://michael.peopleofhonoronly.com/vim/)还有更多版本:黑白,低分辨率,色盲等
<br>![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet-for-programmers.png!zp)<br>
![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet-for-programmers.png!zp)
### 3.4. 增强版
下图是一个更新时间较新的现代版,含有的信息也更丰富。[原文链接](http://vimcheatsheet.com/)
<br>![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet-02.png!zp)<br>
![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet-02.png!zp)
### 3.5. 文字版
[原文链接](http://tnerual.eriogerg.free.fr/vimqrc.pdf)
<br>![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet-text-01.png!zp)<br>
![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet-text-01.png!zp)
<br>![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet-text-02.png!zp)<br>
![img](http://dunwu.test.upcdn.net/cs/os/linux/vim/vim-cheat-sheet-text-02.png!zp)
## 4. 资料

View File

@ -18,7 +18,7 @@ Beats 是安装在服务器上的数据中转代理。
Beats 可以将数据直接传输到 Elasticsearch 或传输到 Logstash 。
<br>![img](https://www.elastic.co/guide/en/beats/libbeat/current/images/beats-platform.png)<br>
![img](https://www.elastic.co/guide/en/beats/libbeat/current/images/beats-platform.png)
Beats 有多种类型,可以根据实际应用需要选择合适的类型。
@ -47,7 +47,7 @@ Filebeat带有内部模块auditdApacheNginxSystem和MySQL
FileBeat 不会让你的管道超负荷。FileBeat 如果是向 Logstash 传输数据,当 Logstash 忙于处理数据,会通知 FileBeat 放慢读取速度。一旦拥塞得到解决FileBeat 将恢复到原来的速度并继续传播。
<br>![img](https://www.elastic.co/guide/en/beats/filebeat/current/images/filebeat.png)<br>
![img](https://www.elastic.co/guide/en/beats/filebeat/current/images/filebeat.png)
## 安装

View File

@ -4,7 +4,7 @@
单击侧面导航栏中的 `Discover` ,可以显示 `Kibana` 的数据查询功能功能。
<br>![img](https://www.elastic.co/guide/en/kibana/current/images/tutorial-discover.png)<br>
![img](https://www.elastic.co/guide/en/kibana/current/images/tutorial-discover.png)
在搜索栏中您可以输入Elasticsearch查询条件来搜索您的数据。您可以在 `Discover` 页面中浏览结果并在 `Visualize` 页面中创建已保存搜索条件的可视化。
@ -14,7 +14,7 @@
默认情况下每个匹配文档都显示所有字段。要选择要显示的文档字段请将鼠标悬停在“可用字段”列表上然后单击要包含的每个字段旁边的添加按钮。例如如果只添加account_number则显示将更改为包含五个帐号的简单列表
<br>![img](https://www.elastic.co/guide/en/kibana/6.1/images/tutorial-discover-3.png)<br>
![img](https://www.elastic.co/guide/en/kibana/6.1/images/tutorial-discover-3.png)
### 查询语义

View File

@ -32,7 +32,7 @@ Logstash 有两个必要元素:`input` 和 `output` ,一个可选元素:`f
这三个元素,分别代表 Logstash 事件处理的三个阶段:输入 > 过滤器 > 输出。
<br>![img](https://www.elastic.co/guide/en/logstash/current/static/images/basic_logstash_pipeline.png)<br>
![img](https://www.elastic.co/guide/en/logstash/current/static/images/basic_logstash_pipeline.png)
- input 负责从数据源采集数据。
- filter 将数据修改为你指定的格式或内容。

View File

@ -32,7 +32,7 @@ ELK 是 elastic 公司旗下三款产品 [ElasticSearch](https://www.elastic.co/
### Elastic 架构
<br>![img](https://www.elastic.co/guide/en/logstash/current/static/images/deploy3.png)<br>
![img](https://www.elastic.co/guide/en/logstash/current/static/images/deploy3.png)
> **说明**
>
@ -274,7 +274,7 @@ output {
大功告成,此后,`io.github.dunwu.spring` 包中的 TRACE 及以上级别的日志信息都会被定向输出到 logstash 服务。
<br>![img](http://upload-images.jianshu.io/upload_images/3101171-cd876d79a14955b0.png)<br>
![img](http://upload-images.jianshu.io/upload_images/3101171-cd876d79a14955b0.png)
## 资料

View File

@ -1,31 +1,16 @@
# Gitlab 安装
# Gitlab 运维
> 环境:
>
> OS: CentOS7
## gitlab 安装
<!-- TOC depthFrom:2 depthTo:3 -->
### Gitlab 的普通安装
- [安装 gitlab](#安装-gitlab)
- [常规安装 gitlab](#常规安装-gitlab)
- [Docker 安装 gitlab](#docker-安装-gitlab)
- [安装 gitlab-ci-multi-runner](#安装-gitlab-ci-multi-runner)
- [常规安装 gitlab-ci-multi-runner](#常规安装-gitlab-ci-multi-runner)
- [Docker 安装 gitlab-ci-multi-runner](#docker-安装-gitlab-ci-multi-runner)
- [自签名证书](#自签名证书)
- [创建证书](#创建证书)
- [gitlab 配置](#gitlab-配置)
- [更多内容](#更多内容)
#### 下载
<!-- /TOC -->
## 安装 gitlab
### 常规安装 gitlab
进入官方下载地址https://about.gitlab.com/install/ ,如下图,选择合适的版本。
<br>![img](http://dunwu.test.upcdn.net/snap/20190129155838.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20190129155838.png!zp)
以 CentOS7 为例:
@ -65,7 +50,7 @@ sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce
安装完成后,即可通过默认的 root 账户进行登录。更多细节可以参考:[documentation for detailed instructions on installing and configuration](https://docs.gitlab.com/omnibus/README.html#installation-and-configuration-using-omnibus-package)
### Docker 安装 gitlab
### Gitlab 的 Docker 安装
拉取镜像
@ -87,9 +72,9 @@ docker run -d \
gitlab/gitlab-ce
```
<br>![img](http://dunwu.test.upcdn.net/snap/20190131150515.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20190131150515.png!zp)
## 安装 gitlab-ci-multi-runner
## gitlab-ci-multi-runner 安装
> 参考https://docs.gitlab.com/runner/install/
@ -138,7 +123,7 @@ sudo gitlab-runner register
URL 和令牌信息在 Gitlab 的 Runner 管理页面获取:
<br>![img](http://dunwu.test.upcdn.net/snap/20190129163100.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20190129163100.png!zp)
```
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
@ -302,31 +287,31 @@ sudo gitlab-ctl restart
3. 打开 **Profile settings**.
<br>![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings.png)<br>
![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings.png)
4. 跳转到 **SSH keys** tab 页
<br>![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings_ssh_keys.png)<br>
![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings_ssh_keys.png)
5. 黏贴你的 SSH 公钥内容到 Key 文本框
<br>![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings_ssh_keys_paste_pub.png)<br>
![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings_ssh_keys_paste_pub.png)
6. 为了便于识别,你可以为其命名
<br>![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings_ssh_keys_title.png)<br>
![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings_ssh_keys_title.png)
7. 点击 **Add key** 将 SSH 公钥添加到 GitLab
<br>![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings_ssh_keys_single_key.png)<br>
![img](https://docs.gitlab.com/ce/gitlab-basics/img/profile_settings_ssh_keys_single_key.png)
### 创建项目
<br>![img](http://dunwu.test.upcdn.net/snap/20190131150658.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20190131150658.png!zp)
输入项目信息,点击 Create project 按钮,在 Gitlab 创建项目。
<br>![img](http://dunwu.test.upcdn.net/snap/20190131150759.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20190131150759.png!zp)
### 克隆项目到本地
@ -338,25 +323,44 @@ sudo gitlab-ctl restart
依次点击 **Projects Dashboard** > **Issues** > **New Issue** 可以新建 Issue
<br>![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue_from_tracker_list.png)<br>
![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue_from_tracker_list.png)
在项目中直接添加 issue
<br>![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue.png)<br>
![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue.png)
在未关闭 issue 中,点击 **New Issue** 添加 issue
<br>![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue_from_open_issue.png)<br>
![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue_from_open_issue.png)
通过项目面板添加 issue
<br>![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue_from_projects_dashboard.png)<br>
![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue_from_projects_dashboard.png)
通过 issue 面板添加 issue
<br>![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue_from_issue_board.png)<br>
![img](https://docs.gitlab.com/ce/user/project/issues/img/new_issue_from_issue_board.png)
## 更多内容
## gitlab 权限配置
- **引申**
- [操作系统、运维部署总结系列](https://github.com/dunwu/OS)
### 用户组的权限
- 用户组有这几种权限的概念:`Guest、Reporter、Developer、Master、Owner`
- 这个概念在设置用户组的时候会遇到,叫做:`Add user(s) to the group`,比如链接:`https://<gitlab_host>/<group>`
| 行为 | Guest | Reporter | Developer | Master | Owner |
| ---------- | ----- | -------- | --------- | ------ | ----- |
| 浏览组 | ✓ | ✓ | ✓ | ✓ | ✓ |
| 编辑组 | | | | | ✓ |
| 创建项目 | | | | ✓ | ✓ |
| 管理组成员 | | | | | ✓ |
| 移除组 | | | | | |
## 资料
- 官网https://about.gitlab.com/
- 中文网https://www.gitlab.com.cn/
- 官网下载https://about.gitlab.com/downloads/
- 官网安装说明https://about.gitlab.com/installation/#centos-7
- [操作系统、运维部署总结系列](https://github.com/dunwu/OS)

View File

@ -22,13 +22,13 @@ a. 进入 [Java 官网下载页面](https://www.oracle.com/technetwork/java/java
b. 选择需要的版本:
<br>![img](http://dunwu.test.upcdn.net/snap/20180920181010164121.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20180920181010164121.png!zp)
c. 选择对应操作系统的安装包:
Windows 系统选择 exe 安装包Mac 系统选择 dmp 安装包Linux 系统选择 tar.gz 压缩包RedHat 发行版可以安装 rpm 包)。
<br>![img](http://dunwu.test.upcdn.net/snap/20180920181010164308.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20180920181010164308.png!zp)
2运行安装包按提示逐步安装
@ -51,11 +51,11 @@ Windows 系统选择 exe 安装包Mac 系统选择 dmp 安装包Linux 系
a. 安装完成后,右击"我的电脑",点击"属性",选择"高级系统设置"
<br>![img](https://www.runoob.com/wp-content/uploads/2013/12/win-java1.png)<br>
![img](https://www.runoob.com/wp-content/uploads/2013/12/win-java1.png)
b. 选择"高级"选项卡,点击"环境变量"
<br>![img](https://www.runoob.com/wp-content/uploads/2013/12/java-win2.png)<br>
![img](https://www.runoob.com/wp-content/uploads/2013/12/java-win2.png)
然后就会出现如下图所示的画面:
@ -78,7 +78,7 @@ a. "开始"->"运行",键入"cmd"
b. 键入命令: **java -version**、**java**、**javac** 几个命令,出现以下信息,说明环境变量配置成功;
<br>![img](https://www.runoob.com/wp-content/uploads/2013/12/java-win9.png)<br>
![img](https://www.runoob.com/wp-content/uploads/2013/12/java-win9.png)
## Linux 系统安装方法

View File

@ -98,7 +98,7 @@ Jenkins 是一个强大的 CI 工具,虽然本身使用 Java 开发,但也
General 是构建任务的一些基本配置。名称,描述之类的。
![](http://dunwu.test.upcdn.net/snap/20200310221814.png)
![img](http://dunwu.test.upcdn.net/snap/20200310221814.png)
重要配置项:
@ -111,7 +111,7 @@ General 是构建任务的一些基本配置。名称,描述之类的。
**Source Code Management**,即源码管理,就是配置你代码的存放位置。
![](http://dunwu.test.upcdn.net/snap/20200310222110.png)
![img](http://dunwu.test.upcdn.net/snap/20200310222110.png)
- **Git:** 支持主流的 Github 和 Gitlab 代码仓库。因我们的研发团队使用的是 gitlab所以下面我只会对该项进行介绍。
- **Repository URL**:仓库地址。
@ -124,7 +124,7 @@ General 是构建任务的一些基本配置。名称,描述之类的。
**Build Triggers**,即构建触发器,用于构建任务的触发器。
![](http://dunwu.test.upcdn.net/snap/20200310222608.png)
![img](http://dunwu.test.upcdn.net/snap/20200310222608.png)
配置说明:
@ -138,7 +138,7 @@ General 是构建任务的一些基本配置。名称,描述之类的。
**Build Environment**,即构建环境,配置构建前的一些准备工作,如指定构建工具。
![](http://dunwu.test.upcdn.net/snap/20200310223004.png)
![img](http://dunwu.test.upcdn.net/snap/20200310223004.png)
### Build
@ -146,7 +146,7 @@ Build即构建。
点击下图中的 Add build step 按钮,会弹出一个构建任务菜单,可以根据实际需要来选择。
![](http://dunwu.test.upcdn.net/snap/20200310223241.png)
![img](http://dunwu.test.upcdn.net/snap/20200310223241.png)
【说明】
@ -162,11 +162,11 @@ Build即构建。
**Post-build Actions**,即构建后操作,用于构建完本项目的一些后续操作,比如生成相应的代码测试报告。
![](http://dunwu.test.upcdn.net/snap/20200310224106.png)
![img](http://dunwu.test.upcdn.net/snap/20200310224106.png)
![](http://dunwu.test.upcdn.net/snap/20200310224254.png)
![img](http://dunwu.test.upcdn.net/snap/20200310224254.png)
![](http://dunwu.test.upcdn.net/snap/20200310224331.png)
![img](http://dunwu.test.upcdn.net/snap/20200310224331.png)
个人较常用的配置:
@ -182,13 +182,13 @@ Build即构建。
### 开始构建
![](http://dunwu.test.upcdn.net/snap/20200310224927.png)
![img](http://dunwu.test.upcdn.net/snap/20200310224927.png)
如上图所示,一切配置好后,即可点击 **Build Now** 开始构建。
### 构建结果
![](http://dunwu.test.upcdn.net/snap/20200310225234.png)
![img](http://dunwu.test.upcdn.net/snap/20200310225234.png)
- **构建状态**
- **Successful 蓝色**:构建完成,并且被认为是稳定的。

View File

@ -4,38 +4,19 @@
>
> 关键词maven, nexus
>
> 部署环境
> 部署环境
>
> - Nexus 3.13.0
> - JDK 1.8
> - Maven 3.5.4
<!-- TOC depthFrom:2 depthTo:3 -->
- [1. 安装 Nexus](#1-安装-nexus)
- [2. 启动/停止 Nexus](#2-启动停止-nexus)
- [3. 搭建 Maven 私服](#3-搭建-maven-私服)
- [3.1. 配置仓库](#31-配置仓库)
- [3.2. 配置 settings.xml](#32-配置-settingsxml)
- [3.3. 配置 pom.xml](#33-配置-pomxml)
- [3.4. 执行 maven 构建](#34-执行-maven-构建)
- [4. 开机自启动](#4-开机自启动)
- [5. Nexus 备份和迁移](#5-nexus-备份和迁移)
- [5.1. 备份](#51-备份)
- [5.2. 迁移](#52-迁移)
- [6. FAQ](#6-faq)
- [6.1. 配置 INSTALL4J_JAVA_HOME](#61-配置-install4j_java_home)
- [7. 参考资料](#7-参考资料)
<!-- /TOC -->
## 1. 安装 Nexus
进入[官方下载地址](https://www.sonatype.com/download-oss-sonatype),选择合适版本下载。
![img](http://dunwu.test.upcdn.net/snap/20181127203029.png!zp)
本人希望将 Nexus 部署在 Linux 机器,所以选用的是 Unix 版本。
本人将 Nexus 部署在 Linux 机器,所以选用的是 Unix 版本。
这里,如果想通过命令方式直接下载(比如用脚本安装),可以在[官方历史发布版本页面](https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3)中找到合适版本,然后执行以下命令:
@ -46,8 +27,8 @@ tar -zxf nexus-unix.tar.gz
解压后,有两个目录:
- nexus-3.13.0-01 - 包含了 Nexus 运行所需要的文件。是 Nexus 运行必须的。
- sonatype-work - 包含了 Nexus 生成的配置文件、日志文件、仓库文件等。当我们需要备份 Nexus 的时候默认备份此目录即可。
- `nexus-3.13.0-01` - 包含了 Nexus 运行所需要的文件。是 Nexus 运行必须的。
- `sonatype-work` - 包含了 Nexus 生成的配置文件、日志文件、仓库文件等。当我们需要备份 Nexus 的时候默认备份此目录即可。
## 2. 启动/停止 Nexus

View File

@ -145,7 +145,7 @@ $ vi /etc/sysconfig/svnserve
在新的窗口,输入地址 `svn://<你的 IP>` 即可,不出意外输入用户名和密码就能连接成功了(这里的用户、密码必须在 passwd 配置文件的清单中)。默认端口 3690如果你修改了端口那么要记得加上端口号。如下图所示
<br>![img](http://dunwu.test.upcdn.net/snap/20190129175443.png!zp)<br>
![img](http://dunwu.test.upcdn.net/snap/20190129175443.png!zp)
## 2. 参考资料