腾讯微服务框架Tars配置全解


环境:

[root@izj6cilg0dtunfc49dqpxgz ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@izj6cilg0dtunfc49dqpxgz ~]# uname -a
Linux izj6cilg0dtunfc49dqpxgz 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
tars版本:
https://github.com/TarsCloud/Tars/releases/tag/v1.5.0


安装包准备:


1,依赖


yum install mpfr gmp -y  *mpc* glibc-static libstdc++-static    gcc gcc-c++ autoconf automake libtool curl make g++ unzip zlib zlib-devel  glibc-devel   cmake   perl  git  ncurses-devel 
2,安装jdk


cd /mnt
 mkdir -pv /usr/java
tar xf jdk-8u181-linux-x64.tar.gz -C /usr/java
cat >> /etc/profile << EOF
export JAVA_HOME=/usr/java/jdk1.8.0_181
export JRE_HOME=\${JAVA_HOME}/jre
export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib
export PATH=\${JAVA_HOME}/bin:\$PATH
EOF


source /etc/profile
echo $JAVA_HOME
3,安装mysql-5.7
MySql二进制包安装


这里推荐mysql5.6或者5.7版本的二进制包安装方式。
本次采用5.7版本安装,MySQL5.6安装方式查看历史MySQL安装篇幅。
经测试,在安装8.0版本的MySQL,在后续无法成功编译TarsFramework。


 切换工作路径至/usr/local/src
[root@node100 ~]# cd /usr/local/src/


 下载MySQL
