### Example: Master Node Installation
Source: https://tarscloud.github.io/TarsDocs_en/installation/source.html
Example command for installing the Tars framework on a master node. Replace placeholders with your specific MySQL details and network interface.
```bash
chmod a+x linux-install.sh
./linux-install.sh 192.168.7.153 tars2015 eth0 false false
```
--------------------------------
### Example: Slave Node Installation
Source: https://tarscloud.github.io/TarsDocs_en/installation/source.html
Example command for installing the Tars framework on a slave node. Note the 'true' parameter for SLAVE, indicating this is a slave node.
```bash
chmod a+x linux-install.sh
./linux-install.sh 192.168.7.153 tars2015 eth0 false true
```
--------------------------------
### Installation and Basic Usage
Source: https://tarscloud.github.io/TarsDocs_en/dev/tars.js/tars-winston-tars.html
Instructions on how to install the @tars/winston-tars package and a basic example of how to integrate it with Winston.
```APIDOC
## Installation
`npm install @tars/winston-tars`
## Basic Usage
```javascript
var winston = require('winston');
// Requiring `@tars/winston-tars` will expose
// transports
// `winston.transport.TarsRotate`
// `winston.transport.TarsDate`
// config
// `winston.config.tars.levels`
// `winston.config.tars.colors`
require('@tars/winston-tars');
var logger = new (winston.Logger) ({
transports: [
new (winston.transports.Console) ({})
]
});
```
```
--------------------------------
### Service Template Config File Path Example
Source: https://tarscloud.github.io/TarsDocs_en/question/Install_faq-en.html
Example of the directory containing template configuration files for a service. These files are essential for service setup.
```bash
/usr/local/app/tars/tarsnode/data/Test.HelloServer/conf/
```
--------------------------------
### MySQL Configuration Example (my.cnf)
Source: https://tarscloud.github.io/TarsDocs_en/installation/mysql.html
An example configuration file for MySQL. Adjust parameters like buffer pool size, logging, and bind address according to your system's resources and network setup.
```ini
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
# port = .....
# server_id = .....
socket = /tmp/mysql.sock
bind-address=${your machine ip}
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
```
--------------------------------
### Create Installation Directories
Source: https://tarscloud.github.io/TarsDocs_en/installation/source.html
Prepare the system directories for Tars installation.
```bash
cd /usr/local
mkdir tars
mkdir app
```
--------------------------------
### Install TarsGo and Protobuf Dependencies
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarsgo/pb2tarsgo.html
Install the TarsGo framework and the necessary Go protobuf packages. Ensure the protoc compiler is installed separately.
```bash
go get github.com/TarsCloud/TarsGo/tars
go get github.com/golang/protobuf/{proto,protoc-gen-go}
install protoc
```
--------------------------------
### Install Docker on CentOS
Source: https://tarscloud.github.io/TarsDocs_en/installation/docker-install.html
Executes the installation of Docker CE and configures it to start on boot.
```bash
sudo su
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
systemctl start docker
systemctl enable docker
```
--------------------------------
### Manually Start Tars Web Services
Source: https://tarscloud.github.io/TarsDocs_en/installation/source-windows.html
Navigate to the Tars installation directory and use 'npm run start' to manually start the web and demo services. This is useful for troubleshooting if services fail to start via PM2.
```bash
cd c:\tars-install\web\demo; npm run start
cd c:\tars-install\web; npm run start
```
```bash
cd c:\tars-install\web; npm run start
```
--------------------------------
### Test Docker installation
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarsjava/tars-quick-start.html
Verifies that Docker has been installed successfully by running the 'hello-world' container.
```bash
docker run hello-world
```
--------------------------------
### Install and run TARS via Docker
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarsphp/Environment/docker.html
Initializes local data directories and starts the MySQL and TARS containers with required environment variables.
```bash
mkdir -p /data/tars/mysql_data
mkdir -p /data/tars/tars_data
docker run --name mysql -e MYSQL_ROOT_PASSWORD=(your DB password) -d -p 3306:3306 -v /data/tars/mysql_data:/var/lib/mysql mysql:5.6 --innodb_use_native_aio=0
docker run -d -it --name tars --link mysql --env MOUNT_DATA=false --env DBIP=mysql --env DBPort=3306 --env DBUser=root --env DBPassword=(DB password) -p 3000:3000 -v /data/tars/tars_data:/data tarscloud/tars:php
```
--------------------------------
### Prepare MySQL Installation Directory
Source: https://tarscloud.github.io/TarsDocs_en/installation/mysql.html
Sets up the directory structure and ownership for MySQL installation. This involves creating a directory and a symbolic link.
```bash
cd /usr/local
mkdir mysql-5.6.26
chown ${owner}:${owner} ./mysql-5.6.26
ln -s /usr/local/mysql-5.6.26 /usr/local/mysql
```
--------------------------------
### Start RPC Server
Source: https://tarscloud.github.io/TarsDocs_en/dev/tars.js/tars-rpc.html
Execute the main server script to start the RPC server. Ensure you are in the server's directory.
```bash
node main.js
```
--------------------------------
### Start Services from Configuration File
Source: https://tarscloud.github.io/TarsDocs_en/dev/tars.js/tars-rpc.html
Iterates through servants defined in a configuration file to start multiple services.
```javascript
// STEP01 introduces key modules
var Tars = require ("@ tars / rpc");
var TRom = require ("./ NodeJsCommImp.js");
Tars.server.getServant ("./ TRom.NodeJsTestServer.config.conf"). ForEach (function (config) {
var svr, map;
map = {
'TRom.NodeJsTestServer.NodeJsCommObj': TRom.NodeJsCommImp
};
svr = Tars.server.createServer (map [config.servant]);
svr.start (config);
});
```
--------------------------------
### Start and Enable MySQL Service
Source: https://tarscloud.github.io/TarsDocs_en/installation/mysql.html
Starts the MySQL service and configures it to start automatically on system boot. Ensure the service script is correctly placed and executable.
```bash
service mysql start
chkconfig mysql on
```
--------------------------------
### Install tars2go Tool
Source: https://tarscloud.github.io/TarsDocs_en/env/tarsgo.html
Install the tars2go binary from the downloaded TarsGo source directory.
```bash
go install $GOPATH/src/github.com/TarsCloud/TarsGo/tars/tools/tars2go
```
--------------------------------
### Install TarsFramework
Source: https://tarscloud.github.io/TarsDocs_en/installation/source.html
Execute the installation script after compilation.
```bash
cd build
make install
```
--------------------------------
### Navigate to Tars Web Demo Directory and Start
Source: https://tarscloud.github.io/TarsDocs_en/installation/source.html
Use this command to navigate to the demo directory of Tars Web and start the service. This is useful for locating and resolving startup issues.
```bash
cd /usr/local/app/web/demo; npm run start
```
--------------------------------
### Service Log File Path Example
Source: https://tarscloud.github.io/TarsDocs_en/question/Install_faq-en.html
Example of the directory structure for service log files. Ensure logs are checked here if issues arise.
```bash
/usr/local/app/tars/app_log/Test/HelloServer/
```
--------------------------------
### Example Adapter Configuration XML
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarsgo
Shows an example of adapter configuration in XML, defining network endpoints, connection limits, and protocol details for a specific service object.
```xml
#each adapter configuration
#allow Ip for white list.
allow
# ip and port to listen on
endpoint=tcp -h 10.120.129.226 -p 20001 -t 60000
#handlegroup
handlegroup=TestApp.HelloServer.HelloObjAdapter
#max connection
maxconns=200000
#portocol, only tars for now.
protocol=tars
#max capbility in handle queue.
queuecap=10000
#timeout in ms for the request in the queue.
queuetimeout=60000
#servant
servant=TestApp.HelloServer.HelloObj
#threads in handle server side implement code. goroutine for golang.
threads=5
```
--------------------------------
### Navigate to Tars Web Directory and Start
Source: https://tarscloud.github.io/TarsDocs_en/installation/source.html
Use this command to navigate to the main Tars Web directory and start the service. This is useful for locating and resolving startup issues.
```bash
cd /usr/local/app/web; npm run start
```
--------------------------------
### Install Build Dependencies
Source: https://tarscloud.github.io/TarsDocs_en/installation/source.html
Commands to install required build tools and libraries on various operating systems.
```bash
yum install glibc-devel gcc gcc-c++ bison flex cmake psmisc ncurses-devel zlib-devel
```
```bash
sudo apt-get install build-essential bison flex cmake psmisc libncurses5-dev zlib1g-dev
```
```bash
brew install bison flex cmake
```
--------------------------------
### Tars Server Configuration Example
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarscpp/tars-guide.html
An example of the XML-based configuration file structure used to initialize the Tars server environment.
```xml
#Ip:port of local node
node=tars.tarsnode.ServerObj@tcp -h 10.120.129.226 -p 19386 -t 60000
#Application name
app=TestApp
#Server name
server=HelloServer
#Local ip
localip=10.120.129.226
#Management port
local=tcp -h 127.0.0.1 -p 20001 -t 3000
#The server's executable files, configuration files, and so on
basepath=/usr/local/app/tars/tarsnode/data/TestApp.HelloServer/bin/
#Data directory of the server
datapath=/usr/local/app/tars/tarsnode/data/TestApp.HelloServer/data/
#Log path
```
--------------------------------
### Service Executable File Path Example
Source: https://tarscloud.github.io/TarsDocs_en/question/Install_faq-en.html
Example of the directory where service executable files are located. This path is specific to the application and service name.
```bash
/usr/local/app/tars/tarsnode/data/Test.HelloServer/bin/
```
--------------------------------
### Server Tars file example
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarsjava/tars-reference.html
Define your service interface within a module. This example shows a simple 'Hello' interface.
```tars
module TestApp
{
interface Hello
{
string hello(int no, string name);
};
};
```
--------------------------------
### Server Startup Command
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarscpp/tars-guide.html
Execute the server binary with the specified configuration file path.
```bash
HelloServer --config=config.conf
```
--------------------------------
### Start HTTP Benchmark Tool
Source: https://tarscloud.github.io/TarsDocs_en/benchmark/http-guide.html
Use this command to start the tb tool for benchmarking an HTTP service. It specifies the number of requests, concurrency, server details, and the target URL.
```bash
./tb -n 2 -c 5000 -s 20000 -D 192.168.10.3 -P 80 -p http -i 10 -u "http://192.168.16.1/cgi-bin/proxy?cmd=test&f=json" -F aa.txt
```
--------------------------------
### Create Server with Manual Configuration
Source: https://tarscloud.github.io/TarsDocs_en/dev/tars.js/tars-rpc.html
Shows how to create a server instance by explicitly providing endpoint and protocol options.
```javascript
// STEP01 introduces key modules
var Tars = require ("@ tars / tars"). server;
var TRom = require ("./ NodeJsCommImp.js"). TRom;
// STEP02 Create an instance of the service
// Note that "endpoint" and "protocol" are mandatory options, and the format must be the same as the following example
var svr = Tars.createServer (TRom.NodeJsCommImp);
svr.start ({
name: "TRom.NodeJsTestServer.AdminObjAdapetr",
servant: "TRom.NodeJsTestServer.AdminObj",
endpoint: "tcp -h 127.0.0.1 -p 14002 -t 10000",
maxconns: 200000,
protocol: "tars"
});
console.log ("server started.");
```
--------------------------------
### Deploy sample simpleserver
Source: https://tarscloud.github.io/TarsDocs_en/installation/k8s-docker-2.html
Applies the Kubernetes configuration for the simpleserver example.
```bash
cd examples/simple && kubectl apply -f simpleserver.yaml
```
--------------------------------
### Manually Start Tars Web Service
Source: https://tarscloud.github.io/TarsDocs_en/installation/web.html
Navigate to the installation directory and start the service manually to view error output in the console.
```bash
cd /usr/local/app/web
npm run dev
```
--------------------------------
### Implement HttpServer Initialization and Main
Source: https://tarscloud.github.io/TarsDocs_en/demo/tarscpp/tars_cpp_http_demo.html
Implementation of the application initialization, including servant registration and protocol parser assignment.
```cpp
#include "HttpServer.h"
#include "HttpImp.h"
#include "util/tc_network_buffer.h"
using namespace std;
HttpServer g_app;
void
HttpServer::initialize()
{
//initialize application here:
//...
addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj");
addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj",&TC_NetWorkBuffer::parseHttp);
}
/////////////////////////////////////////////////////////////////
void
HttpServer::destroyApp()
{
//destroy application here:
//...
}
/////////////////////////////////////////////////////////////////
int
main(int argc, char* argv[])
{
try
{
g_app.main(argc, argv);
g_app.waitForShutdown();
}
catch (std::exception& e)
{
cerr << "std::exception:" << e.what() << std::endl;
}
catch (...)
{
cerr << "unknown exception." << std::endl;
}
return -1;
}
/////////////////////////////////////////////////////////////////
```
--------------------------------
### Start Server Command
Source: https://tarscloud.github.io/TarsDocs_en/dev/tars.js/tars-rpc.html
Command to execute the server entry file.
```bash
node server.js
```
--------------------------------
### Check CMake Version
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarscpp/tars-2.0-update.html
Verify the installed version of CMake before starting the build process.
```bash
cmake --version
```
--------------------------------
### Example CMake Configuration Output
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarscpp/tars-2.0-update.html
Sample output showing the configuration summary for a macOS build.
```text
jarodruan-mb:cmake-build-debug jarod$ cmake ..
----------------------------------------------------
CMAKE_BUILD_TYPE: Debug
PLATFORM: mac
INSTALL_PREFIX: /usr/local/tars/cpp
----------------------------------------------------
TARS_MYSQL: ON
TARS_HTTP2: OFF
TARS_SSL: OFF
TARS_PROTOBUF: OFF
----------------------------------------------------
CMAKE_SYSTEM_NAME: Darwin
CMAKE_SYSTEM_PROCESSOR: x86_64
CMAKE_CXX_COMPILER_ID: Clang
ABI_STR: sysv
BF_STR: macho
CPU_STR: x86_64
JUMP_SRC: asm/jump_x86_64_sysv_macho_gas.S
MAKE_SRC: asm/make_x86_64_sysv_macho_gas.S
CMAKE_C_SIZEOF_DATA_PTR: 8
----------------------------------------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jarod/centos/TarsCpp/cmake-build-debug
```
--------------------------------
### Start Tars Node Web Service with PM2
Source: https://tarscloud.github.io/TarsDocs_en/installation/source-windows.html
If the web page is inaccessible, use 'pm2 start tars-node-web' to ensure the service is running. This command is recommended for formal operation after installation.
```bash
pm2 start tars-node-web
```
--------------------------------
### Implement Server Application
Source: https://tarscloud.github.io/TarsDocs_en/dev/tarscpp/tars-guide.html
Implementation file for the HelloServer class and the main entry point.
```cpp
#include "HelloServer.h"
#include "HelloImp.h"
using namespace std;
HelloServer g_app;
/////////////////////////////////////////////////////////////////
void
HelloServer::initialize()
{
//initialize application here:
//Adding Servant interface to implement binding between class HelloImp and routing Obj
addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".HelloObj");
}
/////////////////////////////////////////////////////////////////
void
HelloServer::destroyApp()
{
//destroy application here:
//...
}
/////////////////////////////////////////////////////////////////
int
main(int argc, char* argv[])
{
try
{
g_app.main(argc, argv);
g_app.waitForShutdown();
}
catch (std::exception& e)
{
cerr << "std::exception:" << e.what() << std::endl;
}
catch (...)
{
cerr << "unknown exception." << std::endl;
}
return -1;
}
////////////////////////////////////////////////////////////////
```
--------------------------------
### Quick Release Parameters
Source: https://tarscloud.github.io/TarsDocs_en/benchmark/build.html
Configuration parameters for the install.sh script.
```text
webhost Host or ip:port on the TarsWeb management side
token Which can obtain the http://webhost/auth.html#/token through the management side
adminsip The IP address of the AdminServer deployment, it must be deployed at a single point. It is recommended to deploy together with tarsregistry.。
nodeip The IP address of the NodeServer deployment, it should be separated from the AdminServer, it is recommended to expand the capacity on the management side. The more machines deployed, the stronger the ability to support parallel benchmark.
```
--------------------------------
### Configure node-agent to run as a specific user
Source: https://tarscloud.github.io/TarsDocs_en/dev/tars.js/tars-node-agent.html
Example of starting the node-agent as a specific user ('nobody'). This can be configured via command line, package.json, or TARS configuration file.
```bash
node-agent app.js –run-as-user = nobody
```
```json
{
"nodeAgent" : {
"runAsUser" : "nobody"
}
}
```
```ini
run-as-user = nobody
server>
application>
tars>
```
--------------------------------
### Tars List Operation Example
Source: https://tarscloud.github.io/TarsDocs_en/dev/tars.js/tars-stream.html
Demonstrates adding elements, getting length, accessing elements by index, and iterating through a Tars List. Also shows conversion to and from objects for lists of custom types.
```javascript
var Tars = require ("@tars/stream");
var ve = new Tars.List (Tars.String);
// Add elements to the array
ve.push ("TENCENT-MIG");
ve.push ("TENCENT-SNG");
ve.push ("TENCENT-IEG");
ve.push ("TENCENT-TEG");
// Get the length of the array
console.log ("Length:", ve.length);
// Get the element at the specified position
console.log ("Array [1]:", ve.at (1));
// Iterate method 1:
ve.forEach (function (value, index, oArray) {
console.log ("Array [" + index + "]:", value);
});
// Traverse method 2:
for (var index = 0, len = ve.length; index > v);
int set(vector