分类 运维 下的文章

CENTOS7二进制安装MYSQL.sh

#!/bin/bash
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
yum -y install cmake gcc gcc-c++ bison ncurses ncurses-devel wget
mkdir -p /data/mys &&cd /data/mys
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
tar xf mysql-5.7.22.tar.gz
rm -f mysql-5.7.22.tar.gz
cd /data/mys/mysql-5.7.22/
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz --no-check-certificate
tar xf boost_1_59_0.tar.gz
rm -f boost_1_59_0.tar.gz
mv boost_1_59_0 boost
cmake \
-DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DWITH_BOOST=/data/mys/mysql-5.7.22/boost \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER=1
make && make install
cat >/etc/my.cnf<<EOF
[client]
default-character-set = utf8mb4
socket=/data/mysql/mysql.sock
[mysql]
default-character-set = utf8mb4
[mysqld]
port=3306
user=mysql
basedir=/data/mysql
datadir=/data/mysql/data
log-error=/data/mysql/logs/error.log
socket=/data/mysql/mysql.sock
pid-file=/data/mysql/mysqld.pid
default-time-zone = '+8:00'
innodb_online_alter_log_max_size=128M
innodb_open_files=3000
table_open_cache=2000
innodb_lock_wait_timeout=120
innodb_log_files_in_group=3
thread_cache_size=100
max_connect_errors=200
myisam_sort_buffer_size=64M
back_log=800
server-id=1
innodb_log_file_size=1G
innodb_buffer_pool_size=1G
log_bin_trust_function_creators=1
character_set_server=utf8mb4
default_storage_engine=InnoDB
wait_timeout=28800
expire_logs_days=7
long_query_time=1
binlog_format=ROW
log-bin=mysql-bin
tmp_table_size=64M
read_buffer_size=4M
join_buffer_size=8M
sort_buffer_size=16M
max_heap_table_size=64M
binlog_cache_size=4M
max_allowed_packet=20M
max_connections=2000
long_query_time=1
slow-query-log=ON
log-output=TABLE
default_authentication_plugin = mysql_native_password
symbolic-links=0
lower_case_table_names=1
includedir /etc/my.cnf.d
EOF
mkdir -p /etc/my.cnf.d
mkdir -p /data/mysql/logs
touch /data/mysql/logs/error.log
chown -R mysql:mysql /data/mysql
/data/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/data/mysql \
--datadir=/data/mysql/data
#添加环境变量
cat >>/etc/profile<<EOF
PATH=$PATH:/data/mysql/bin:
EOF
source /etc/profile
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl daemon-reload && systemctl enable mysql && systemctl start mysql
mysqld_safe --defaults-file=/etc/my.cnf
#设置密码为123456并允许从任何地方登陆
mysql -uroot -e "SET PASSWORD = PASSWORD('123456');"
mysql -uroot -p123456 -e "use mysql;UPDATE user SET host = '%' WHERE user = 'root';"
mysql -uroot -p123456 -e "flush privileges;"
rm -fr /data/mys
rm -f $0

环境:

[root@master01 prometheus]# docker -v
Docker version 19.03.14, build 5eb3275d40
[root@master01 prometheus]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.9", GitCommit:"a17149e1a189050796ced469dbd78d380f2ed5ef", GitTreeState:"clean", BuildDate:"2020-04-16T11:44:51Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

docker是19.03.14
k8s是v1.16.9不同版本yaml文件可能有微调

下面上文件
config-map.yaml
grafana.yaml
prometheus.yaml
node-exporter.yaml
rbac-setup.yaml
直接应用上述文件,查看svc:

 [root@rke-master01 prometheus]# kubectl -n kube-system get svc
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                  AGE
grafana          NodePort    172.21.15.98   <none>        3000:31000/TCP           6m8s
kube-dns         ClusterIP   172.21.0.10    <none>        53/UDP,53/TCP,9153/TCP   18d
metrics-server   ClusterIP   172.21.0.11    <none>        443/TCP                  18d
node-exporter    NodePort    172.21.9.202   <none>        9100:31672/TCP           6m8s
prometheus       NodePort    172.21.9.246   <none>        9090:30003/TCP           6m7s

查看pod

 [root@rke-master01 prometheus]# kubectl -n kube-system get pod
NAME                                      READY   STATUS      RESTARTS   AGE
coredns-89bcfc8d5-mxdd4                   1/1     Running     0          18d
coredns-89bcfc8d5-x4dv8                   1/1     Running     0          18d
coredns-autoscaler-976fbb6bf-2q456        1/1     Running     0          18d
grafana-core-5b8dbf444-v2xkq              1/1     Running     0          31m
kube-flannel-4nvgs                        2/2     Running     0          18d
kube-flannel-nbzjv                        2/2     Running     0          18d
kube-flannel-t5m5l                        2/2     Running     0          18d
metrics-server-8cdbf5cd7-bmp2q            1/1     Running     0          18d
node-exporter-26b7h                       1/1     Running     0          30m
node-exporter-99p6b                       1/1     Running     0          30m
node-exporter-p4flt                       1/1     Running     0          30m
prometheus-759d85775b-2589h               1/1     Running     0          34m

都是running就可以通过192.168.100.241:31000访问grafana了,默认账号密码都是admin
进去后如图添加数据库,再import-315就可以看到一些基础数据了。
添加数据库