龙蜥操作系统
Anolis OS 8 是 OpenAnolis 社区推出的完全开源、中立、开放的发行版,它支持多计算架构,也面向云端场景优化,兼容 CentOS 软件生态。Anolis OS 8 旨在为广大开发者和运维人员提供稳定、高性能、安全、可靠、开源的操作系统服务。
安装JDK
解压
先把 jdk1.8.0_11.tar.gz 放到 /usr/local/。(当然你也可以根据自己的需要,放到其他位置)
解压 jdk1.8.0_11.tar.gz 在当前目录下得到 jdk1.8.0_11 文件夹
tar -zxvf jdk1.8.0_11.tar.gz
设置环境变量
vi /etc/profile # 文件末尾配置环境变量
export JAVA_HOME=/usr/local/jdk1.8.0_11
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
刷新配置
source /etc/profile
查看版本
java -version
安装Tomcat
Apache Tomcat官网: Anolis系统中离线安装Tomcat与Linux一致,Tomcat下载到本地,上传解压运行即可。
MySql官网
Anolis系统中离线安装MySql数据库,与Linux安装方式基本一致。
安装版本:mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
进入安装流程
安装mysql时,也可安装到默认目录/usr/local/mysql
创建目录
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 restart
ERROR! 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 -A
Database 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 native
systemd services. SysV configuration data might be overridden by native
systemd 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
问题解决
- 启动数据库报错
root@anolis mysql]# ./bin/mysqld --defaults-file=my.cnf &
[1] 64437
[root@anolis mysql]# mysqld: Error on realpath() on '/usr/local/mysql/file' (Error 2 - No such file or directory)
2024-05-15T04:07:25.262369Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-05-15T04:07:25.262472Z 0 [ERROR] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /usr/local/mysql/file
2024-05-15T04:07:25.262480Z 0 [ERROR] Aborting
2024-05-15T04:07:25.262485Z 0 [Note] Binlog end
#在文件安装目录创建file
- 登录数据库报错
# 修改密码报错
update user set authentication_string=password("数据库密码") where user="root";
You have an error in your sql syntax;check the manual that corresponds to your Mysql server version for the right syntax to use near'('123456') where user='root'' at line 1
# 更换修改密码语句
ALTER USER 'root'@'%' IDENTIFIED BY 'new_password';
[root@anolis usr]# mysql -u root -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
# 该问题由于系统中未安装对应5版本库件导致
root@anolis usr]# find /usr/ -name 'libncurses.so*'
/usr/lib64/libncurses.so.6
/usr/lib64/libncurses.so.6.4
[root@anolis usr]# sudo ln -s /usr/lib64/libncurses.so.6.4 /usr/lib64/libncurses.so.5
[root@anolis usr]# mysql -u root -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
[root@anolis usr]# sudo systemctl restart mysqld
# 二次登录
[root@anolis usr]# mysql -u root -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
[root@anolis usr]# find /usr/ -name 'libtinfo.so*'
/usr/lib64/libtinfo.so.6
/usr/lib64/libtinfo.so.6.4
[root@anolis usr]# sudo ln -s /usr/lib64/libtinfo.so.6.4 /usr/lib64/libtinfo.so.5
[root@anolis usr]# find /usr/ -name 'libtinfo.so*'
/usr/lib64/libtinfo.so.6
/usr/lib64/libtinfo.so.6.4
/usr/lib64/libtinfo.so.5
[root@anolis usr]# 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;
- my.cnf文件内容
[client]
port= 3306
# socket= /usr/local/mysql/data/mysql.sock
[mysqld]
port= 3306
user=mysql
server_id= 1
gtid-mode=on
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysql.pid
secure-file-priv=/usr/local/mysql/file
log_error=/usr/local/mysql/logs/error.log
log-bin=mysql-bin
log_bin=/usr/local/mysql/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=1024M
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=/usr/local/mysql/logs/slow.log
long_query_time=0.5
log_queries_not_using_indexes=1
- mysql数据库目录