[root@node100 src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar


 解压 MySQL 5.7 二进制包
  [root@node100 src]# tar xf mysql-5.7.25-linux-glibc2.12-x86_64.tar


  [root@node100 src]# tar xf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz


 移动 解压好的MySQL 5.7目录至/usr/local
[root@node100 src]# mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local


 创建MySQL软连接
[root@node100 src]# ln -s /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql


 创建 mysql 应用运行用户
[root@node100 src]# useradd -r -s /sbin/nologin mysql


创建 MySQL 数据存放目录
  [root@node100 src]# mkdir -vp /data/mysql_data


  mkdir: created directory `/data'


  mkdir: created directory `/data/mysql_data'


 在 MySQL 二进制包目录中创建 mysql-files 目录 [MySQL 数据导入/导出数据专放目录]
  [root@node100 src]# mkdir -v /usr/local/mysql/mysql-files


 mkdir: created directory `/usr/local/mysql/mysql-files'


 修改 MySQL 二进制包目录的所属用户与所属组
[root@node100 src]# chown root.mysql -R /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64


  修改 MySQL 数据目录与 数据导入/导出专放目录的所属用户与所属组
[root@node100 src]# chown mysql.mysql /usr/local/mysql/mysql-files /data/mysql_data


 重命名不使用系统自带 MySQL 配置文件 /etc/my.cnf [ debian类系统在 /etc/mysql/my.cnf ]
[root@node100 src]# mv /etc/my.cnf{,.old}


 初始化
  [root@node100 src]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data


 2020-02-05T13:56:34.415131Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).


  2020-02-05T13:56:35.563289Z 0 [Warning] InnoDB: New log files created, LSN=45790


 2020-02-05T13:56:35.835511Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.


 2020-02-05T13:56:35.915147Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 853b8efd-27bb-11e9-9c8d-52540009b76e.


2020-02-05T13:56:35.925540Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.


2020-02-05T13:56:35.926081Z 1 [Note] A temporary password is generated for root@localhost: wKoMdt7<yNor


 开启 SSL 连接[可选]


[root@node100 src]# /usr/local/mysql/bin/mysql_ssl_rsa_setup -d /data/mysql_data


 修改SSL证书文件所属用户和用户组


[root@node100 src]# chown mysql.mysql -R /data/mysql_data


 创建mysql systemctl启动脚本 


[root@node100 src]# cat /usr/lib/systemd/system/mysqld.service



# Simple MySQL systemd service file 

# systemd supports lots of fancy features, look here (and linked docs) for a full list:  
#   http://www.freedesktop.org/software/systemd/man/systemd.exec.html 

# Note: this file ( /usr/lib/systemd/system/mysql.service ) 
# will be overwritten on package upgrade, please copy the file to  

#  /etc/systemd/system/mysql.service  
#   
# to make needed changes. 
#  
# systemd-delta can be used to check differences between the two mysql.service files. 



[Unit] 
Description=MySQL Community Server 
After=network.target 
After=syslog.target 


[Install] 
WantedBy=multi-user.target 
Alias=mysql.service 


[Service] 
User=mysql 
Group=mysql 


# Execute pre and post scripts as root 
PermissionsStartOnly=true 


# Needed to create system tables etc. 
#ExecStartPre=/usr/bin/mysql-systemd-start pre 


# Start main service 
ExecStart=/usr/local/mysql/bin/mysqld_safe 


# Don't signal startup success before a ping works 
#ExecStartPost=/usr/bin/mysql-systemd-start post 


# Give up if ping don't get an answer 
TimeoutSec=600 


Restart=always 
PrivateTmp=false


systemd加载启动配置文件
[root@node100 src]#  systemctl daemon-reload


创建MySQL配置文件my.cnf, 指定数据目录
 [root@node100 src]# cat /etc/my.cnf


 [mysqld]


user = mysql


bind_address = 0.0.0.0


character_set_server=utf8mb4


skip_name_resolve = 1


max_connections = 800


max_connect_errors = 1000


datadir = /data/mysql_data
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
general_log=on
general_log_file=/data/mysql_data/iZrj91xlsyfkpdqr309s22Z.log


启动MySQL服务
[root@node100 src]# systemctl start mysqld


 添加MySQL bin目录至path变量,并生效环境变量


[root@node100 src]# cat /etc/profile.d/mysql.sh


export MYSQL_HOME=/usr/local/mysql


export PATH=$MYSQL_HOME/bin:$PATH




[root@node100 src]# source /etc/profile


* 通过mysql命令连接mysql服务,并修改默认密码(本次修改为123456.), 默认密码为初始化时的随机密码


[root@node100 src]# mysql -uroot -p'wKoMdt7<yNor'
 mysql> alter user 'root'@'localhost' identified by '123456.'
 Query OK, 0 rows affected (0.00 sec) 


4,安装resin


cd /usr/local/
wget http://www.caucho.com/download/resin-4.0.49.tar.gz
tar xf resin-4.0.49.tar.gz
ln -s /usr/local/resin-4.0.49 /usr/local/resin
5,安装maven


cd /mnt
tar fx apache-maven-3.5.4-bin.tar.gz
mv apache-maven-3.5.4 /usr/local/maven
cp /etc/profile /etc/profile.bak
echo "export MVEN_HOME=/usr/local/maven" >>/etc/profile
echo "export PATH=$MVEN_HOME/bin:$PATH" >>/etc/profile
source /etc/profile
ln -s /usr/local/maven/bin/mvn /usr/bin/mvn
mvn -version
6,安装web管理系统开发环境nvm


cd /root/
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
source ~/.bashrc
nvm install v8.11.3
npm install -g pm2 --registry=https://registry.npm.taobao.org
7,安装bison组件和flex组件


yum -y install bison flex
10,安装Java语言工具包


cd /mnt
tar fx thirdparty.tgz
cd  thirdparty/tars-1.5.0/;ls
----->
build  docs           Install_faq.en.md  Install.md          Introduction.md  LICENSE.TXT  php      README.en.md  tup
cpp    Install.en.md  Install_faq.md     Introduction.en.md  java             nodejs       plugins  README.md     web


cd java
mvn clean install
mvn clean install -f core/client.pom.xml
mvn clean install -f core/server.pom.xml
8、安装c++环境


yum -y install dos2unix flex bison


cd /mnt/thirdparty/tars-1.5.0/cpp/thirdparty
git clone https://github.com/Tencent/rapidjson.git


cd /mnt/thirdparty/tars-1.5.0/cpp/build/
./build.sh all     
mkdir /usr/local/tars
make install
9、tars数据库环境初始化


mysql -uroot -proot@appinside -e "grant all on *.* to 'tars'@'%' identified by 'tars2015' with grant option;"
mysql -uroot -proot@appinside -e "grant all on *.* to 'tars'@'localhost' identified by 'tars2015' with grant option;"
mysql -uroot -proot@appinside -e "grant all on *.* to 'tars'@'${MachineName}' identified by 'tars2015' with grant option;"
mysql -uroot -proot@appinside -e "flush privileges;"
cd /mnt/thirtparty/tars-1.5.0/cpp/framework/sql
sed -i "s/192.168.2.131/172.31.38.11/g" `grep 192.168.2.131 -rl ./*`
sed -i "s/db.tars.com/172.31.38.11/g" `grep db.tars.com -rl ./*`
chmod u+x exec-sql.sh
./exec-sql.sh
10、打包框架基础服务


cd /mnt/thirdparty/tars-1.5.0/cpp/build/
make framework-tar


make tarsstat-tar
make tarsnotify-tar
make tarsproperty-tar
make tarslog-tar
make tarsquerystat-tar
make tarsqueryproperty-tar
11、安装核心基础服务


mkdir -p /usr/local/app/tars/
cd /mnt/thirtyparty/tars-1.5.0/cpp/build


cp framework.tgz /usr/local/app/tars/
cd /usr/local/app/tars
tar xf framework.tgz


sed -i "s/192.168.2.131/172.31.38.11/g" `grep 192.168.2.131 -rl ./*`
sed -i "s/db.tars.com/172.31.38.11/g" `grep db.tars.com -rl ./*`
sed -i "s/registry.tars.com/172.31.38.11/g" `grep registry.tars.com -rl ./*`
sed -i "s/web.tars.com/172.31.38.11/g" `grep web.tars.com -rl ./*`


chmod u+x tars_install.sh
./tars_install.sh
./tarspatch/util/init.sh
12、安装web管理系统


cd /mnt/thirtparty/tars-1.5.0/web/
sed -i "s/db.tars.com/172.31.38.11/g" `grep db.tars.com -rl ./src/main/resources/*`
sed -i "s/registry1.tars.com/172.31.38.11/g" `grep registry1.tars.com -rl ./src/main/resources/*`
sed -i "s/registry2.tars.com/172.31.38.11/g" `grep registry2.tars.com -rl ./src/main/resources/*`


mvn clean package
cp ./target/tars.war /usr/local/resin/webapps/
#./web/target/tars/WEB-INF/classes/log4j.properties  这里可以修改日志目录
mkdir -p /data/log/tars/
mv /usr/local/resin/conf/resin.xml /usr/local/resin/conf/resin.xml.backup
cat > /usr/local/resin/conf/resin.xml << EOF
<!--
   - Resin 4.0 configuration file.
  -->
<resin xmlns="http://caucho.com/ns/resin"
       xmlns:resin="urn:java:com.caucho.resin">


  <!-- property-based Resin configuration -->
  <resin:properties path="\${__DIR__}/resin.properties" optional="true"/>


  <resin:if test="\${properties_import_url}">
     <resin:properties path="\${properties_import_url}"
                    optional="true" recover="true"/>
  </resin:if>




  <!-- Logging configuration for the JDK logging API -->
  <log-handler name="" level="all" path="stdout:"
               timestamp="[%y-%m-%d %H:%M:%S.%s]"
               format=" {\${thread}} \${log.message}"/>
               
  <!--
     - Alternative pseudo-TTCC log format
     -
     - <log-handler name="" level="all" path="stdout:"
     -           timestamp="%y-%m-%d %H:%M:%S.%s"
     -           format=" [\${thread}] \${log.level} \${log.shortName} - \${log.message}"/>
    -->
   
  <!--
     - level='info' for production
     - 'fine' or 'finer' for development and troubleshooting
    -->
  <logger name="" level="\${log_level?:'info'}"/>


  <logger name="com.caucho.java" level="config"/>
  <logger name="com.caucho.loader" level="config"/>


  <!--
     - Default configuration applied to all clusters, including
     - HTTP, HTTPS, and /resin-admin configuration.
    -->
  <resin:import path="\${__DIR__}/cluster-default.xml"/>
 
  <!--
     - health configuration
    -->
  <resin:import path="\${__DIR__}/health.xml"/>


 
  <!--
     - Remote management requires at least one enabled admin user.
    -->
  <resin:AdminAuthenticator>
    <user name="\${admin_user}" password="\${admin_password}"/>
    
    <resin:import path="\${__DIR__}/admin-users.xml" optional="true"/>
  </resin:AdminAuthenticator>


  <!--
     - For clustered systems, create a password in as cluster_system_key
    -->
  <cluster-system-key>\${cluster_system_key}</cluster-system-key>


  <!--
     - For production sites, change dependency-check-interval to something
     - like 600s, so it only checks for updates every 10 minutes.
    -->
  <dependency-check-interval>\${dependency_check_interval?:'2s'}</dependency-check-interval>


  <!-- For resin.properties dynamic cluster joining -->
  <home-cluster>\${home_cluster}</home-cluster>
  <home-server>\${home_server}</home-server>
  <elastic-server>\${elastic_server}</elastic-server>
  <elastic-dns>\${elastic_dns}</elastic-dns>


  <!--
     - Configures the main application cluster.  Load-balancing configurations
     - will also have a web cluster.
    -->
  <cluster id="app">
    <!-- define the servers in the cluster -->
    <server-multi id-prefix="app-" address-list="\${app_servers}" port="6800"/>


    <host-default>
      <!-- creates the webapps directory for .war expansion -->
      <web-app-deploy path="webapps"
                      expand-preserve-fileset="WEB-INF/work/**"
                      multiversion-routing="\${webapp_multiversion_routing}"
                      path-suffix="\${elastic_webapp?resin.id:''}"/>
    </host-default>


    <!-- auto virtual host deployment in hosts/foo.example.com/webapps -->
    <host-deploy path="hosts">
      <host-default>
        <resin:import path="host.xml" optional="true"/>
      </host-default>
    </host-deploy>


    <!-- the default host, matching any host name -->
    <host id="" root-directory=".">
      <!--
         - webapps can be overridden/extended in the resin.xml
        -->
      <web-app id="/" document-directory="webapps/tars"/>


    </host>
      
    <resin:if test="\${resin_doc}">
      <host id="\${resin_doc_host}" root-directory="\${resin_doc_host}">
        <web-app id="/resin-doc" root-directory="\${resin.root}/doc/resin-doc"/>
      </host>
    </resin:if>
  </cluster>


  <cluster id="web">
    <!-- define the servers in the cluster -->
    <server-multi id-prefix="web-" address-list="\${web_servers}" port="6810"/>


    <host id="" root-directory="web">
      <web-app id="">
        <resin:LoadBalance regexp="" cluster="app"/>
      </web-app>
    </host>
  </cluster>


  <cluster id="memcached" xmlns:memcache="urn:java:com.caucho.memcached">
    <!-- define the servers in the cluster -->
    <server-multi id-prefix="memcached-" address-list="\${memcached_servers}" port="6820">
      <!-- listen for the memcache protocol -->
      <listen port="\${memcached_port?:11211}"
              keepalive-timeout="600s" socket-timeout="600s">
        <memcache:MemcachedProtocol/>
      </listen>
    </server-multi>
  </cluster>
 
  <cluster id="proxycache">
    <!-- define the servers in the cluster -->
    <server-multi id-prefix="proxycache-" address-list="\${proxycache_servers}" port="6830"/>


    <host id="" root-directory="proxycache">
      <web-app id="">
        <resin:HttpProxy regexp=".*">
          <!-- backend HTTP servers to proxy to -->
          <addresses>\${backend_servers}</addresses>
        </resin:HttpProxy>
      </web-app>
    </host>
  </cluster>


</resin>
EOF
17、现在可以访问8080端口的web管理系统了


/usr/local/resin/bin/resin.sh start
http://172.31.38.11:8080




13:修改默认:8080端口


[root@iZj6cei7bawcahykkmo8dzZ conf]# pwd


vim /usr/local/resin/conf
#app.http          : 8080
app.http          : 3000
# app.https         : 8443
#web.http          : 8080
web.http          : 3000
分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS