In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The previous article explained in detail the CentOS installation LNMP+Mongodb production environment, and now details their deployment, most of which have been implemented during installation. Here are the main explanations and common maintenance:
= mysql
# user groups
Groupadd mysql
# user
Useradd-g mysql mysql-s / bin/false
# MySQL database storage directory
/ home/mysql/data
# MySQL running directory
/ usr/local/mysql
# configuration file
/ etc/my.cnf
# Service script
/ etc/rc.d/init.d/mysqld
# Communication file
/ var/lib/mysql/mysql.sock
# change the default password sql
Alter user 'root'@'localhost' identified by' sa'
# allow root to log in remotely and change the password to 'sa' 's sql
GRANT ALL PRIVILEGES ON *. * TO 'root'@'%' IDENTIFIED BY' sa' WITH GRANT OPTION
Flush privileges
# sql that forbids root remote login
Delete from mysql.user where host'localhost' and user='root'
Flush privileges
# read and write account
# master write
> mysql grant select,insert,update,delete,create,alter,index on mydb.* to 'web'@'%' identified by' 123456'
> mysql flush privileges
# slave read
> mysql grant select on mydb.* to 'web'@'%' identified by' 123456'
> mysql flush privileges
= nginx
# user groups
Groupadd www
# user
Useradd-g www www-s / bin/false
# run directory
/ usr/local/nginx
# Service script
/ etc/rc.d/init.d/nginx
# configuration file
/ usr/local/nginx/conf/nginx.conf
# website root directory
/ usr/local/nginx/html/
= php
# run directory
/ usr/local/php
# ini file with soft link
Ln-s / usr/local/php/etc/php.ini / etc/php.ini
# profile with soft links
Ln-s / usr/local/php/etc/php-fpm.conf / etc/php-fpm.conf
# Service script
/ etc/rc.d/init.d/php-fpm
# install php extensions, such as "xxx"; all such compiled so should be in / 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 # add extension= "xxx.so"
# memcache service running directory
/ usr/local/memcached
# memcache service script
/ etc/init.d/memcached
= MongoDB
# user groups
Groupadd mongodb
# user
Useradd-g mongodb mongodb-s / bin/false
# run directory
/ usr/local/mongodb
# data directory
Mkdir-p / home/mongodb/db
# Log directory
Mkdir-p / home/mongodb/log
# configuration file
/ usr/local/mongodb/mongodb.conf
# pid path
/ usr/local/mongodb/mongo.pid
# Service script
/ etc/rc.d/init.d/mongod
# [!! Pit! ] after restarting the mongodb process, you must restart all connected client processes such as php-fpm, httpd, java, etc., otherwise "Remote server has closed the connection" is returned.
# start MongoDB
Mongo # enter the MongoDB console
Show dbs # View default database
Use admin # switch to admin database
Exit # exit the MongoDB console
# create an index
> mongo db.table01.ensureIndex ({"myid": 1})
= sphinx
# run directory
/ usr/local/sphinx
# configuration file
/ usr/local/sphinx/etc/sphinx.conf
# Index file storage directory
/ home/sphinx
# Service script
/ etc/rc.d/init.d/sphinx
# start the process
/ usr/local/sphinx/bin/searchd-c / usr/local/sphinx/etc/sphinx.conf
# re-index
/ usr/local/sphinx/bin/indexer-config / usr/local/sphinx/etc/sphinx.conf-all-rotate
# stop indexing and process
/ usr/local/sphinx/bin/searchd-config / usr/local/sphinx/etc/sphinx.conf-stop
# if the sphinx file is too large, delete the corresponding directory file and rebuild the incremental index folder
Cd / home/sphinx/
Rm *-fr
Mkdir indexdelta
# if the sphinx service cannot be started or there is an error in starting, try renaming the mv / usr/local/sphinx/var/data/binlog.meta file, and then restart the 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 synchronization
# read and write account
Master write
Grant select,insert,update,delete,create,alter,index on sqtdb.* to 'web'@'%' identified by' 123456'
Flush privileges
Slave read
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 Log in to master to establish a synchronization account
> 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
# logging in to slave with root
> 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; # to check whether synchronization is mainly based on Slave_IO_Running and Slave_SQL_Running options. If synchronized normally, both selections must be "YES".
# if an error occurs when starting slave, ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
> mysql reset slave; # reset first (use with caution! First write down the current log file name and location of slave. If the log name and location are not correct after reset, then use stop and then change master)
After mysql start slave; #, you can start using start
# if you want to resynchronize, execute > mysql flush logs; and then > mysql show master status; on master to get File and Position, and then execute the following statement in slave:
> 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
# full resynchronization method
-slave
> mysql stop slave
-master
> mysql flush tables with read lock; # Lock the table first!
> mysql show master status\ G
Mysql-bin.000021 | 47529419
# using the method of mass export, the import is accelerated. If the data is large, the parameter gzip is used.
/ 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 mydbmysql unlock tables; # slave import is completed and then 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; # if there is a "Slave failed to initialize relay log info structure from the repository" error, first reset slave and then change master.
> mysql show slave status\ G
= mongodb master-slave synchronization (it is recommended to switch to replica set mode)
# master modify startup script
Vi / etc/init.d/mongod
/ usr/local/mongodb/bin/mongod-maxConns 20000-config / usr/local/mongodb/mongodb.conf-master
# slave modify startup script
Vi / etc/init.d/mongod
/ usr/local/mongodb/bin/mongod-- maxConns 20000-- config / usr/local/mongodb/mongodb.conf-- slave-- source 192.168.1.100 config 27017
# [Note] Slave node slave is read-only and cannot provide write operation. If you want to switch to slave,slave, you must first stop the mongo process, then change the mongo startup script to master mode, and finally restart the mongo process.
# adding slave can only be operated when the business impact is small, otherwise the locking table when slave synchronizes for the first time will affect the reading of master
# [remember] after restarting the mongodb process, you must restart all connected client processes such as php-fpm, httpd, java, etc., otherwise "Remote server has closed the connection" is returned.
= apache2+ftp server (optional)
# users and groups
User apache
Group apache
# run
/ usr/sbin/httpd
# configuration
/ etc/httpd/conf/httpd.conf
# website Root
/ var/www/html
# systemctl Service
/ usr/lib/systemd/system/httpd.service
Systemctl enable httpd.service
# install 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 # set ftp password
Chown-R myftp / var/www/html
Chmod-R 777 / var/www/html
Systemctl enable vsftpd.service
Vi / etc/sysconfig/iptables # 80 port is set according to the actual situation
-An INPUT-m state-- state NEW-p tcp-- dport 21-j ACCEPT
-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 80-j ACCEPT
Vi / etc/sysconfig/iptables-config # adds 2 items
IPTABLES_MODULES= "ip_conntrack_ftp"
IPTABLES_MODULES= "ip_nat_ftp"
Systemctl restart iptables.service
= modify the server ip and mysql accounts, then modify the corresponding files and sql
# if mongodb is bound to ip, change
Vi / usr/local/mongodb/mongodb.conf
# if the synchronization account of master is also changed, change the synchronization account in the following sql statement:
First execute > mysql flush logs; on master, then > mysql show master status; to get File and Position, and then execute the following statement on slave:
> mysql stop slave
Mysql change master to master_host=' 's new 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; # wait about 1 minute before executing this sentence
= mysql binglog export
Mysqlbinlog-u root-p-- start-datetime='2016-10-27 10 stop-datetime='2016-10-27 00 mysqlbinlog 14'--stop-datetime='2016-10-27 13 13 14'/ home/mysql/data/mysql-bin.000001 > / home/mysql/20161027-1.binlog
= restore a mysql table separately
1. Extract the backup file to get the full backup file sql
2.shell executes to get the table data and save it to a sql file
Grep 'INSERT INTO `tbl_ 001` VALUES' mydb20160606.sql > / home/mysql/dbbak/ex001.sql
Clear data in 3.mysql
> mysql truncate table tbl_001
# if a foreign key constraint forbids truncate, remember the current session recovery constraint set foreign_key_checks=1 after performing set foreign_key_checks=0; data recovery in the current session
Import data in 4.mysql to complete data recovery
> mysql source / home/mysql/dbbak/ex001.sql
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.