龍蜥操作系統
Anolis OS 8 是 OpenAnolis 社區推出的完全開源、中立、開放的發行版,它支持多計算架構,也面向云端場景優化,兼容 CentOS 軟件生態。Anolis OS 8 旨在為廣大開發者和運維人員提供穩定、高性能、安全、可靠、開源的操作系統服務。
Apache Tomcat官網: Anolis系統中離線安裝Tomcat與Linux一致,Tomcat下載到本地,上傳解壓運行即可。
MySql官網
Anolis系統中離線安裝MySql數據庫,與Linux安裝方式基本一致。
安裝版本:mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
進入安裝流程
創建目錄
mkdir -p /server/tools
mkdir -p /opt/mysql
mkdir -p /data/mysql/mysql3306/{data,logs}
cd /server/tools #進入到該目錄
解壓安裝包
tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
移動到指定目錄
mv mysql-5.7.26-linux-glibc2.12-x86_64 /opt/mysql/mysql-5.7.26
創建軟連接
ln -s /opt/mysql/mysql-5.7.26/ /usr/local/mysql
編輯配置文件
vi /data/mysql/mysql3306/my3306.cnf
[client]
user=mysql
port= 3306
socket= /data/mysql/mysql3306/mysql.sock
[mysqld]
port= 3306
user=mysql
server_id= 1
basedir=/usr/local/mysql
datadir=/data/mysql/mysql3306/data
log_error=/data/mysql/mysql3306/logs/error.log
log_bin=/data/mysql/mysql3306/logs/mysql-bin
binlog_format=row
gtid_mode=on
enforce_gtid_consistency=true
log_slave_updates=1
max_connections=1024
wait_timeout=60
sort_buffer_size=2M
max_allowed_packet=32M
join_buffer_size=2M
innodb_buffer_pool_size=128M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_log_files_in_group=2
binlog_cache_size=2M
max_binlog_cache_size=8M
max_binlog_size=512M
expire_logs_days=7
slow_query_log=on
slow_query_log_file=/data/mysql/mysql3306/logs/slow.log
long_query_time=0.5
log_queries_not_using_indexes=1
初始化數據庫
初始化數據庫之前如果/data/mysql/mysql3306路徑下有data文件夾,則需要刪除,否則初始化失敗。
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data
加入環境變量
vim /etc/profile #vim編輯
export PATH="/usr/local/mysql/bin:$PATH"
啟動數據庫
mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
查看是否啟動成功
netstat -lntup
啟動數據庫報錯
2025-01-13T09:19:04.303142Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2025-01-13T09:19:04.303159Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
解決報錯
vim /etc/my.cnf
datadir=/var/lib/mysql/data刪除data目錄中的內容
rm -rf data //在mysql安裝目錄下執行
mkdir data
連接數據庫
因為初始化的時候設置了–initialize-insecure,所以登錄時不需要密碼。
第一次連接沒有密碼,直接敲回車:mysql -u root -p
存在問題
啟動數據庫時只能使用:mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
不能使用用:service mysqld start
命令,使用該命令會報如下錯誤:
Starting MySQL.Logging to '/usr/local/mysql/data/anolis.err'.ERROR! The server quit without updating PID file (/usr/local/mysql/data/anolis.pid).
解決辦法
- 將配置文件移動到mysql的安裝目錄
- 修改配置文件中的路徑
- 設置通過命令啟動:
mv /opt/mysql/mysql-5.7.26/support-files/mysql.server /etc/init.d/mysqld
- 設置用戶權限
# 增加用戶和組
[root@anolis ~]# groupadd mysql
[root@anolis ~]# useradd -r -g mysql mysql
# 設置對應的mysql文件權限
# 這里因為/usr/local/mysql/data是創建的/opt/mysql/mysql-5.7.26/的軟鏈接,所以兩個地址實際上是一個
chown mysql:mysql -R /opt/mysql/mysql-5.7.26/
chmod -R 755 /usr/local/mysql/data
- 初始化數據庫
# 進入mysql安裝目錄
cd /usr/local/mysql/data
# 刪除data
rm -rf data/
# 初始化,如果是--initialize的話登錄就需要輸入密碼
./bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize-insecure --user=mysql
# 初始化完成后可進行啟動數據庫
[root@anolis mysql]# service mysqld restartERROR! MySQL server PID file could not be found!
Starting MySQL.. SUCCESS!
登錄數據庫
[root@anolis mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-log MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
# 設置數據庫密碼
mysql> update user set authentication_string=password("數據庫密碼") where user="root";
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 1
# 刷新,否則可能不生效
mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)
# 設置數據庫遠程訪問
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
# 刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 退出
mysql> quit;Bye
設置MySQL開機自啟
設置MySQL開機自啟可以通過chkconfig命令來實現
# 添加到管理列表
chkconfig --add mysqld
# 設置開機自啟動,或者通過chkconfig --level 2345 mysql on命令來指定在運行級2、3、4、5中開啟MySQL服務
chkconfig mysqld on
# 查看設置狀態
chkconfig --list mysqld
[root@anolis ~]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off