centos7配置mariadb
一、安装及配置:[*]下载mariadb:
yum -y install mariadb-server mariadb
[*]开启mariadb服务:
systemctl start mariadb
[*]无密码登录mariadb:
mysql
[*]查看用户表:
select * from mysql.user\G
[*]添加远程访问用户:
grant all on *.* to 'root'@'%' identified by '123456'
[*]设置添加用户的授权权限:
update mysql.user set Grant_priv='Y' where Host='%'
[*]移除匿名用户:
delete from mysql.user where Host'%' or User'root'
[*]退出mariadb命令行:
quit
[*]修改字符集:
vim/etc/my.cnf
character-set-server=utf8mb4
[*]修改端口号:
port=8033
[*]配置文件参考:
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
character-set-server=utf8mb4
port=8033
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
[*]重启mariadb:
systemctl restart mariadb
[*]执行语句:
mysql-uroot-p123456-e 'select*frommysql.user '
[*]执行文件内命令:
mysql-uroot-p123456<test.sql
[*]备份:
mysqldump-uroot-p123456--all-databases>backup.sql
mysqldump-uroot-p123456test>backup.sql
二、主从复制:
[*]服务器列表:
角色 ip地址
主服务器 192.168.8.81
从服务器 192.168.8.82
[*]主服务器的配置(192.168.8.81):
a. 配置:
vim/etc/my.cnf
http://i2.运维网.com/images/blog/201805/22/013e198953d084f1477920e3fd9dddfb.png
b. 重启:
systemctlrestartmariadb
[*]从服务器配置(192.168.8.82):
a. 配置:
vim/etc/my.cnf
http://i2.运维网.com/images/blog/201805/22/710f2371fbc761dc2496357315b282cb.png
b. 重启:
systemctlrestartmariadb
[*]主服务器设置(192.168.8.81):
a. 进入命令行:
http://i2.运维网.com/images/blog/201801/23/145c6887ba38d726552bb59ed7b098ed.png
b. 查看状态:
http://i2.运维网.com/images/blog/201801/23/679a5ecd1fa99958a4f4253596fe29ec.png
[*]从服务器设置(192.168.8.82):
a. 进入命令行:
http://i2.运维网.com/images/blog/201801/23/160ab1a863aed4766b9d74857aa26a3c.png
b. 配置:
change master to
master_host='xx.xx.xx.xx',
master_port=xxxx,
master_user='root',
master_password='123456',
master_log_file='dollarphp.000002',
master_log_pos=245;
http://i2.运维网.com/images/blog/201801/23/b90a4ab339d87d7fb5163b6835da70d3.png
c. 开启:
http://i2.运维网.com/images/blog/201801/23/bec80ee94905057c2e7d7780b391f746.png
d. 查看状态:
http://i2.运维网.com/images/blog/201801/23/cbedefaebb4fb56bff608f5756521853.png
[*]测试:
a. 主:
http://i2.运维网.com/images/blog/201801/23/f92cf51b726db533250e0b46d5a5a417.png
b. 从:
http://i2.运维网.com/images/blog/201801/23/5d5e875922b95951729b8714331303a6.png
三、读写分离:
[*]安装代理:
yum-yinstallmysql-proxy
[*]主文件配置:
vim/etc/sysconfig/mysql-proxy
ADMIN_USER="admin"
ADMIN_PASSWORD=""
ADMIN_LUA_SCRIPT="/usr/lib64/mysql-proxy/lua/admin.lua"
PROXY_USER="mysql-proxy"
PROXY_OPTIONS="--defaults-file=/etc/mysql-proxy.cnf"
[*]代理文件配置:
a. 修改文件:
vim/etc/mysql-proxy.cnf
user = root
admin-username=root
admin-password=123456
proxy-address = 0.0.0.0:4000
proxy-backend-addresses = 192.168.8.81:3306#主,多个以逗号分隔
proxy-read-only-backend-addresses=192.168.8.82:3306#从,多个以逗号分隔
proxy-lua-script=/usr/lib64/mysql-proxy/lua/proxy/balance.lua
admin-lua-script=/usr/lib64/mysql-proxy/lua/admin.lua
log-file = /var/log/mysql-proxy.log
log-level = debug
daemon = true
keepalive = true
b. 更改权限:
chmod0660/etc/mysql-proxy.cnf
[*]修复启动脚本:
a. 修改启动文件:
vim/etc/init.d/mysql-proxy
将
[ ${NETWORKING} = "no" ] && exit 0
修改为
[ "${NETWORKING}" = "no" ] && exit 0
将
daemon $prog $PROXY_OPTIONS --pid-file=$PROXY_PID --user=$PROXY_USER --admin-username="$ADMIN_USER" --admin-lua-script="$ADMIN_LUA_SCRIPT" --admin-password="$ADMIN_PASSWORD"
修改为
daemon $prog $PROXY_OPTIONS --pid-file=$PROXY_PID
http://i2.运维网.com/images/blog/201806/15/e7e1485d90c3affe403fefeb1e5c8d44.png
http://i2.运维网.com/images/blog/201805/24/4347bc0b55407754fef382cfdc7555f9.png
b. 加载启动文件:
systemctldaemon-reload
[*]启动服务:
systemctlstartmysql-proxy
[*]测试:
mysql-h192.168.8.81-uroot-p123456--port=4000
http://i2.运维网.com/images/blog/201805/24/bc6fb323e216fe002ac1379b123e02ee.png
四、coreseek(sphinx:不推荐使用):
[*]安装依赖:
yum-yinstallmakegccgcc-c++libtoolautoconfautomakeimakemariadbmariadb-servermariadb-devel libxml2-devel expat-devel
[*]下载软件包:
a. 克隆:
gitclonehttps://github.com/dollarphper/soft.git
b. 进入目录:
cdsoft
[*]解压缩:
tar-xzfcoreseek-4.1-beta.tar.gz
[*]安装mmseg:
a. 进入目录:
cdcoreseek-4.1-beta/mmseg-3.2.14/
b. 安装:
./bootstrap
./configure --prefix=/usr/local/mmseg3
make && make install
[*]安装coreseek:
a. 进入目录:
cd../csft-4.1
b. 修改配置文件:
vimconfigure.ac
将
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
修改为
AM_INIT_AUTOMAKE([-Wall foreign])
c. 下载软件:
yum-yinstallpatch
d. 打补丁:
patch-p1</home/lee/sphinx/sphinxexpr.cpp-csft-4.1-beta.patch
输入:
/home/lee/sphinx/coreseek-4.1-beta/csft-4.1/src/sphinxexpr.cpp
http://i2.运维网.com/images/blog/201805/22/7bda8bb8d527430b3e4313e45c5431c3.png
e. 安装:
shbuildconf.sh
./configure--prefix=/usr/local/coreseek--without-unixodbc--with-mmseg--with-mmseg-includes=/usr/local/mmseg3/include/mmseg/--with-mmseg-libs=/usr/local/mmseg3/lib/--with-mysql
make&&make install
[*]测试:
a. 进入测试目录:
cd../testpack/
b. 查看测试文件:
catvar/test/test.xml
http://i2.运维网.com/images/blog/201805/22/b9f4baa3050b36218a434ce26fa7a720.png
c. 测试中文分词:
/usr/local/mmseg3/bin/mmseg-d/usr/local/mmseg3/etc var/test/test.xml
http://i2.运维网.com/images/blog/201805/22/d0ada2b4a7002fbd69560ce7f9445a43.png
d. 创建索引:
/usr/local/coreseek/bin/indexer-cetc/csft.conf--all
http://i2.运维网.com/images/blog/201805/22/9b4db72cf1151c9af3dcdab8d7ccd36a.png
e. 搜索测试:
/usr/local/coreseek/bin/search-cetc/csft.conf李彦宏
http://i2.运维网.com/images/blog/201805/22/ae0726db656bf203992eb7dcec1c648a.png
[*]php连接sphinx:
a. 安装扩展:
a-1. 进入目录:
cd../csft-4.1/api/libsphinxclient/
a-2. 编译:
aclocal
libtoolize --force
automake --add-missing
autoconf
autoheader
make clean
./configure--prefix=/usr/local/sphinxclient
make&&make install
a-3. 回到软件包目录:
cd../../../../
a-4. 解压:
tar-xzfsphinx-1.3.0.tgz
a-5. 安装php-devel:
yum-yinstallphpphp-devel
a-6. 进入目录:
cdsphinx-1.3.0
a-7. 安装:
phpize
./configure --with-php-config=/usr/bin/php-config --with-sphinx=/usr/local/sphinxclient
make && make install
a-8. 开启php-sphinx扩展:
vim/etc/php.ini
在末尾加上:
extension=sphinx.so
b. 测试:
b-1. 启动mariadb服务:
systemctlstartmariadb
b-2. 添加测试数据:
mysql-uroot-p123456</usr/local/coreseek/etc/example.sql
b-3. 复制配置文件:
cp/usr/local/coreseek/etc/sphinx.conf.dist/usr/local/coreseek/etc/csft.conf
cp/home/lee/sphinx/coreseek-4.1-beta/mmseg-3.2.14/data/*/usr/local/mmseg3/etc/
b-4. 修改配置文件:
vim/usr/local/coreseek/etc/csft.conf
source src1
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = 123456
sql_db = test
sql_port = 3306# optional, default is 3306
sql_query_pre = SET NAMES utf8
sql_sock = /var/lib/mysql/mysql.sock
sql_query = \
SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
FROM documents
sql_attr_uint = group_id
sql_attr_timestamp= date_added
sql_ranged_throttle = 0
sql_query_info_pre = SET NAMES utf8
sql_query_info = SELECT * FROM documents WHERE id=$id
}
source src1throttled : src1
{
sql_ranged_throttle = 100
}
index test1
{
source = src1
path = /usr/local/coreseek/var/data/test1
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
html_strip = 0
charset_dictpath = /usr/local/mmseg3/etc/
charset_type = zh_cn.utf-8
}
indexer
{
mem_limit = 128M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /usr/local/coreseek/var/log/searchd.log
query_log = /usr/local/coreseek/var/log/query.log
read_timeout = 5
client_timeout = 300
max_children = 30
pid_file = /usr/local/coreseek/var/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
mva_updates_pool = 1M
max_packet_size = 8M
max_filters = 256
max_filter_values = 4096
max_batch_queries = 32
workers = threads # for RT to work
}
b-5. :复制二进制文件:
cp/usr/local/coreseek/bin/*/usr/bin/
b-6. 生成索引:
indexer--rotate--all-c/usr/local/coreseek/etc/csft.conf
b-7. 启动服务:
searchd-c/usr/local/coreseek/etc/csft.conf
b-8. 停止服务:
searchd--stop
b-9. 测试:
b-9-1. 编写测试脚本:
vimtest.php
页:
[1]