文章目录
1. goaccess 日志可视化
它是一款可视化web日志监控工具,它能够为需要动态可视服务器报告的系统管理员提供快速且有价值的 HTTP 统计信息,主要优点:快速、实时、具有美观的页面,几乎支持所有的web日志格式
## 软件安装:
[root@server11 ~]# tar -xzvf goaccess-1.4.tar.gz
[root@server11 ~]# yum install -y GeoIP-devel-1.5.0-13.el7.x86_64.rpm
[root@server11 ~]# cd goaccess-1.4/
[root@server11 goaccess-1.4]# ./configure --enable-utf8 --enable-geoip=legacy
[root@server11 goaccess-1.4]# make
[root@server11 goaccess-1.4]# make install
'/usr/local/etc/goaccess'
[root@server11 logs]# goaccess access.log -o /usr/local/nginx/html/report.html --log-format=COMBINED --real-time-html ##生成可视化界面文件report.html
[root@server11 conf]# vim nginx.conf
#rewrite ^(.*) http://www.westos.org permanent; ##重定向注释
[root@server11 conf]# nginx -s reload
[root@foundation file_recv]# ab -c1 -n100 http://192.168.0.11/index.html
可以访问到可视化页面,且当有新的日志生成时网页自动实时更新,无需手动刷新
2. tomcat结合memcache
2.1 配置tomcat,与nginx结合
tomcat介绍链接:https://baike.baidu.com/item/tomcat/255751?fr=aladdin.
nginx中结合tomcat之后,访问流程:
client -> nginx:80 ->*.jsp ->tomcat:8080
nginx适合高并发,tomcat属于应用服务器,对资源的消耗比较大,因此并不适合高并发场景,一般需要多台服务器来缓解其压力,然后再用nginx做负载较均衡即可
用户访问资源,然后到nginx服务器的80端口,如果访问的是以.jsp为后缀的文件时交给tomcat:8080处理
##在server12,13上做同样操作
[root@server12 ~]# tar zxf apache-tomcat-7.0.37.tar.gz
[root@server12 ~]# ls ##下载所需资源
apache-tomcat-7.0.37 apache-tomcat-7.0.37.tar.gz jdk-8u121-linux-x64.rpm
[root@server12 ~]# rpm -ivh jdk-8u121-linux-x64.rpm
[root@server12 ~]# mv apache-tomcat-7.0.37 /usr/local/tomcat
[root@server12 ~]# cd /usr/local/tomcat
[root@server12 tomcat]# ls
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[root@server12 tomcat]# bin/startup.sh ##启动tomcat
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@server12 tomcat]# netstat -antlp ##端口开启
tcp6 0 0 :::8009 :::* LISTEN 4224/java
tcp6 0 0 :::8080 :::* LISTEN 4224/java
访问8080端口能够访问到tomcat首页
2.2 nginx配置tomcat负载均衡
[root@server11 conf]# vim nginx.conf ##编辑nginx配置文件
upstream tomcat{
sticky;
server 192.168.0.12:8080;
server 192.168.0.13:8080;
}
location ~ \.jsp$ {
proxy_pass http://tomcat;
}
[root@server11 conf]# nginx -s reload
[root@foundation file_recv]# scp test.jsp root@192.168.0.12:/usr/local/tomcat/webapps/ROOT/
[root@foundation file_recv]# scp test.jsp root@192.168.0.13:/usr/local/tomcat/webapps/ROOT/
sticky算法:保证在同一个客户端访问动态资源时不做负载均衡,不调度到其它后端,用户信息得以保存。
[root@server12 logs]# cat catalina.out
[root@server12 tomcat]# bin/shutdown.sh ##当server2挂掉时,会接管到server3,但数据丢失
2.3 交叉存储
## 在server12,server13上做同样操作
[root@server12 ~]# unzip jar.zip ##所需jar包
[root@server12 ~]# cd jar/
[root@server12 jar]# mv * /usr/local/tomcat/lib/
[root@server12 tomcat]# netstat -antlp
[root@server12 tomcat]# bin/shutdown.sh
[root@server12 conf]# vim context.xml
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.0.12:11211,n2:192.168.0.13:11211"
failoverNodes="n1"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
[root@server13 ~]# cd /usr/local/tomcat/
[root@server13 tomcat]# bin/shutdown.sh
[root@server13 conf]# vim context.xml
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.0.12:11211,n2:192.168.0.13:11211"
failoverNodes="n2"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
[root@server12 conf]# yum install memcached -y
[root@server12 conf]# systemctl enable --now memcached
[root@server12 conf]# netstat -antlp
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 7637/memcached
[root@server12 conf]# cd ..
[root@server12 tomcat]# bin/startup.sh
[root@server12 tomcat]# cd logs/
[root@server12 logs]# cat catalina.out
[root@server13 tomcat]# bin/shutdown.sh
server13 shutdown.sh 后,以前调度在server13上提交的信息还在。
[root@server12 conf]# systemctl stop memcached
同样,如果server13 tomcat开启,server12上的memcache关掉,调度节点不会转移为server13,之前在server12后端提交的信息也不会丢失
3. mysql基础主从复制
3.1 master端
master端:已经安装了mysql
[root@server11 data]# scp -r mysql/ root@192.168.0.12:/usr/local ##复制mysql二进制程序到另外一台主机中用于设置mysql从属
[root@server11 data]# cd ..
[root@server11 mysql]# cd /etc/
[root@server11 etc]# scp my.cnf server12:/etc/
[root@server11 etc]# scp /etc/init.d/mysqld server12:/etc/init.d/
[root@server11 etc]# /etc/init.d/mysqld start
Starting MySQL SUCCESS!
[root@server11 etc]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock
symbolic-links=0
server-id=1 ##数据同步
log-bin=mysql-bin
[root@server11 etc]# /etc/init.d/mysqld restart ##重启使之生效
[root@server11 data]# mysql -pwestos
mysql> grant REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'westos';
mysql> show master status;
为replication创建一个用户:
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'westos'; %mysql7版本可以通过一个语句完成,mysql8中必须需要如下所示两个语句:
mysql> CREATE USER 'repl'@'%.example.com' IDENTIFIED BY 'password';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.example.com';
mysql-bin.000001会记录对数据库的所有变更,mysql-bin.index是数据库二进制索引文件,它记录了数据库所有的二进制日志:
3.2 slave端
[root@server12 ~]# cd /usr/local/
[root@server12 local]# du -sh mysql/
2.0G mysql/
[root@server12 ~]# vim .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin ##添加环境变量
[root@server12 ~]# source .bash_profile
[root@server12 ~]# cd /usr/local/mysql/data/
[root@server12 data]# rm -fr * ##删除原来的mysql配置
[root@server12 ~]# useradd -M -d /usr/local/mysql/data/ -s /sbin/nologin mysql ##添加mysql用户
[root@server12 ~]# mysqld --initialize --user=mysql ##mysql初始化
[root@server12 data]# /etc/init.d/mysqld start ##启动数据库
[root@server12 data]# mysql_secure_installation ##安全安装
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No:
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
[root@server12 data]# mysql -pwestos
[root@server12 data]# vim /etc/my.cnf
[root@server12 data]# cat /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock
symbolic-links=0
server-id=2
[root@server12 data]# /etc/init.d/mysqld restart ##重启使之生效
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@server12 data]# mysql -pwestos
mysql> CHANGE MASTER TO MASTER_HOST='192.168.0.11',MASTER_USER='repl',MASTER_PASSWORD='westos',MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=437; ##备份数据库
mysql> start slave; ##启动slave
mysql> show slave status\G;
IO线程:负责复制replication的日志
SQL线程:负责重做
3.3 测试
在server11上创建数据库westos,server12数据库会同步更新。