在开始配置前,需完成以下基础准备工作:
sudo yum update -y确保系统包为最新版本;sudo yum install epel-release -y,扩展软件包来源;Development Tools、mysql-devel等)。# 搜索SQLAdmin包(确认包名,如'sqladmin'或'version-specific')
sudo yum search sqladmin
# 安装SQLAdmin
sudo yum install sqladmin -y
# 验证安装
sqladmin --version
# 安装依赖
sudo yum groupinstall "Development Tools" -y
sudo yum install wget curl git mysql-devel -y
# 下载源码(替换为实际链接)
wget https://github.com/sqladmin/sqladmin/archive/refs/tags/v1.0.0.tar.gz
tar -zxvf v1.0.0.tar.gz
cd sqladmin-1.0.0
# 编译安装
./configure
make
sudo make install
# 验证安装
sqladmin --version
# 安装Python及pip
sudo yum install python3 python3-pip -y
# 升级pip
sudo pip3 install --upgrade pip
# 安装sqladmin
sudo pip3 install sqladmin
# 验证安装
sqladmin --version
若上述方法不可用,可从官方仓库下载源码,按README或INSTALL文件指引编译安装。
SQLAdmin需访问数据库才能管理,需创建专用用户并授权:
# 登录MySQL
mysql -u root -p
# 创建SQLAdmin用户(替换'your_password'为强密码)
CREATE USER 'sqladmin'@'localhost' IDENTIFIED BY 'your_password';
# 授权(根据需求调整权限,如仅需管理可限制为USAGE)
GRANT ALL PRIVILEGES ON *.* TO 'sqladmin'@'localhost' WITH GRANT OPTION;
# 刷新权限
FLUSH PRIVILEGES;
# 退出
exit
安全注意事项:
'sqladmin'@'localhost'而非'%');SQLAdmin通常通过Web界面访问,需配置Web服务器:
# 安装Apache
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
# 创建配置文件(如未自动创建)
sudo vi /etc/httpd/conf.d/sqladmin.conf
配置内容:
<VirtualHost *:80>
ServerName your_domain.com # 替换为域名或IP
DocumentRoot /usr/share/sqladmin # 替换为SQLAdmin安装路径
<Directory /usr/share/sqladmin>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/sqladmin_error.log
CustomLog ${APACHE_LOG_DIR}/sqladmin_access.log combined
</VirtualHost>
重启Apache:sudo systemctl restart httpd
# 安装Nginx
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
# 创建配置文件
sudo vi /etc/nginx/conf.d/sqladmin.conf
配置内容:
server {
listen 80;
server_name your_domain.com; # 替换为域名或IP
root /usr/share/sqladmin; # 替换为SQLAdmin安装路径
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # 根据PHP版本调整
}
location ~ /\.ht {
deny all;
}
}
重启Nginx:sudo systemctl restart nginx。
编辑SQLAdmin配置文件(路径因安装方式而异,常见为/etc/sqladmin/sqladmin.conf或安装目录下的config.inc.php):
# 示例:修改config.inc.php(PHP-based SQLAdmin)
sudo vi /path/to/sqladmin/config.inc.php
关键参数设置:
$cfg['blowfish_secret'] = 'your_random_string'; // 用于cookie加密,需16位以上随机字符
$cfg['DefaultLang'] = 'zh_cn'; // 设置默认语言(如zh_cn为简体中文)
$cfg['Servers'][$i]['host'] = 'localhost'; // 数据库主机
$cfg['Servers'][$i]['user'] = 'sqladmin'; // 数据库用户名
$cfg['Servers'][$i]['password'] = 'your_password'; // 数据库密码
注意:配置文件权限需严格控制,避免敏感信息泄露:
sudo chown root:sqladmin /path/to/sqladmin/config.inc.php
sudo chmod 640 /path/to/sqladmin/config.inc.php
# 开放HTTP(80)和HTTPS(443)端口
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
# 临时允许httpd访问(测试用)
sudo setenforce 0
# 永久修改(需编辑/etc/selinux/config,将SELINUX=enforcing改为disabled)
# 注意:修改前需评估安全风险
http://your_domain.com/sqladmin(或IP),使用sqladmin用户登录;/var/log/httpd/error_log或/var/log/nginx/error.log)。mysqldump备份数据库,存储到异地或云存储;