Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4466705

Browse files
committed
update docs and scripts
1 parent 097cfb4 commit 4466705

File tree

11 files changed

+672
-162
lines changed

11 files changed

+672
-162
lines changed

‎codes/linux/soft/gitlab-install.sh‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env bash
22

33
# -----------------------------------------------------------------------------------------------------
4-
# 安装 Gitlab 脚本
4+
# Gitlab 安装脚本
55
# 仅适用于 CentOS7 发行版本
6+
# 官方安裝參考:https://about.gitlab.com/install/#centos-7
67
# @author: Zhang Peng
78
# -----------------------------------------------------------------------------------------------------
89

@@ -37,11 +38,6 @@ export ENV_FAILED=1
3738

3839
# ------------------------------------------------------------------------------ functions
3940

40-
# 显示打印日志的时间
41-
SHELL_LOG_TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
42-
# 那个用户在操作
43-
USER=$(whoami)
44-
4541
redOutput() {
4642
echo -e "${ENV_COLOR_RED} $@${ENV_COLOR_RESET}"
4743
}
@@ -95,18 +91,20 @@ callAndLog () {
9591

9692
# ------------------------------------------------------------------------------ main
9793

98-
printInfo ">>>> 安装 gitlab"
99-
printInfo ">>>> 安装和配置必要依赖"
94+
# 官方安裝參考:https://about.gitlab.com/install/#centos-7
95+
printInfo ">>>> install gitlab on Centos7"
96+
printInfo ">>>> Install and configure the necessary dependencies"
10097
yum install -y curl policycoreutils-python openssh-server
10198
systemctl enable sshd
10299
systemctl start sshd
103-
printInfo ">>>> 关闭防火墙"
104-
firewall-cmd --permanent --add-service=http
105-
systemctl reload firewalld
106-
printInfo ">>>> 安装和配置邮件服务"
100+
printInfo ">>>> open http, https and ssh access in the system firewall"
101+
sudo firewall-cmd --permanent --add-service=http
102+
sudo firewall-cmd --permanent --add-service=https
103+
sudo systemctl reload firewalld
104+
printInfo ">>>> install postfix"
107105
yum install postfix
108106
systemctl enable postfix
109107
systemctl start postfix
110-
printInfo ">>>> 通过 yum 安装 gitlab"
108+
printInfo ">>>> Add the GitLab package repository and install the package"
111109
curl -o- https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
112110
EXTERNAL_URL="http://gitlab.transwarp.io" yum install -y gitlab-ce
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
# -----------------------------------------------------------------------------------------------------
4+
# Gitlab 操作脚本
5+
# 支持操作:
6+
# 备份 Gitlab
7+
# 恢复 Gitlab
8+
# @author: Zhang Peng
9+
# -----------------------------------------------------------------------------------------------------
10+
11+
12+
# ------------------------------------------------------------------------------ env
13+
14+
# Gilab 操作的环境变量,使用方法:
15+
# 可以在执行本脚本之前,export 以下环境变量,否则将按照默认配置执行
16+
17+
# Gitlab 备份文件最大数量(默认为 7 天)
18+
export ENV_BACKUP_MAX_NUM=7
19+
# 备份路径
20+
export ENV_GITLAB_BACKUP_DIR="/var/opt/gitlab/backups"
21+
# 备份日志路径
22+
export ENV_LOG_PATH="${ENV_GITLAB_BACKUP_DIR}/gitlab-backup.log"
23+
24+
ENV_REMOTE_USER=root
25+
ENV_REMOTE_HOST=172.22.6.42
26+
27+
# ------------------------------------------------------------------------------ load libs
28+
29+
GIT_SCRIPTS_DIR=$(cd `dirname 0ドル`; pwd)
30+
if [[ ! -x ${GIT_SCRIPTS_DIR}/gitlab.sh ]]; then
31+
echo "${GIT_SCRIPTS_DIR}/gitlab.sh not exists!"
32+
exit 1
33+
fi
34+
source ${GIT_SCRIPTS_DIR}/gitlab.sh
35+
36+
# ------------------------------------------------------------------------------ functions
37+
38+
backupGitlab
39+
if [[ "$?" != ${ENV_SUCCEED} ]]; then
40+
printError "退出"
41+
exit ${ENV_FAILED}
42+
fi
43+
44+
#将备份文件传输到gitlab备份服务器
45+
BACKUP_FILE=$(find "${ENV_GITLAB_BACKUP_DIR}" -type f -name "*gitlab_backup.tar" | xargs ls -t | head -1)
46+
scp ${BACKUP_FILE} ${ENV_REMOTE_USER}@${ENV_REMOTE_HOST}:${ENV_GITLAB_BACKUP_DIR}

‎codes/linux/soft/gitlab/gitlab.sh‎

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/usr/bin/env bash
2+
3+
# -----------------------------------------------------------------------------------------------------
4+
# Gitlab 操作脚本
5+
# 支持操作:
6+
# 备份 Gitlab
7+
# 恢复 Gitlab
8+
# @author: Zhang Peng
9+
# -----------------------------------------------------------------------------------------------------
10+
11+
# ------------------------------------------------------------------------------ env
12+
13+
# Regular Color
14+
export ENV_COLOR_BLACK="033円[0;30m"
15+
export ENV_COLOR_RED="033円[0;31m"
16+
export ENV_COLOR_GREEN="033円[0;32m"
17+
export ENV_COLOR_YELLOW="033円[0;33m"
18+
export ENV_COLOR_BLUE="033円[0;34m"
19+
export ENV_COLOR_MAGENTA="033円[0;35m"
20+
export ENV_COLOR_CYAN="033円[0;36m"
21+
export ENV_COLOR_WHITE="033円[0;37m"
22+
# Bold Color
23+
export ENV_COLOR_B_BLACK="033円[1;30m"
24+
export ENV_COLOR_B_RED="033円[1;31m"
25+
export ENV_COLOR_B_GREEN="033円[1;32m"
26+
export ENV_COLOR_B_YELLOW="033円[1;33m"
27+
export ENV_COLOR_B_BLUE="033円[1;34m"
28+
export ENV_COLOR_B_MAGENTA="033円[1;35m"
29+
export ENV_COLOR_B_CYAN="033円[1;36m"
30+
export ENV_COLOR_B_WHITE="033円[1;37m"
31+
# Reset Color
32+
export ENV_COLOR_RESET="$(tput sgr0)"
33+
34+
# status
35+
export ENV_YES=0
36+
export ENV_NO=1
37+
export ENV_SUCCEED=0
38+
export ENV_FAILED=1
39+
40+
# ------------------------------------------------------------------------------ functions
41+
42+
# 显示打印日志的时间
43+
SHELL_LOG_TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
44+
# 那个用户在操作
45+
USER=$(whoami)
46+
47+
redOutput() {
48+
echo -e "${ENV_COLOR_RED} $@${ENV_COLOR_RESET}"
49+
}
50+
greenOutput() {
51+
echo -e "${ENV_COLOR_B_GREEN} $@${ENV_COLOR_RESET}"
52+
}
53+
yellowOutput() {
54+
echo -e "${ENV_COLOR_YELLOW} $@${ENV_COLOR_RESET}"
55+
}
56+
blueOutput() {
57+
echo -e "${ENV_COLOR_BLUE} $@${ENV_COLOR_RESET}"
58+
}
59+
magentaOutput() {
60+
echo -e "${ENV_COLOR_MAGENTA} $@${ENV_COLOR_RESET}"
61+
}
62+
cyanOutput() {
63+
echo -e "${ENV_COLOR_CYAN} $@${ENV_COLOR_RESET}"
64+
}
65+
whiteOutput() {
66+
echo -e "${ENV_COLOR_WHITE} $@${ENV_COLOR_RESET}"
67+
}
68+
69+
printInfo() {
70+
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
71+
}
72+
printWarn() {
73+
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
74+
}
75+
printError() {
76+
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
77+
}
78+
79+
callAndLog () {
80+
$*
81+
if [[ $? -eq ${ENV_SUCCEED} ]]; then
82+
printInfo "$@"
83+
return ${ENV_SUCCEED}
84+
else
85+
printError "$@ EXECUTE FAILED"
86+
return ${ENV_FAILED}
87+
fi
88+
}
89+
90+
# ------------------------------------------------------------------------------ env
91+
92+
# Gilab 操作的环境变量,使用方法:
93+
# 可以在执行本脚本之前,export 以下环境变量,否则将按照默认配置执行
94+
95+
# Gitlab 备份文件最大数量(默认为 7 天)
96+
ENV_BACKUP_MAX_NUM=${ENV_BACKUP_MAX_NUM:-2}
97+
# 备份路径
98+
ENV_GITLAB_BACKUP_DIR="${ENV_GITLAB_BACKUP_DIR:-/var/opt/gitlab/backups}"
99+
# 备份日志路径
100+
ENV_LOG_PATH="${ENV_GITLAB_BACKUP_DIR}/gitlab-backup.log"
101+
102+
magentaOutput "------------------------------------------------------------------------------"
103+
magentaOutput "Gitlab 脚本操作环境变量:"
104+
magentaOutput "ENV_BACKUP_MAX_NUM:${ENV_BACKUP_MAX_NUM}"
105+
magentaOutput "ENV_GITLAB_BACKUP_DIR:${ENV_GITLAB_BACKUP_DIR}"
106+
magentaOutput "ENV_LOG_PATH:${ENV_LOG_PATH}"
107+
magentaOutput "------------------------------------------------------------------------------"
108+
109+
110+
# ------------------------------------------------------------------------------ functions
111+
112+
# 安装 Gitlab
113+
installGitlab() {
114+
# 官方安裝參考:https://about.gitlab.com/install/#centos-7
115+
printInfo ">>>> install gitlab on Centos7"
116+
printInfo ">>>> Install and configure the necessary dependencies"
117+
yum install -y curl policycoreutils-python openssh-server
118+
systemctl enable sshd
119+
systemctl start sshd
120+
printInfo ">>>> open http, https and ssh access in the system firewall"
121+
sudo firewall-cmd --permanent --add-service=http
122+
sudo firewall-cmd --permanent --add-service=https
123+
sudo systemctl reload firewalld
124+
printInfo ">>>> install postfix"
125+
yum install postfix
126+
systemctl enable postfix
127+
systemctl start postfix
128+
printInfo ">>>> Add the GitLab package repository and install the package"
129+
curl -o- https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
130+
EXTERNAL_URL="http://gitlab.transwarp.io" yum install -y gitlab-ce
131+
}
132+
133+
# 备份 Gitlab
134+
backupGitlab() {
135+
136+
#时间戳
137+
local beginTime=$(date +'%Y-%m-%d %H:%M:%S')
138+
139+
#备份所有数据库
140+
printInfo ">>>> 备份 Gitlab 开始"
141+
gitlab-rake gitlab:backup:create >> ${ENV_LOG_PATH};
142+
143+
#检查备份结果是否成功
144+
if [[ "$?" != ${ENV_SUCCEED} ]]; then
145+
printError "<<<< 备份 Gitlab 失败"
146+
return ${ENV_FAILED}
147+
fi
148+
149+
# 压缩备份sql文件,删除旧的备份文件
150+
cd "${ENV_GITLAB_BACKUP_DIR}"
151+
152+
#只保存期限内的备份文件,其余删除
153+
find "${ENV_GITLAB_BACKUP_DIR} -name *_gitlab_backup.tar -type f -mtime +${ENV_BACKUP_MAX_NUM} -exec rm -rf {} \;" > /dev/null 2>&1
154+
155+
local endTime=$(date +'%Y-%m-%d %H:%M:%S')
156+
local beginSeconds=$(date --date="${beginTime}" +%s)
157+
local endSeconds=$(date --date="${endTime}" +%s)
158+
printInfo "本次备份执行时间:$((endSeconds-beginSeconds)) s"
159+
printInfo "<<<< 备份 Gitlab 成功\n"
160+
return ${ENV_SUCCEED}
161+
}
162+
163+
# 恢复 Mysql
164+
recoveryGitlab() {
165+
166+
local version=1ドル
167+
if [[ !version ]]; then
168+
printError "<<<< 未指定恢复版本"
169+
return ${ENV_FAILED}
170+
fi
171+
172+
#创建备份目录及日志文件
173+
mkdir -p ${ENV_GITLAB_BACKUP_DIR}
174+
if [[ ! -f ${ENV_LOG_PATH} ]]; then
175+
touch ${ENV_LOG_PATH}
176+
fi
177+
178+
printInfo ">>>> 恢复 Gitlab 开始"
179+
180+
gitlab-ctl stop unicorn
181+
gitlab-ctl stop sidekiq
182+
183+
gitlab-rake gitlab:backup:restore BACKUP=${version}
184+
if [[ "$?" != 0 ]]; then
185+
printError "<<<< 恢复 Gitlab 失败"
186+
return ${ENV_FAILED}
187+
fi
188+
189+
printInfo "<<<< 恢复 Gitlab 成功\n"
190+
return ${ENV_SUCCEED}
191+
}

‎codes/linux/soft/lib/mysql.sh‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ ENV_MYSQL_DATABASES="${ENV_MYSQL_DATABASES:---all-databases}"
108108
# 备份路径
109109
ENV_MYSQL_BACKUP_DIR="${ENV_MYSQL_BACKUP_DIR:-/var/lib/mysql/backup}"
110110
# 备份日志路径
111-
export ENV_LOG_PATH="${ENV_MYSQL_BACKUP_DIR}/mysql-backup.log"
111+
ENV_MYSQL_BACKUP_LOG_PATH="${ENV_MYSQL_BACKUP_DIR}/mysql-backup.log"
112112

113113
magentaOutput "------------------------------------------------------------------------------"
114114
magentaOutput "Mysql 脚本操作环境变量:"
@@ -119,7 +119,7 @@ magentaOutput "ENV_MYSQL_PASSWORD:${ENV_MYSQL_PASSWORD}"
119119
magentaOutput "ENV_BACKUP_MAX_NUM:${ENV_BACKUP_MAX_NUM}"
120120
magentaOutput "ENV_MYSQL_DATABASES:${ENV_MYSQL_DATABASES}"
121121
magentaOutput "ENV_MYSQL_BACKUP_DIR:${ENV_MYSQL_BACKUP_DIR}"
122-
magentaOutput "ENV_LOG_PATH:${ENV_LOG_PATH}"
122+
magentaOutput "ENV_MYSQL_BACKUP_LOG_PATH:${ENV_MYSQL_BACKUP_LOG_PATH}"
123123
magentaOutput "------------------------------------------------------------------------------"
124124

125125

@@ -133,7 +133,7 @@ backupAllDatabase() {
133133

134134
#备份所有数据库
135135
printInfo ">>>> 备份所有数据库开始"
136-
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};
136+
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_MYSQL_BACKUP_LOG_PATH};
137137

