首页 > 其他分享 >35_安装mariadb

35_安装mariadb

时间:2024-03-13 10:57:41浏览次数:27  
标签:mysql1 安装 bkApi 35 bk p01 go mariadb root

1.安装 mariadb
# 1. 安装
[root@mysql1 ~] yum -y  install mariadb-server
[root@mysql1 ~]# systemctl start mariadb
[root@mysql1 ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@mysql1 ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.5 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
     Active: active (running) since Mon 2023-11-06 21:13:26 CST; 19s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 25550 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 13 (limit: 11125)
     Memory: 78.1M
        CPU: 698ms
     CGroup: /system.slice/mariadb.service
             └─25550 /usr/libexec/mariadbd --basedir=/usr
Nov 06 21:13:25 mysql1 mariadbd[25550]: 2023-11-06 21:13:25 0 [Note] /usr/libexec/mariadbd (mysqld 10.5.16-MariaDB) starting as process 25550 ...
Nov 06 21:13:26 mysql1 systemd[1]: Started MariaDB 10.5 database server.

# 2. 查看端口
[root@mysql1 ~]# netstat -antulp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      596/sshd: /usr/sbin
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd
tcp        0      0 10.10.10.102:22         10.10.10.1:37344        ESTABLISHED 3994/sshd: root [pr
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd
tcp6       0      0 :::3306                 :::*                    LISTEN      25550/mariadbd
udp        0      0 10.10.10.102:68         10.10.10.1:67           ESTABLISHED 538/NetworkManager
udp        0      0 0.0.0.0:111             0.0.0.0:*                           1/systemd
udp        0      0 127.0.0.1:323           0.0.0.0:*                           552/chronyd
udp6       0      0 :::111                  :::*                                1/systemd
udp6       0      0 ::1:323                 :::*                                552/chronyd
[root@mysql1 ~]#
[root@mysql1 ~]#
[root@mysql1 ~]# netstat -antulp | grep mariadb
tcp6       0      0 :::3306                 :::*                    LISTEN      25550/mariadbd

# 3. 更改端口为12122
[root@mysql1 ~]# cat /etc/my.cnf.d/mariadb-server.cnf | grep -A5 -B5 port
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld/mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld]
port=12122
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/run/mariadb/mariadb.pid
[root@mysql1 ~]# cat /etc/my.cnf.d/mariadb-server.cnf | grep -A5 -B5 port
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld/mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld]
port=12122
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/run/mariadb/mariadb.pid

[root@mysql1 ~]#
[root@mysql1 ~]# systemctl restart mariadb.service
[root@mysql1 ~]#
[root@mysql1 ~]# netstat -antulp | grep mariadb
tcp6       0      0 :::12122                :::*                    LISTEN      25838/mariadbd

# 4. 数据库设置
[root@mysql1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.5.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# 创建blog数据库
MariaDB [(none)]> CREATE DATABASE blog;
# 设置字符集
MariaDB [(none)]> ALTER DATABASE blog CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

# 创建用户设置密码
MariaDB [(none)]> CREATE USER 'ckh'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.007 sec)

# 用户访问表 授权
MariaDB [(none)]> GRANT ALL ON blog.* TO 'ckh'@'%';
Query OK, 0 rows affected (0.005 sec)

# 刷新权限
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

# 以该用户登录查看权限
[root@mysql1 ~]# mysql -uckh -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.5.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| blog               |
| information_schema |
+--------------------+
2 rows in set (0.001 sec)


# 5. 复制我的源码到mysql1(提前安装go) scp 命令
[root@kvm ~]# ls
createVM.sh  Desktop  Documents  Downloads  Music  p01_bk-p01_bkApi.zip  Pictures  Public  Templates  tmp  Videos
[root@kvm ~]# scp p01_bk-p01_bkApi.zip [email protected]:/root
Warning: Permanently added '10.10.10.78' (ED25519) to the list of known hosts.
[email protected]\s password:
p01_bk-p01_bkApi.zip

# mysql1 上安装解压zip包的命令
[root@mysql1 ~]# yum -y install unzip
[root@mysql1 ~]# unzip p01_bk-p01_bkApi.zip
[root@mysql1 ~]# ls
install_go.sh  p01_bk-p01_bkApi  p01_bk-p01_bkApi.zip
[root@mysql1 ~]# cd p01_bk-p01_bkApi/
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# ls
conf  controllers  go.mod  go.sum  lastupdate.tmp  LICENSE  main.go  models  package-lock.json  README.md  routers  scripts  tests  word

