上篇詳解了CentOS安裝LNMP+MongoDB生產(chǎn)環(huán)境,現(xiàn)在詳解它們的部署,多數(shù)已經(jīng)在安裝時(shí)執(zhí)行過(guò)了,此處主要做解釋以及常用維護(hù):
成都創(chuàng)新互聯(lián)專注于秦淮企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計(jì),購(gòu)物商城網(wǎng)站建設(shè)。秦淮網(wǎng)站建設(shè)公司,為秦淮等地區(qū)提供建站服務(wù)。全流程按需定制網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
============================================= MySQL
#用戶組
groupadd mysql
#用戶
useradd -g mysql mysql -s /bin/false
#MySQL數(shù)據(jù)庫(kù)存放目錄
/home/mysql/data
#MySQL運(yùn)行目錄
/usr/local/mysql
#配置文件
/etc/my.cnf
#服務(wù)腳本
/etc/rc.d/init.d/mysqld
#通信文件
/var/lib/mysql/mysql.sock
#改默認(rèn)密碼sql
alter user 'root'@'localhost' identified by 'sa';
#允許root遠(yuǎn)程登錄,改密碼為'sa'的sql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'sa' WITH GRANT OPTION;
flush privileges;
#禁止root遠(yuǎn)程登錄的sql
delete from mysql.user where host<>'localhost' and user='root';
flush privileges;
#讀寫(xiě)賬號(hào)
#master 寫(xiě)
>mysql grant select,insert,update,delete,create,alter,index on mydb.* to 'web'@'%' identified by '123456';
>mysql flush privileges;
#slave 讀
>mysql grant select on mydb.* to 'web'@'%' identified by '123456';
>mysql flush privileges;
============================================= nginx
#用戶組
groupadd www
#用戶
useradd -g www www -s /bin/false
#運(yùn)行目錄
/usr/local/nginx
#服務(wù)腳本
/etc/rc.d/init.d/nginx
#配置文件
/usr/local/nginx/conf/nginx.conf
#網(wǎng)站根目錄
/usr/local/nginx/html/
============================================= php
#運(yùn)行目錄
/usr/local/php
#ini文件,帶軟鏈接
ln -s /usr/local/php/etc/php.ini /etc/php.ini
#配置文件,帶軟鏈接
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
#服務(wù)腳本
/etc/rc.d/init.d/php-fpm
#安裝php擴(kuò)展,比如“xxx”;所有此般編譯后的so都應(yīng)在/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
cd xxx
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
vi /usr/local/php/etc/php.ini #加入 extension="xxx.so"
#memcache服務(wù)運(yùn)行目錄
/usr/local/memcached
#memcache服務(wù)腳本
/etc/init.d/memcached
============================================= MongoDB
#用戶組
groupadd mongodb
#用戶
useradd -g mongodb mongodb -s /bin/false
#運(yùn)行目錄
/usr/local/mongodb
#數(shù)據(jù)目錄
mkdir -p /home/mongodb/db
#日志目錄
mkdir -p /home/mongodb/log
#配置文件
/usr/local/mongodb/mongodb.conf
#pid路徑
/usr/local/mongodb/mongo.pid
#服務(wù)腳本
/etc/rc.d/init.d/mongod
#【??!坑??!】重啟mongodb進(jìn)程后,必須重啟php-fpm、httpd、java等所有已連接客戶端的進(jìn)程,否則返回“Remote server has closed the connection”
#啟動(dòng)MongoDB
mongo #進(jìn)入MongoDB控制臺(tái)
show dbs #查看默認(rèn)數(shù)據(jù)庫(kù)
use admin #切換到admin數(shù)據(jù)庫(kù)
exit #退出MongoDB控制臺(tái)
#創(chuàng)建索引
>mongo db.table01.ensureIndex({"myid":1});
============================================== sphinx
#運(yùn)行目錄
/usr/local/sphinx
#配置文件
/usr/local/sphinx/etc/sphinx.conf
#索引文件存放目錄
/home/sphinx
#服務(wù)腳本
/etc/rc.d/init.d/sphinx
#啟動(dòng)進(jìn)程
/usr/local/sphinx/bin/searchd -c /usr/local/sphinx/etc/sphinx.conf
#重建索引
/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all --rotate
#停止索引和進(jìn)程
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf --stop
#如果sphinx文件太大,刪除對(duì)應(yīng)存放目錄文件再重建增量索引文件夾
cd /home/sphinx/
rm * -fr
mkdir indexdelta
# 如果sphinx服務(wù)無(wú)法啟動(dòng)或者啟動(dòng)有錯(cuò)誤,可嘗試重命名 mv /usr/local/sphinx/var/data/binlog.meta文件,再重啟則ok
============================================== jre
yum install java-1.8.0-openjdk-devel
vi /etc/profile
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_71
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
:wq!
source /etc/profile
============================================== mysql 同步
# 讀寫(xiě)賬號(hào)
master 寫(xiě)
grant select,insert,update,delete,create,alter,index on sqtdb.* to 'web'@'%' identified by '123456';
flush privileges;
slave 讀
grant select on sqtdb.* to 'web'@'%' identified by '123456';
flush privileges;
********* master vi /etc/my.cnf
[mysqld]
server-id=100
binlog-format=mixed
log-bin=mysql-bin
max_binlog_size=1000M
binlog-do-db=mydb
#binlog-ignore-db=mysql
#binlog-ignore-db=information_schema
#binlog-ignore-db=performance_schema
#binlog-ignore-db=sys
#root登錄master建立同步賬號(hào)
>mysql grant replication slave on *.* to 'replc'@'%' identified by '123456';
********* slave vi /etc/my.cnf
[mysqld]
server-id=200
binlog-format=mixed
log-bin=mysql-bin
max_binlog_size=1000M
binlog-do-db=mydb
#binlog-ignore-db=mysql
#binlog-ignore-db=information_schema
#binlog-ignore-db=performance_schema
#binlog-ignore-db=sys
#root 登錄slave
>mysql change master to master_host='192.168.1.100',master_user='replc',master_password='123456',master_connect_retry=100;
>mysql show slave status\G; #查看同步是否主要是查看Slave_IO_Running與Slave_SQL_Running選項(xiàng)。如果正常同步,這兩選必須同時(shí)為“YES”。
#如果啟動(dòng)slave時(shí)報(bào)錯(cuò) ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
>mysql reset slave; # 先reset(慎用!先記下slave當(dāng)前日志文件名和位置,如果reset后日志名和位置不對(duì),則直接用stop再change master)
>mysql start slave; # 之后可以使用start 啟動(dòng)了
#如果要重新同步,先在master上執(zhí)行>mysql flush logs; 然后 >mysql show master status; 得到File、Position,再到slave執(zhí)行以下語(yǔ)句:
>mysql stop slave;
>mysql change master to master_host='192.168.1.100',master_user='replc',master_password='123456',master_log_file="localhost-bin.000004",master_log_pos=659,master_connect_retry=100;
>mysql start slave;
# 完全重新同步辦法
----slave
>mysql stop slave;
----master
>mysql flush tables with read lock; #先鎖表 ?。?!
>mysql show master status\G;
mysql-bin.000021 | 47529419
# 使用大批量的導(dǎo)出方式,導(dǎo)入也隨之加速,如果數(shù)據(jù)大就帶參數(shù)gzip
/usr/local/mysql/bin/mysqldump -uroot -p --default-character-set=utf8 -e --max_allowed_packet=41943040 --net_buffer_length=41043040 mydb|gzip > /home/mysql/mydb20160606.sql.gz
----slave
scp root@192.168.1.100:/home/mysql/mydb20160606.sql.gz /home/mysql/mydb20160606.sql.gz
gzip -d -c /home/mysql/mydb20160606.sql.gz > /home/mysql/mydb20160606.sql
>mysql drop database mydb;
>mysql create database `mydb` character set utf8 collate utf8_general_ci;
mysql -uroot -p mydb</home/mysql/mydb20160606.sql
----master
>mysql unlock tables; #slave導(dǎo)入完成再unlock ?。?!
----slave
>mysql change master to master_host='192.168.1.100',master_user='replc',master_password='123456',master_log_file="mysql-bin.000021",master_log_pos=47529419,master_connect_retry=100;
>mysql start slave; #如果有“Slave failed to initialize relay log info structure from the repository”錯(cuò)誤先 reset slave再 change master ……
>mysql show slave status\G;
============================================== mongodb 主從同步(推薦轉(zhuǎn)用副本集模式)
# master 修改啟動(dòng)腳本
vi /etc/init.d/mongod
/usr/local/mongodb/bin/mongod --maxConns 20000 --config /usr/local/mongodb/mongodb.conf --master
# slave 修改啟動(dòng)腳本
vi /etc/init.d/mongod
/usr/local/mongodb/bin/mongod --maxConns 20000 --config /usr/local/mongodb/mongodb.conf --slave --source 192.168.1.100:27017
# 【注意】從節(jié)點(diǎn)slave是只讀,不能提供寫(xiě)操作的;如果寫(xiě)操作要切換到slave,slave必須先停止mongo進(jìn)程,再修改mongo啟動(dòng)腳本為master模式,最后重新啟動(dòng)mongo進(jìn)程;
# 增加slave只可在業(yè)務(wù)影響小的時(shí)候操作,否則slave首次同步時(shí)的鎖表會(huì)影響master的讀??;
# 【切記】重啟mongodb進(jìn)程后,必須重啟php-fpm、httpd、java等所有已連接客戶端的進(jìn)程,否則返回“Remote server has closed the connection”
============================================= apache2+ftp server(選裝)
#用戶和組
User apache
Group apache
#運(yùn)行
/usr/sbin/httpd
#配置
/etc/httpd/conf/httpd.conf
#網(wǎng)站根
/var/www/html
#systemctl服務(wù)
/usr/lib/systemd/system/httpd.service
systemctl enable httpd.service
#安裝vsftpd
yum -y install vsftpd
vi /etc/vsftpd/vsftpd.conf
local_root = /var/www/html
useradd myftp -s /sbin/nologin -d /var/www/html -g ftp
passwd myftp #設(shè)ftp密碼
chown -R myftp /var/www/html
chmod -R 777 /var/www/html
systemctl enable vsftpd.service
vi /etc/sysconfig/iptables # 80端口看實(shí)際情況設(shè)置
-A INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
vi /etc/sysconfig/iptables-config # 增加2項(xiàng)
IPTABLES_MODULES="ip_conntrack_ftp"
IPTABLES_MODULES="ip_nat_ftp"
systemctl restart iptables.service
============================================= 修改服務(wù)器ip、mysql賬戶,則修改對(duì)應(yīng)文件和sql
#如果mongodb綁定了ip,則更改
vi /usr/local/mongodb/mongodb.conf
#如果master的同步賬號(hào)也更換了,也要隨之更改以下sql語(yǔ)句中的同步賬號(hào):
先在master上執(zhí)行>mysql flush logs; 然后 >mysql show master status; 得到File、Position,再到slave上執(zhí)行以下語(yǔ)句:
>mysql stop slave;
>mysql change master to master_host='新的ip',master_user='replc',master_password='123456',master_log_file="localhost-bin.000004",master_log_pos=659,master_connect_retry=100;
>mysql start slave;
>mysql show slave status\G; #等待1分鐘左右再執(zhí)行此句
============================================= mysql binglog export
mysqlbinlog -u root -p --start-datetime='2016-10-27 10:00:14' --stop-datetime='2016-10-27 13:02:14' /home/mysql/data/mysql-bin.000001 > /home/mysql/20161027-1.binlog
============================================= 單獨(dú)恢復(fù)mysql某表
1.解壓備份文件,得到完整備份文件sql
2.shell執(zhí)行得到該表數(shù)據(jù)并保存到某個(gè)sql文件
grep 'INSERT INTO `tbl_001` VALUES' mydb20160606.sql > /home/mysql/dbbak/ex001.sql
3.mysql中清除數(shù)據(jù)
>mysql truncate table tbl_001;
# 如果遇到外鍵約束禁止truncate,當(dāng)前會(huì)話中執(zhí)行 set foreign_key_checks=0; 數(shù)據(jù)恢復(fù)完畢后記得當(dāng)前會(huì)話恢復(fù)約束 set foreign_key_checks=1;
4.mysql中導(dǎo)入數(shù)據(jù),完成數(shù)據(jù)恢復(fù)
>mysql source /home/mysql/dbbak/ex001.sql;
文章題目:CentOS7部署LNMP+Mongodb環(huán)境
文章地址:http://jinyejixie.com/article6/iissig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、建站公司、網(wǎng)站改版、品牌網(wǎng)站設(shè)計(jì)、Google、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)