-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmariadb103.sh
235 lines (185 loc) · 5.91 KB
/
mariadb103.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/sh
#rootユーザーで実行 or sudo権限ユーザー
<<COMMENT
作成者:サイトラボ
URL:https://www.site-lab.jp/
URL:https://www.logw.jp/
注意点:conohaのポートは全て許可前提となります。MariaDBがインストールされていない状態となります。
目的:システム更新+mariadbのインストール
・Mariadb
COMMENT
start_message(){
echo ""
echo "======================開始======================"
echo ""
}
end_message(){
echo ""
echo "======================完了======================"
echo ""
}
#CentOS7か確認
if [ -e /etc/redhat-release ]; then
DIST="redhat"
DIST_VER=`cat /etc/redhat-release | sed -e "s/.*\s\([0-9]\)\..*/\1/"`
if [ $DIST = "redhat" ];then
if [ $DIST_VER = "7" ];then
#rootのパスワード
RPASSWORD=$(more /dev/urandom | tr -dc '12345678abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ,.+\-\!' | fold -w 12 | grep -i [12345678] | grep -i '[,.+\-\!]' | head -n 1)
#userパスワード
UPASSWORD=$(more /dev/urandom | tr -dc '12345678abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ,.+\-\!' | fold -w 12 | grep -i [12345678] | grep -i '[,.+\-\!]' | head -n 1)
#EPELリポジトリのインストール
start_message
yum remove -y epel-release
yum -y install epel-release
end_message
#gitリポジトリのインストール
start_message
yum -y install git
end_message
# yum updateを実行
echo "yum updateを実行します"
echo ""
start_message
yum -y update
end_message
# yumのキャッシュをクリア
echo "yum clean allを実行します"
start_message
yum clean all
end_message
# ディレクトリ作成
echo "mkdir /var/log/mysql"
start_message
mkdir /var/log/mysql
end_message
# MariaDBの設定ファイルを追加
start_message
cat >/etc/yum.repos.d/MariaDB.repo <<'EOF'
# MariaDB 10.3 CentOS repository list
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
yum -y install mariadb-server maradb-client
yum list installed | grep mariadb
end_message
#ファイル作成
start_message
rm -rf /etc/etc/my.cnf.d/server.cnf
cat >/etc/etc/my.cnf.d/server.cnf <<'EOF'
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
#
# * Galera-related settings
#
#エラーログ
log_error="/var/log/mysql/mysqld.log"
log_warnings=1
# Query log
general_log = ON
general_log_file="/var/log/mysql/sql.log"
# Slow Query log
slow_query_log=1
slow_query_log_file="/var/log/mysql/slow.log"
log_queries_not_using_indexes
log_slow_admin_statements
long_query_time=5
character-set-server = utf8
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.3 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.3]
EOF
#バージョン表示
start_message
mysql --version
end_message
#MariaDBの起動
start_message
systemctl start mariadb.service
systemctl status mariadb.service
end_message
#自動起動の設定
start_message
systemctl enable mariadb
systemctl list-unit-files --type=service | grep mariadb
end_message
#パスワード設定
start_message
mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${RPASSWORD}'; flush privileges;"
echo ${RPASSWORD}
cat <<EOF >/etc/createdb.sql
CREATE DATABASE centos;
CREATE USER 'centos'@'localhost' IDENTIFIED BY '${UPASSWORD}';
GRANT ALL PRIVILEGES ON centos.* TO 'centos'@'localhost';
FLUSH PRIVILEGES;
SELECT user, host FROM mysql.user;
EOF
mysql -u root -p${RPASSWORD} -e "source /etc/createdb.sql"
end_message
#ファイルを保存
cat <<EOF >/etc/my.cnf.d/centos.cnf
[client]
user = centos
password = ${UPASSWORD}
host = localhost
EOF
#ファイルの保存
start_message
echo "パスワードなどを保存"
cat <<EOF >/root/pass.txt
root = ${RPASSWORD}
centos = ${UPASSWORD}
EOF
end_message
systemctl restart mariadb.service
cat <<EOF
ステータスがアクティブの場合は起動も成功です
MySQLへのログイン方法
centosユーザーでログインするには下記コマンドを実行してください
mysql --defaults-extra-file=/etc/my.cnf.d/centos.cnf
EOF
else
echo "CentOS7ではないため、このスクリプトは使えません。このスクリプトのインストール対象はCentOS7です。"
fi
fi
else
echo "このスクリプトのインストール対象はCentOS7です。CentOS7以外は動きません。"
cat <<EOF
検証LinuxディストリビューションはDebian・Ubuntu・Fedora・Arch Linux(アーチ・リナックス)となります。
EOF
fi