# 安装golang api 运行依赖包
[root@mysql1 p01_bk-p01_bkApi]# go mod vendor
# 创建日志目录
[root@mysql1 p01_bk-p01_bkApi]# mkdir /root/p01_bk-p01_bkApi/log
# 启动 api 项目
[root@mysql1 p01_bk-p01_bkApi]# bee run # 要看到 http://:8092
______
| ___ \
| |_/ /  ___   ___
| ___ \ / _ \ / _ \
| |_/ /|  __/|  __/
\____/  \___| \___| v2.1.0
2023/11/06 23:05:23 WARN     ▶ 0001 Running application outside of GOPATH
2023/11/06 23:05:23 INFO     ▶ 0002 Using 'p01_bk-p01_bkApi' as 'appname'
2023/11/06 23:05:23 INFO     ▶ 0003 Initializing watcher...
2023/11/06 23:05:24 SUCCESS  ▶ 0004 Built Successfully!
2023/11/06 23:05:24 INFO     ▶ 0005 Restarting 'p01_bk-p01_bkApi'...
2023/11/06 23:05:24 SUCCESS  ▶ 0006 './p01_bk-p01_bkApi' is running...
2023/11/06 23:05:24.196 [I] [parser.go:85]  /root/p01_bk-p01_bkApi/controllers no changed

2023/11/06 23:05:24.197 [I] [server.go:241]  http server Running on http://:8092

# client1 上 获取数据
[root@client1 ~]# curl http://10.10.10.102:8092/v1/code/labels?token=wgnowehgiowGW66OEHGO.WEfwe12

# 生成可执行程序,放到后台执行
[root@mysql1 p01_bk-p01_bkApi]# ls
conf  controllers  go.mod  go.sum  lastupdate.tmp  LICENSE  log  main.go  models  package-lock.json  README.md  routers  scripts  tests  vendor  word
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# go build
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# ls
conf  controllers  go.mod  go.sum  lastupdate.tmp  LICENSE  log  main.go  models  p01_bkApi  package-lock.json  README.md  routers  scripts  tests  vendor  word
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# chmod +x p01_bkApi
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# ./p01_bkApi
2023/11/06 23:23:35.731 [I] [parser.go:85]  /root/p01_bk-p01_bkApi/controllers no changed

2023/11/06 23:23:35.731 [I] [server.go:241]  http server Running on http://:8092

2023/11/06 23:23:40.670 [D] [router.go:955]  |    10.10.10.78| 200 |   4.435923ms|   match| GET      /v1/code/labels   r:/v1/code/labels

^C
[root@mysql1 p01_bk-p01_bkApi]# ls
conf  controllers  go.mod  go.sum  lastupdate.tmp  LICENSE  log  main.go  models  p01_bkApi  package-lock.json  README.md  routers  scripts  tests  vendor  word
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# ./p01_bkApi &
[1] 27616
[root@mysql1 p01_bk-p01_bkApi]# 2023/11/06 23:24:10.540 [I] [parser.go:85]  /root/p01_bk-p01_bkApi/controllers no changed

2023/11/06 23:24:10.540 [I] [server.go:241]  http server Running on http://:8092