138138
#检查备份结果是否成功
139139
if [[ "$?" != ${ENV_SUCCEED} ]]; then
@@ -172,7 +172,7 @@ backupSelectedDatabase() {
172172
for database in ${databaseList}; do
173173

174174
printInfo "正在备份数据库:${database}"
175-
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};
175+
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_MYSQL_BACKUP_LOG_PATH};
176176
if [[ "$?" != 0 ]]; then
177177
printError "<<<< 备份 ${database} 失败"
178178
return ${ENV_FAILED}
@@ -200,8 +200,8 @@ backupSelectedDatabase() {
200200
backupMysql() {
201201
#创建备份目录及日志文件
202202
mkdir -p ${ENV_MYSQL_BACKUP_DIR}
203-
if [[ ! -f ${ENV_LOG_PATH} ]]; then
204-
touch ${ENV_LOG_PATH}
203+
if [[ ! -f ${ENV_MYSQL_BACKUP_LOG_PATH} ]]; then
204+
touch ${ENV_MYSQL_BACKUP_LOG_PATH}
205205
fi
206206

207207
#正式备份数据库
@@ -216,13 +216,13 @@ backupMysql() {
216216
recoveryMysql() {
217217
#创建备份目录及日志文件
218218
mkdir -p ${ENV_MYSQL_BACKUP_DIR}
219-
if [[ ! -f ${ENV_LOG_PATH} ]]; then
220-
touch ${ENV_LOG_PATH}
219+
if [[ ! -f ${ENV_MYSQL_BACKUP_LOG_PATH} ]]; then
220+
touch ${ENV_MYSQL_BACKUP_LOG_PATH}
221221
fi
222222

223223
printInfo ">>>> 恢复数据库开始"
224224

225-
mysql -h ${ENV_MYSQL_HOST} -P${ENV_MYSQL_PORT} -u${ENV_MYSQL_USERNAME} -p${ENV_MYSQL_PASSWORD} < ${ENV_LOG_PATH}
225+
mysql -h ${ENV_MYSQL_HOST} -P${ENV_MYSQL_PORT} -u${ENV_MYSQL_USERNAME} -p${ENV_MYSQL_PASSWORD} < ${ENV_MYSQL_BACKUP_LOG_PATH}
226226
if [[ "$?" != 0 ]]; then
227227
printError "<<<< 恢复数据库失败"
228228
return ${ENV_FAILED}

‎codes/linux/soft/mysql-install.sh‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/conf
121121

122122
printInfo ">>>> create mysql log file"
123123
mkdir -p /var/log/mysql
124-
touch /var/log/mysql/mysql-slow.log
125-
chmod 777 /var/log/mysql/mysql-slow.log
124+
touch /var/log/mysql/mysql.log
125+
touch /var/log/mysql/mysql_slow_query_log.log
126+
chmod 777 /var/log/mysql/mysql.log
127+
chmod 777 /var/log/mysql/mysql_slow_query_log.log
126128
chown -R mysql:mysql /var/log/mysql
127129

128130
printInfo ">>>> modify limits.conf"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /