Centos7.3环境部署

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修改如下:





    
    0  
    0  

        2
       
         
    
    
        
        0
        
        
        
        
        
        
        
        
        0
        
            
        1

        
        1m

        
        1k

        0

        
        384m


        
        true


    
    
    
    
    
    
        123456
        dry
        
        
        
    

    
        123456
        dry
        true
    



schema.xml配置文件修改如下:




      
      
      
      
      
      
      
      
      
      
      
          
          select user()
          
          
              
          
          
              
          
      

MYSQL宕机邮件警报

    # vi /etc/mail.rc
    # 发送邮件邮箱
    set [email protected]
    # 外部stmp服务器地址
    set smtp=smtp.126.com
    # 外部smtp服务器认证的用户名
    set smtp-auth-user=345684180
    # 外部smtp服务器认证的用户密码,注意是外部服务器的授权码并非邮箱登录密码
    set smtp-auth-password=123456
    # 邮件认证的方式
    set smtp-auth=login

安装rabbitmq

#安装依赖编程语言包
        yum install -y gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel autoconf

       https://www.rabbitmq.com/install-rpm.html


        vim /etc/yum.repos.d/rabbitmq_erlang.repo
  
        [bintray-rabbitmq-server]
        name=bintray-rabbitmq-rpm
        baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.8.x/el/7/
        gpgcheck=0
        repo_gpgcheck=0
        enabled=1
        
    yum -y install erlang

        vim /etc/yum.repos.d/rabbitmq.repo
        rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
        yum install rabbitmq-server-3.8.1-1.el7.noarch.rpm
        
        wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.1/rabbitmq-server-3.8.1-1.el7.noarch.rpm
        yum install rabbitmq-server-3.8.1-1.el7.noarch.rpm
#安装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." [email protected] < /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." [email protected]
     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!" [email protected]
 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." [email protected]
 fi

spring-boot打包成war启动

        
        
            org.springframework.boot
            spring-boot-starter-tomcat
            provided
        

    
        ${project.artifactId}
        
                        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                                  com.learn.order.OrderApplication
                
            
                        
            
                org.apache.maven.plugins
                maven-war-plugin
                
                    false
                
            
                        
            
                org.apache.maven.plugins
                maven-surefire-plugin
                
                    false
                
            
        
    

创建tomcat包启动war的目录结构


Centos7.3环境部署_第1张图片
1527520514341.jpg

web.xml文件配置




JDK1.9 spring-boot运行环境 jar依赖

        
            javax.xml.bind
            jaxb-api
        

发布项目:

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  #退出窗口

你可能感兴趣的:(Centos7.3环境部署)