[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# ls
conf  controllers  go.mod  go.sum  lastupdate.tmp  LICENSE  log  main.go  models  p01_bkApi  package-lock.json  README.md  routers  scripts  tests  vendor  word
[root@mysql1 p01_bk-p01_bkApi]# ls
conf  controllers  go.mod  go.sum  lastupdate.tmp  LICENSE  log  main.go  models  p01_bkApi  package-lock.json  README.md  routers  scripts  tests  vendor  word
[root@mysql1 p01_bk-p01_bkApi]# ps -ef | grep Api
root       27616   26451  0 23:24 pts/0    00:00:00 ./p01_bkApi
root       27624   26451  0 23:24 pts/0    00:00:00 grep --color=auto Api
[root@mysql1 p01_bk-p01_bkApi]# 2023/11/06 23:24:40.386 [D] [router.go:955]  |    10.10.10.78| 200 |   3.613273ms|   match| GET      /v1/code/labels   r:/v1/code/labels

# 但是日志输出还是打印到前台了
[root@mysql1 p01_bk-p01_bkApi]# ls2023/11/06 23:27:52.144 [D] [router.go:955]  |    10.10.10.78| 200 |   4.848498ms|   match| GET      /v1/code/labels   r:/v1/code/labels

2023/11/06 23:27:52.728 [D] [router.go:955]  |    10.10.10.78| 200 |   2.428822ms|   match| GET      /v1/code/labels   r:/v1/code/labels

2023/11/06 23:27:53.309 [D] [router.go:955]  |    10.10.10.78| 200 |   4.407138ms|   match| GET      /v1/code/labels   r:/v1/code/labels

2023/11/06 23:27:53.866 [D] [router.go:955]  |    10.10.10.78| 200 |   4.231196ms|   match| GET      /v1/code/labels   r:/v1/code/labels

^C
# 使用nohup
[root@mysql1 p01_bk-p01_bkApi]# ps -aux | grep Api
root       27616  0.0  1.4 1096940 26488 pts/0   Sl   23:24   0:00 ./p01_bkApi
root       27632  0.0  0.1   6408  2176 pts/0    S+   23:29   0:00 grep --color=auto Api
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# kill -9 27616
[root@mysql1 p01_bk-p01_bkApi]#
[1]+  Killed                  ./p01_bkApi
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# ls
conf  controllers  go.mod  go.sum  lastupdate.tmp  LICENSE  log  main.go  models  p01_bkApi  package-lock.json  README.md  routers  scripts  tests  vendor  word
[root@mysql1 p01_bk-p01_bkApi]# nohup ./p01_bkApi &
[1] 27636
[root@mysql1 p01_bk-p01_bkApi]# nohup: ignoring input and appending output to 'nohup.out'

[root@mysql1 p01_bk-p01_bkApi]# ls
conf  controllers  go.mod  go.sum  lastupdate.tmp  LICENSE  log  main.go  models  nohup.out  p01_bkApi  package-lock.json  README.md  routers  scripts  tests  vendor  word
[root@mysql1 p01_bk-p01_bkApi]# cat nohup.out
2023/11/06 23:30:05.988 [I] [parser.go:85]  /root/p01_bk-p01_bkApi/controllers no changed

2023/11/06 23:30:05.988 [I] [server.go:241]  http server Running on http://:8092

[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# cat nohup.out
2023/11/06 23:30:05.988 [I] [parser.go:85]  /root/p01_bk-p01_bkApi/controllers no changed

2023/11/06 23:30:05.988 [I] [server.go:241]  http server Running on http://:8092

2023/11/06 23:30:33.162 [D] [router.go:955]  |    10.10.10.78| 200 |   7.940736ms|   match| GET      /v1/code/labels   r:/v1/code/labels

2023/11/06 23:30:33.680 [D] [router.go:955]  |    10.10.10.78| 200 |   2.550892ms|   match| GET      /v1/code/labels   r:/v1/code/labels

2023/11/06 23:30:34.216 [D] [router.go:955]  |    10.10.10.78| 200 |   3.955831ms|   match| GET      /v1/code/labels   r:/v1/code/labels

2023/11/06 23:30:34.720 [D] [router.go:955]  |    10.10.10.78| 200 |   5.085136ms|   match| GET      /v1/code/labels   r:/v1/code/labels

# 这两个服务都不能挂掉
[root@mysql1 p01_bk-p01_bkApi]# ps -ef | grep Api
root       27636   26451  0 23:30 pts/0    00:00:00 ./p01_bkApi
root       27661   26451  0 23:36 pts/0    00:00:00 grep --color=auto Api
[root@mysql1 p01_bk-p01_bkApi]#
[root@mysql1 p01_bk-p01_bkApi]# systemctl status mariadb.service
● mariadb.service - MariaDB 10.5 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
     Active: active (running) since Mon 2023-11-06 22:29:30 CST; 1h 7min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 26224 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/SUCCESS)
    Process: 26247 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
    Process: 26299 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=0/SUCCESS)
   Main PID: 26282 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 12 (limit: 11125)
     Memory: 79.7M
        CPU: 2.814s
     CGroup: /system.slice/mariadb.service
             └─26282 /usr/libexec/mariadbd --basedir=/usr

Nov 06 22:29:29 mysql1 systemd[1]: Starting MariaDB 10.5 database server...
Nov 06 22:29:30 mysql1 mariadb-prepare-db-dir[26247]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
Nov 06 22:29:30 mysql1 mariadb-prepare-db-dir[26247]: If this is not the case, make sure the /var/lib/mysql is empty before running mariadb-prepare-db-dir.
Nov 06 22:29:30 mysql1 mariadbd[26282]: 2023-11-06 22:29:30 0 [Note] /usr/libexec/mariadbd (mysqld 10.5.16-MariaDB) starting as process 26282 ...
Nov 06 22:29:30 mysql1 systemd[1]: Started MariaDB 10.5 database server.


