centos 查看所有运行中的服务的详细信息命令:
netstat -tunpl
#中文显示
LANG="zh_CN.UTF-8"
清理内存:
free -m
sync; echo 3 > /proc/sys/vm/drop_caches
更新源
yum update
#搜索
yum search ~
安装JAVA
yum -y install java
yum -y install maven
切换java版本
alternatives --config java
安装常用程序
yum -y install lrzsz
yum -y install git
yum -y install vim
yum -y install erlang
yum -y install nginx
安装Docker
yum install epel-release -y
yum install docker-io
#Docker使用
service docker start
#删除docker 容器
sudo docker ps -a
#获取最后字段的NAME
sudo docker rm NAME
#删除退出状态的容器
docker rm $(docker container ls -f "status=exited" -q)
#删除所有状态的容器
docker rm $(docker ps -aq)
安装MYSQL
mkdir ~/usr/local
# 下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
#检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
安装#
yum install mysql-community-server
#启动MySQL服务
systemctl start mysqld
#查看MySQL的启动状态
systemctl status mysqld
#开机启动
systemctl enable mysqld
systemctl daemon-reload
#修改密码策略
在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略
#选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
#不需要密码策略
validate_password = off
#修改字符编码
character_set_server=utf8
init_connect='SET NAMES utf8'
log-bin=mysql-bin
server-id=master_1 或者 server-id=slave_1
lower_case_table_names=1
#重启服务mysql
systemctl restart mysqld
#获取root密码
grep 'temporary password' /var/log/mysqld.log
#登录修改root密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'tang0624'; || set password for 'root'@'localhost'=password('MyNewPass4!');
#添加新用户
GRANT ALL PRIVILEGES ON *.* TO 'cheer'@'%' IDENTIFIED BY 'cheerrrr' WITH GRANT OPTION;
#创建数据库
create database dry;
#开启远程端口服务提供给外部
firewall-cmd --zone=public --add-port=3306/tcp --permanent
MYSQL主从读写分离
#主机
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'45.32.26.26' IDENTIFIED BY 'tang0624';(指定从机ip)
##或者
GRANT REPLICATION SLAVE ON *.* to 'user'@'%' identified by 'mysql';(所有ip)
#主机查询授权用户
select * from information_schema.user_privileges;
show master status;
#记录 File 的值和 Position 的值。
#从机
change master to
master_host='45.32.26.26',
master_user='slave',
master_log_file='mysql-bin.000008',
master_log_pos=8911,
master_port=3306,
master_password='tang0624';
show slave status\G
start slave; 修改配置 stop slave;
http://www.cnblogs.com/hanyucq/p/5524921.html
MYCAT使用(要进行自动读写分离(读写数据连接自动切换) 客户端请连接MYCAT 端口默认8066 用户密码在scheme文件配置 数据库请使用mycat逻辑数据库) 修改如下2个配置文件 server.xml修改如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License. - You
may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
- - Unless required by applicable law or agreed to in writing, software -
distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
License for the specific language governing permissions and - limitations
under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
<system>
<property name="useSqlStat">0</property> <!-- 1为开启实时统计、0为关闭 -->
<property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 -->
<property name="sequnceHandlerType">2</property>
<!-- <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
<!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
<!-- <property name="processorBufferChunk">40960</property> -->
<!--
<property name="processors">1</property>
<property name="processorExecutor">32</property>
-->
<!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena-->
<property name="processorBufferPoolType">0</property>
<!--默认是65535 64K 用于sql解析时最大文本长度 -->
<!--<property name="maxStringLiteralLength">65535</property>-->
<!--<property name="sequnceHandlerType">0</property>-->
<!--<property name="backSocketNoDelay">1</property>-->
<!--<property name="frontSocketNoDelay">1</property>-->
<!--<property name="processorExecutor">16</property>-->
<!--
<property name="serverPort">8066</property> <property name="managerPort">9066</property>
<property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property>
<property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
<!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
<property name="handleDistributedTransactions">0</property>
<!--
off heap for merge/order/group/limit 1开启 0关闭
-->
<property name="useOffHeapForMerge">1</property>
<!--
单位为m
-->
<property name="memoryPageSize">1m</property>
<!--
单位为k
-->
<property name="spillsFileBufferSize">1k</property>
<property name="useStreamOutput">0</property>
<!--
单位为m
-->
<property name="systemReserveMemorySize">384m</property>
<!--是否采用zookeeper协调切换 -->
<property name="useZKSwitch">true</property>
</system>
<!-- 全局SQL防火墙设置 -->
<!--
<firewall>
<whitehost>
<host host="127.0.0.1" user="mycat"/>
<host host="127.0.0.2" user="mycat"/>
</whitehost>
<blacklist check="false">
</blacklist>
</firewall>
-->
<user name="account">
<property name="password">123456</property>
<property name="schemas">dry</property>
<!-- 表级 DML 权限设置 -->
<!--
<privileges check="false">
<schema name="TESTDB" dml="0110" >
<table name="tb01" dml="0000"></table>
<table name="tb02" dml="1111"></table>
</schema>
</privileges>
-->
</user>
<user name="readAccount">
<property name="password">123456</property>
<property name="schemas">dry</property>
<property name="readOnly">true</property>
</user>
</mycat:server>
schema.xml配置文件修改如下:
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<!-- 定义一个MyCat的模式,逻辑数据库名称TestDB -->
<!-- “checkSQLschema”:描述的是当前的连接是否需要检测数据库的模式 -->
<!-- “sqlMaxLimit”:表示返回的最大的数据量的行数 -->
<!-- “dataNode="dn1"”:该操作使用的数据节点是dn1的逻辑名称 -->
<schema name="dry" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1" />
<!-- 定义个数据的操作节点,以后这个节点会进行一些库表分离使用 -->
<!-- “dataHost="localhost1"”:定义数据节点的逻辑名称 -->
<!-- “database="test"”:定义数据节点要使用的数据库名称 -->
<dataNode name="dn1" dataHost="localhost1" database="dry" />
<!-- 定义数据节点,包括了各种逻辑项的配置 -->
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="3" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<!-- 配置真实MySQL与MyCat的心跳 -->
<heartbeat>select user()</heartbeat>
<!-- 配置真实的MySQL的连接路径 -->
<writeHost host="hostMaster" url="45.32.26.26:3306" user="cheer" password="cheerrrr">
<readHost host="hostSlave" url="45.76.105.238:3306" user="cheer" password="cheerrrr"/>
</writeHost>
<writeHost host="hostMaster2" url="45.76.105.238:3306" user="cheer" password="cheerrrr">
<readHost host="hostSlave2" url="45.76.105.238:3306" user="cheer" password="cheerrrr"/>
</writeHost>
</dataHost>
</mycat:schema>
MYSQL宕机邮件警报
# vi /etc/mail.rc
# 发送邮件邮箱
set from=345684180@qq.com
# 外部stmp服务器地址
set smtp=smtp.126.com
# 外部smtp服务器认证的用户名
set smtp-auth-user=345684180
# 外部smtp服务器认证的用户密码,注意是外部服务器的授权码并非邮箱登录密码
set smtp-auth-password=123456
# 邮件认证的方式
set smtp-auth=login
安装rabbitmq
#安装依赖编程语言包
yum -y install erlang
#安装rabbitmq服务端
yum -y install rabbitmq-server
#启动服务
sudo service rabbitmq-server start
#查看启动状态
sudo service rabbitmq-server status
#开启UI监控
rabbitmq-plugins enable rabbitmq_management
firewall-cmd --zone=public --add-port=15672/tcp --permanent
firewall-cmd --reload
#开启远程客户端连接端口
firewall-cmd --zone=public --add-port=5672/tcp --permanent
firewall-cmd --reload
#创建client用户
添加用户:rabbitmqctl add_user admin 123456
添加权限:rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
修改用户角色:rabbitmqctl set_user_tags admin administrator
#重启服务 访问
sudo service rabbitmq-server restart
浏览器登录 127.0.0.1:15672
#开机启动
systemctl enable rabbitmq-server
systemctl daemon-reload
安装Jenkins
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins
#修改端口7711
vim /etc/sysconfig/jenkins
firewall-cmd --zone=public --add-port=7711/tcp --permanent
firewall-cmd --reload
#启动Jenkins
chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins
service jenkins restart
ps -ef | grep jenkins
#开机启动
sudo chkconfig jenkins on
安装redis
yum install epel-release
yum install redis
#启动服务 开机启动
service redis start
chkconfig redis on
#开放网络访问
vim /etc/redis.conf 注释掉bind 127.0.0.1
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload
开启一个端口
#添加
firewall-cmd --zone=public --add-port=8066/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
#重新载入
firewall-cmd --reload
#查看
firewall-cmd --zone=public --query-port=8081/tcp
#删除
firewall-cmd --zone=public --remove-port=80/tcp --permanent
MYSQL数据监测 主从状态监控
#check MySQL Slave's Runnning Status
#Crontab time 00:10
MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $4}'`
MYSQLIP=`ifconfig eth0|grep "inet" | awk ' {print $2}'`
STATUS=$(/usr/bin/mysql -uroot -ptang0624 -S /var/lib/mysql/mysql.sock -e "show slave status\G" | grep -i "running")
DELAYED=$(/usr/bin/mysql -uroot -ptang0624 -S /var/lib/mysql/mysql.sock -e "show slave status\G" | grep -i "Seconds_Behind_Master")
#echo "$STATUS"
IO_env=`echo $STATUS | grep IO | awk ' {print $2}'`
echo "============================="
echo "$STATUS"
echo "$DELAYED"
SQL_env=`echo $STATUS | grep SQL | awk ' {print $4}'`
DELAYED_env=`echo $DELAYED | awk ' {print $2}'`
DATA=`date +"%y-%m-%d %H:%M:%S"`
function checkMysqlStatus(){
if [ "$MYSQLPORT" == "3306" ]
then
/usr/bin/mysql -uroot -ptang0624 --connect_timeout=5 -e "show databases;" &>/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Server: $MYSQLIP mysql is down, please try to restart mysql by manual!" > ~/usr/mysql.err
#mail -s "WARN! server: $MYSQLIP mysql is down." WENTAO_Wanna@126.com < /data/mysql/mysql.err
else
echo "mysql is running..."
fi
else
echo "发送邮件...WARN!Server: $MYSQLIP mysql is down."
#mail -s "WARN!Server: $MYSQLIP mysql is down." WENTAO_Wanna@126.com
fi
}
echo "================================="
echo "$IO_env"
echo "$SQL_env"
echo "$DELAYED_env"
echo "================================="
checkMysqlStatus
# 延时大于60s
if [ "$DELAYED_env" -ge 60 ]
then
echo "MySQL Slave is delayed $DELAYED_env s!"
echo "####### $DATA #########">> /usr/mysql_slave_status.log
echo "MySQL Slave is delayed $DELAYED_env s!" >> /usr/mysql_slave_status.log
#echo "MySQL Slave is delayed $DELAYED_env s!" | mail -s "WARN! $MYSQLIP MySQL Slave is delayed $DELAYED_env s!" WENTAO_Wanna@126.com
fi
if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ]
then
echo "MySQL Slave is running!"
else
echo "####### $DATA #########">> /usr/mysql_slave_status.log
echo "MySQL Slave is not running!" >> /usr/mysql_slave_status.log
#echo "MySQL Slave is not running!" | mail -s "WARN! $MYSQLIP MySQL Slave is not running." WENTAO_Wanna@126.com
fi
spring-boot打包成war启动
<!-- 使用外部tomcat容器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- spring-boot打包插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.learn.order.OrderApplication</mainClass>
</configuration>
</plugin>
<!-- 打包war插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!--打包,编译,安装阶段 是否跳过测试-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
</plugins>
</build>
创建tomcat包启动war的目录结构
1527520514341.jpg
web.xml文件配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" metadata-complete="true">
</web-app>
JDK1.9 spring-boot运行环境 jar依赖
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
发布项目:
java -Dspring.profiles.active=test -jar xxxx.jar
nohup java -jar -Xms128m -Xmx256m -Dspring.profiles.active=8761 eureka-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &
nohup java -jar eureka-0.0.1-SNAPSHOT.jar --spring.profile.active=8761 >/dev/null 2>&1 &
mvn spring-boot:run
java -jar xxx.jar
java -jar xxx.war
java -jar -Dspring.profiles.active=test -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=端口 xxx.jar #开启调试模式(用于测试环境)
端口开启:
iptables -nvL --line-number #查看INPUT 序号和端口
iptables -I INPUT 序号 -p tcp --dport 80 -j ACCEPT -m comment --comment "80 logs" #开启端口
firewall-cmd --permanent --zone=public --add-port=3306/tcp #开启端口
firewall-cmd --reload #重新加载,开始生效
多窗口操作:
yum -y instatll screen
命令:
screen -ls #查看所有窗口
screen -S 窗口名 #新建窗口
screen -r 窗口名 #切换到指定窗口
Ctrl+A+D #退出窗口
网友评论