# 配置开机自启
[root@kvm2 ~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
bash /root/MyScripts/runApi.sh
[root@kvm2 ~]#
[root@kvm2 ~]#
[root@kvm2 ~]# cat /root/MyScripts/runApi.sh
#!/bin/bash
sleep 30
cd /root/p01_bk-p01_bkApi
chmod +x p01_bk-p01_bkApi
nohup ./p01_bk-p01_bkApi &

标签:mysql1,安装,bkApi,35,bk,p01,go,mariadb,root
From: https://www.cnblogs.com/ckh2023/p/18070137

相关文章

  • Nginx安装nginx-rtmp-module模块
    简介nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。流程查看当前nginx的版本(假设安装位置为:/usr/local/nginx)下......
  • npm安装失败解决方案
    分析过后这个问题是证书过期的意思考虑到其他的原因这里给出三个解决方案一:清除npm缓存npmcacheclean--force取消ssl验证:npmconfigsetstrict-sslfalse之后再npminstall二:npmconfigsetregistryhttp://registry.cnpmjs.orgnpmconfigsetregistryhttp://registry.n......
  • Conda 安装本地 bz2 包方法
    将tar.bz2文件复制到Anaconda/pkgs文件夹下。如果是Miniconda,则文件路径为miniconda3/pkgs如果之前在终端下载过该包的缓存文件,则先删除该缓存文件再复制。打开终端,将位置定位到Anaconda/pkgs文件夹下,使用指令condainstall--use-localpkg-name进行本地安装。以......
  • windwos下mysql5.7安装connection_control插件,限制多次登录失败,限定用户重试时间
    启动时加载插件,在配置文件中修改后重启服务[mysqld]plugin-load-add=connection_control.dll运行时加载插件INSTALLPLUGINCONNECTION_CONTROLSONAME'connection_control.dll';INSTALLPLUGINCONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTSSONAME'connection_control.dl......
  • 用QT开发Android投屏软件--上传文件和安装apk
    这篇文章我们给Android投屏软件增加文件上传和安装apk的功能。上传文件和安装apk对pc端的操作基本没有差别,因为apk也是一种文件格式。通过点击按钮或者拖动待上传(安装)的文件到投屏窗口,软件获取到文件路径,执行不同的adb命令。上传文件的adb命令:adb-s设备序列号push<电......
  • python软件安装
    WelcometoPython.org一:打开这个网址(如下图所示)二:点击下方图标将会跳转到下面这个页面三:将页面翻到下图位置随便选择一个版本下载即可(尽量选择低于最新版本的几个版本)四:安装这个软件在cmd里面,输入python,出来这个结果,即为安装成功......
  • 【Spark编程基础】实验二Spark和Hadoop的安装(附源代码)
    文章目录一、实验目的二、实验平台三、实验内容和要求1.HDFS常用操作2、Spark读取文件系统的数据四、实验过程一、实验目的(1)掌握在Linux虚拟机中安装Hadoop和Spark的方法;(2)熟悉HDFS的基本使用方法;(3)掌握使用Spark访问本地文件和HDFS文件的方法。二、......
  • win11 安装make (gnumake)
    在vscode安装一个插件时,需要用到make工具,因此安装make,虽然根据https://zhuanlan.zhihu.com/p/630244738 可以在https://gnuwin32.sourceforge.net/packages/make.htm直接下载编译好的windows下的makesetup安装包,但是我嫌弃它版本太低了,所以找了个安装最新版的方式。参考:ht......
  • 错误:在 /tmp/easy_install-rad8_t5b/PyQt5-5.14.0.tar.gz #15 中找不到安装脚本
    thePyQt55.14.0isbrokenbecausecan'tnotinstallonresppi3.youcantoinstallaversionofPyQt5thatworkingfineonresp.followthesteps:PyQt55.14.0已损坏,因为无法无法安装在resppi3上。您可以安装一个在resp上运行良好的PyQt5版本,请按照以下......
  • 安装JDK11+Tomcat10.0.1+eclipse-jee-2023-12-R-win32-x86_64 配置
    第一步,先双击启动软件:改一下名称:C:\Users\Administrator\eclipse-workspace变成:C:\ProgramFiles\JavaJava:为什么JSP文件要放到SpringBoot工程的src/main/webapp目录下参考文章:https://blog.csdn.net/netyeaxi/article/details/100928105为了看到更具体的页面,可以做个性化......