2016年4月22日 星期五

Thrift C++ on Linux with Makefile Tutorial


首先假设你已经安装好thrift,我用的是CentOS7.2

C++

[root@thrift gen-cpp]# thrift --version
Thrift version 1.0.0-dev

准备thrift档案内容如下
[root@thrift cal]# vi cal.thrift
struct nums {
    1: i32 i1;
    2: i32 i2;
}

service sumservice {
    void sum(1: nums n)
}

然后用thrift产生cpp的header及source档案
[root@thrift cal]# thrift --gen cpp cal.thrift

可以看见产生了gen-cpp文件夹,进入gen-cpp文件夹,看见以下几个产生出来的文件。
其中3组.h及.cpp文件:cal_constants.*,cal_types.*,sumservice.*,共6个文件thrift已经完全写好。
cal_constants.* 及 cal_types.* 的命名方式是基于cal.thrift档案名称的
sumservice.* 的命名方式cal.thrift档案里面所有的service的名称的
sumservice.*是server side交易资料的implementation
产生出来的3组.h及.cpp合共全部6个文件一般无需自行更改
[root@thrift sum]# ls && cd gen-cpp/ && ls
cal.thrift  gen-cpp
cal_constants.cpp  cal_types.cpp  sumservice.cpp  sumservice_server.skeleton.cpp
cal_constants.h    cal_types.h    sumservice.h

留意sumservice.*里面的几个class名字及顺序
If, IfFactory, IfSingletonFactory, Null:If
args__isset, args, pargs, result, presult
Client:If, Processor:TDispatchProcessor, ProcessorFactory:TPorcessorFactory
Multiface:If, ConcurrentClient : If, 

唯一需要自行更改的是sumservice_server.skeleton.cpp, 这是Handler:If的
原本这个sumservice的预设implementation是把function名字打印出来
[root@thrift gen-cpp]# vi sumservice_server.skeleton.cpp
class sumserviceHandler : virtual public sumserviceIf {
 public:
  sumserviceHandler() {
    // Your initialization goes here
  }
  void sum(const nums& n) {
    // Your implementation goes here
    printf("sum\n");
  }
};
其中的main function大意是这样的,主要有关联的是Handler>TProcessor>TSimpleServer,而ServerTransport, TransportFactory及ProtocolFactory是配角。
int main() {
  TSimpleServer server(TProcessor(sumserviceHandler()));
  server.server();
};

由于每次运行都会把这歌现有的skeleton覆盖掉,所以现在干脆直接改名以免后顾之忧,改名以后列出的档案也比较工整
[root@thrift gen-cpp]# mv sumservice_server.skeleton.cpp server.cpp && ls
cal_constants.cpp  cal_types.cpp  client.cpp  sumservice.cpp
cal_constants.h    cal_types.h    server.cpp  sumservice.h

我们把server.cpp其中的两个方法改成以下有意义的内容,值得注意的是这两个方法都是放在一个由sumserviceIf界面虚疑继承的
[root@thrift gen-cpp]# vi server.cpp
class sumserviceHandler : virtual public sumserviceIf {
sumserviceHandler() {
    printf("server created \n");
  }
void sum(const nums& n) {
    printf("sum: %d + %d = %d \n", n.i1, n.i2, n.i1 + n.i2);
  }
}

用g++编译server程序 其中server档案需要参考types, constants 及service档案,留意最后要加上-lthrift
[root@thrift gen-cpp]# g++ -o server server.cpp sumservice.cpp cal_types.cpp cal_constants.cpp -lthrift

可以试试把server程序跑起来,并且看见sumserviceHandler的建构子被呼叫了
[root@thrift gen-cpp]# ls
cal_constants.cpp  cal_types.cpp  server          sumservice.h
cal_constants.h    cal_types.h    sumservice.cpp  server.cpp
[root@thrift gen-cpp]# ./server
server created
^C


下一步要建立client代码去跟server程序沟通
首先要从sumservice.h找出你等下准备要继承的client class, grep Client一下会发现名有两个classes sumserviceClient  sumserviceConcurrentClient 
[root@thrift gen-cpp]# grep Client sumservice.h
#include <thrift/async/TConcurrentClientSyncInfo.h>
class sumserviceClient : virtual public sumserviceIf {
  sumserviceClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) {
  sumserviceClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, boost::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) {
class sumserviceConcurrentClient : virtual public sumserviceIf {
  sumserviceConcurrentClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) {
  sumserviceConcurrentClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, boost::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) {
  ::apache::thrift::async::TConcurrentClientSyncInfo sync_;


client跟server的基本代码结构非常类似,所以直接考出来修改
[root@thrift gen-cpp]# cp server.cpp client.cpp && vi client.cpp

顶头加入TSocket.h并把main方法改成以下
#include <thrift/transport/TSocket.h>
int main(int argc, char **argv) {
  shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
  shared_ptr<TTransport> transport(new TBufferedTransport(socket));
  shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
  transport->open();
  // client code starts here
  nums n;
  n.i1 = 1;
  n.i2 = 2;
  sumserviceClient(protocol).sum(n);
  // client code ends here
  transport->close();
  return 0;
}

client.cpp以下几句只跟server有关却跟client无关,正在写client code的我们为求简洁把他们移除掉。不怕,万一忘记移除,client程序还是可以编译跑起来的。
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
using namespace ::apache::thrift::server;
class sumserviceHandler
shared_ptr<sumserviceHandler> handler(new sumserviceHandler());
shared_ptr<TProcessor> processor(new sumserviceProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));

client.cpp中你会看见原本server的TTransportFactory及TProtocolFactory,如果把它们的Factory去掉就会变成client的要员
  1. boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));    
  2.     boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));    
  3.     boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport)); 

client.cpp整个就是这样
#include "sumservice.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TBufferTransports.h>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using boost::shared_ptr;
#include <thrift/transport/TSocket.h>
int main(int argc, char **argv) {
  shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
  shared_ptr<TTransport> transport(new TBufferedTransport(socket));
  shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
  transport->open();
  // client code starts here
  nums n;
  n.i1 = 1;
  n.i2 = 2;
  sumserviceClient(protocol).sum(n);
  // client code ends here
  transport->close();
  return 0;
}


可以编译了
[root@thrift gen-cpp]# g++ -o client client.cpp sumservice.cpp cal_types.cpp cal_constants.cpp -lthrift

如果看见這个问题不要紧
[ricky@thrift1 gen-cpp]$ ./server
./server: error while loading shared libraries: libthrift-1.0.0-dev.so: cannot open shared object file: No such file or directory

再跑一次就可以
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ export LD_LIBRARY_PATH
$ ./server


可以跑了!背景跑server,前景跑client
[root@thrift gen-cpp]# ./server &
[1] 22189
[root@thrift gen-cpp]# server created
./client
sum: 1 + 2 = 3
[root@thrift gen-cpp]# pkill server


做个最原始的makefile,可以看到server跟client档案的dependency
[root@thrift gen-cpp]# vi makefile

.PHONY: all
all: server client

server: cal_constants.cpp cal_types.cpp sumservice.cpp cal_constants.h cal_types.h server.cpp sumservice.h
        g++ -std=c++11 -o server cal_constants.cpp cal_types.cpp sumservice.cpp server.cpp -lthrift
client: cal_constants.cpp cal_types.cpp client.cpp sumservice.cpp cal_constants.h cal_types.h server.cpp sumservice.h
        g++ -std=c++11 -o client cal_constants.cpp cal_types.cpp sumservice.cpp client.cpp -lthrift


Python

假设你不用C++而要使用Python,用thrift产生cpp的header及source档案
[root@thrift sum]# thrift --gen py cal.thrift && ls && ls ./gen-py/ && ls ./gen-py/cal
cal.thrift  gen-cpp  gen-py
cal  __init__.py
constants.py  __init__.py  sumservice.py  sumservice-remote  ttypes.py


可以看到thrift并不会把server代码skeleton产生给你,于是你需要在thrift档案同一目录下,建立以下的server.py,值得注意的是里面的CalHandler这个类并没有使用继承,只要是任何一个有写好sum(self,n)的类就可以送给sumservice.Processor()去被呼叫。留意,sumservice.py已经由thrift写好里面传送的代码,不用自己修改的。
[root@thrift sum]# vi server.py
#!/usr/bin/env python
import socket
import sys
sys.path.append('./gen-py')
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
from cal import sumservice
from cal.ttypes import *
class CalHandler :
    def sum(self, n) :
        print(n.i1 + n.i2)
handler = CalHandler()
processor = sumservice.Processor(handler)
transport = TSocket.TServerSocket("127.0.0.1", 9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)

server.serve()

参考./gen-py/sum/ttypes.py,可以看见nums已经写好了建构子,与c++的POD struct不同
class nums(object):
    def __init__(self, i1=None, i2=None,):
        self.i1=i1
        self.i2=i2

[root@thrift sum]# vi client.py
#!/usr/bin/env python
import sys
sys.path.append('./gen-py')
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from cal import sumservice
from cal.ttypes import *
try:
    transport = TSocket.TSocket('127.0.0.1', 9090)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = sumservice.Client(protocol)
    transport.open()
    client.sum(nums(1,2)) # call constructor of nums() class from ttypes.py
    transport.close()
except Thrift.TException as ex:

    print ("%s" % (ex.message))

Java

must use "127.0.0.1" instead of "localhost" in server.py and JavaClient.java

JavaClient.java
import org.apache.thrift.TException;
import org.apache.thrift.transport.TSSLTransportFactory;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
public class JavaClient {
    public static void main(String[] args) {
        try {
            TTransport transport;
            transport = new TSocket("127.0.0.1", 9090);
            transport.open();
            TProtocol protocol = new  TBinaryProtocol(transport);
            sumservice.Client client = new sumservice.Client(protocol);
            client.sum(new nums(1, 6));
            System.out.println("done");
            transport.close();
        }
        catch (TException x) {
            x.printStackTrace();
        }
    }
}

[ricky@thrift2 cal]$ thrift --gen java cal.thrift && ls gen-java
nums.java  sumservice.java

[ricky@thrift1 gen-java]$ pwd
/home/ricky/dev/Thrift/cal/gen-java
cp /path/to/thrift/lib/java/build/lib/*.jar ./lib/
cp /path/to/thrift/lib/java/build/libthrift-1.0.0.jar ./lib/

[ricky@thrift2 gen-java]$ javac -cp ".:./lib/*" JavaClient.java && java -cp ".:./lib/*" JavaClient






asdfas

2016年4月20日 星期三

Installing Thrift 1.0.0 on CentOS 7.2 on 4/20/2016

Installing Thrift 0.9.3 on CentOS 7.2 on 4/20/2016

Main Reference https://thrift.apache.org/docs/install/centos

sudo yum install -y autoconf automake libtool flex bison pkgconfig

sudo yum -y groupinstall "Development Tools"

sudo yum install -y wget

Build and Install the Apache Thrift IDL Compiler

git clone https://git-wip-us.apache.org/repos/asf/thrift.git
cd thrift
./bootstrap.sh
./configure --with-lua=no

Python 2

Configure Thrift
./configure --with-lua=no
By default only Python available on Linux CentOS 7.2 after ./configure

thrift 1.0.0-dev
Building Plugin Support ...... : no
Building C++ Library ......... : no
Building C (GLib) Library .... : no
Building Java Library ........ : no
Building C# Library .......... : no
Building Python Library ...... : yes
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : no
Building Dart Library ........ : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : no
Building Lua Library ......... : no

Make and Install Thrift
echo "note: make takes 10 minutes to complete"
make
sudo make install
This will build the compiler (thrift/compiler/cpp/thrift --version) and any language libraries supported. The make install step installs the compiler on the path: /usr/local/bin/thrift You can use the ./configure --enable-libs=no switch to build the Apache Thrift IDL Compiler only without lib builds. To run tests use "make check".
[ricky@thrift2 thrift]$ thrift --version
Thrift version 1.0.0-dev

Using CentOS 7.2 default python 2.7.5 to run the Thrift server.py


[ricky@thrift2 cal]$ python --version
Python 2.7.5
[ricky@thrift2 cal]$ python server.py Traceback (most recent call last): File "server.py", line 6, in <module> from thrift.protocol import TBinaryProtocol File "/usr/lib/python2.7/site-packages/thrift/protocol/TBinaryProtocol.py", line 20, in <module> from .TProtocol import TType, TProtocolBase, TProtocolException File "/usr/lib/python2.7/site-packages/thrift/protocol/TProtocol.py", line 24, in <module> import six ImportError: No module named six
[ricky@thrift2 cal]$ sudo yum install -y python-six
[ricky@thrift2 cal]$ python server.py
running...


Python 3 (No Solution yet on 12/21/2016 found!)

Install Anaconda 3
wget https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh
chomd +x Anaconda3-4.2.0-Linux-x86_64.sh
./Anaconda3-4.2.0-Linux-x86_64.sh
[ricky@thrift2 ~]$ python --version
Python 3.5.2 :: Anaconda 4.2.0 (64-bit)

Error 1: ImportError: No module named 'thrift'
[ricky@thrift2 cal]$ python server.py
Traceback (most recent call last):
  File "server.py", line 4, in <module>
    from thrift.transport import TSocket
ImportError: No module named 'thrift'

So, you must use pip to install thrift (only works for Windows but not Linux)
pip install --upgrade pip
pip install thrift

Error 2: ImportError: cannot import name 'TFrozenDict'
[ricky@thrift2 cal]$ python server.py
Traceback (most recent call last):
  File "server.py", line 8, in <module>
    from cal import sumservice
  File "./gen-py/cal/sumservice.py", line 9, in <module>
    from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException
ImportError: cannot import name 'TFrozenDict'

No Solution yet on 12/21/2016 found! Now for me I can only use Python 2 with Thrift, but not Python 3.

JAVA

Installing Java 8 by RPM and ant
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.rpm
sudo rpm -ivh jdk-8u111-linux-x64.rpm
sudo yum install -y ant

Check JDK Version
[ricky@thrift2 ~]$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
[ricky@thrift2 thrift]$ javac -version
javac 1.8.0_111

Configure Thrift
./configure --with-lua=no
thrift 1.0.0-dev

Building Plugin Support ...... : no
Building C++ Library ......... : no
Building C (GLib) Library .... : no
Building Java Library ........ : yes
Building C# Library .......... : no
Building Python Library ...... : yes
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : no
Building Dart Library ........ : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : no
Building Lua Library ......... : no

Java Library:
   Using javac ............... : javac
   Using java ................ : java
   Using ant ................. : /usr/bin/ant

Make and Install Thrift
echo "note: make takes 10 minutes to complete"
make
sudo make install








C++

Add Optional C++ Language Library Dependencies

Install C++ Lib Dependencies


sudo yum -y install gcc-c++ libevent-devel zlib-devel openssl-devel

Upgrade Boost >= 1.53

wget http://sourceforge.net/projects/boost/files/boost/1.53.0/boost_1_53_0.tar.gz
tar xvf boost_1_53_0.tar.gz
cd boost_1_53_0
./bootstrap.sh
sudo ./b2 install


Thrift的安装和简单示例
http://blog.csdn.net/anonymalias/article/details/26154405

g++ -o server server_types.cpp server_constants.cpp serDemo.cpp serDemo_server.skeleton.cpp -lthrift
g++ -o client server_types.cpp server_constants.cpp serDemo.cpp  client.cpp -lthrift
// client has no no serDemo_server.skeleton.cpp

When running, if you see

error while loading shared libraries: libthrift-1.0.0-dev.so: cannot open shared object file: No such file or directory

Then add below to ~/.bash_profile
export LD_LIBRARY_PATH=/usr/local/lib/:${LD_LIBRARY_PATH}


thrift 0.9.3 on Centos 7.2


yum install boost-devel
cd /root/test/thrift/thrift-0.9.3
./configure

if configure: error: "Error: libcrypto required."

yum install openssl-devel


Download the thrift.tar
tar zxvf thrift.tar
./configure

Then you will see

Building C++ Library ......... : yes

Building C (GLib) Library .... : no

Building Java Library ........ : no

Building C# Library .......... : no

Building Python Library ...... : no

Building Ruby Library ........ : no

Building Haxe Library ........ : no

Building Haskell Library ..... : no

Building Perl Library ........ : no

Building PHP Library ......... : no

Building Erlang Library ...... : no

Building Go Library .......... : no

Building D Library ........... : no

Building NodeJS Library ...... : no

Building Lua Library ......... : no



C++ Library:

   Build TZlibTransport ...... : yes

   Build TNonblockingServer .. : no
   Build TQTcpServer (Qt4) .... : no
   Build TQTcpServer (Qt5) .... : no




2016年4月19日 星期二

笔记:Ubuntu下快速开始使用Python Thrift

http://sunliwen.com/2012/02/apache-thrift-on-ubuntu-10-04/


笔记:Ubuntu下快速开始使用Python Thrift

本文介绍如何在Ubuntu 10.04下安装Apache Thrift并用Python写一个Demo。
apt-get install libboost-dev libevent-dev python-dev automake pkg-config libtool flex bison sun-java6-jdk
wget http://www.apache.org/dist//thrift/0.8.0/thrift-0.8.0.tar.gz
tar zxvf thrift-0.8.0.tar.gz
cd thrift-0.8.0
./configure
make
sudo make install
sudo pip install thrift
编辑接口文件 hellowworld.thrift:
service HelloWorld {
    string ping(),
    string say(1:string msg)
}
编辑 server.py
#!/usr/bin/env python
 
import socket
import sys
sys.path.append('./gen-py')
 
from helloworld import HelloWorld
from helloworld.ttypes import *
 
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
 
class HelloWorldHandler:
  def ping(self):
    return "pong"
 
  def say(self, msg):
    ret = "Received: " + msg
    print ret
    return ret
 
handler = HelloWorldHandler()
processor = HelloWorld.Processor(handler)
transport = TSocket.TServerSocket("localhost", 9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
 
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
 
print "Starting thrift server in python..."
server.serve()
print "done!"
编辑 client.py
#!/usr/bin/env python
 
import sys
sys.path.append('./gen-py')
 
from helloworld import HelloWorld
 
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
 
try:
  transport = TSocket.TSocket('localhost', 9090)
  transport = TTransport.TBufferedTransport(transport)
  protocol = TBinaryProtocol.TBinaryProtocol(transport)
  client = HelloWorld.Client(protocol)
  transport.open()
 
  print "client - ping"
  print "server - " + client.ping()
 
  print "client - say"
  msg = client.say("Hello!")
  print "server - " + msg
 
  transport.close()
 
except Thrift.TException, ex:
  print "%s" % (ex.message)
thrift --gen py helloworld.thrift
python server.py
python client.py

2016年4月14日 星期四

Installing C++ 4.8.5 on CentOS 6.7

With yum on CentOS, the most updated gcc version are
gcc 4.1.2 for CentOS 5
gcc 4.4.7 for CentOS 6
gcc 4.8.5 for CentOS 7

What if you want to have higher version to run on CentOS 6? This article is going to tell you how to compile gcc on CentOS 6.7 which is the final version of CentOS.

First you are going to download CentOS 6.7 DVD1 ISO file.
http://centos.uhost.hk/6.7/isos/x86_64/CentOS-6.7-x86_64-bin-DVD1.iso

I used VMWare Workstation 12 Player to host the virtual machine. As it supports "Linux Easy Install", simply mount the ISO to a newly created VM, start it to enter user name and password. After 15 minutes, it will bring you to the Linux installed environment.


Install gcc compiler
First thing to to is to use terminal to install the most updated compiler. It will be used to compile the new compiler. Yes. gcc is compiled using its gcc compiler.
sudo yum install gcc-c++

Install glibc
sudo yum install -y gcc texinfo-tex flex zip libgcc.i686 glibc-devel.i686

Download gcc source code
wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz

Download mpc, mpfr, gmp package
tar zxf gcc-4.8.5.tar.gz
cd gcc-4.8.5
./contrib/download_prerequisites

Compile gcc
mkdir gcc-build-4.8.5
cd gcc-build-4.8.5
../configure --prefix=/usr
sudo make && make install

Check your gcc versions
gcc --version
gcc (GCC) 4.8.5
g++ --version
g++ (GCC) 4.8.5
which gcc
/usr/bin/gcc
which g++
/usr/bin/g++

After 2 hours of compilation, you will be able to see the below installed log.


Test the compilation:

cat >test.cc <<EOF
#include <iostream>
using namespace std;
int main() {
  cout << "Hello, World!" << endl;
  return 0;
}
EOF

g++ -o test.exe -g -Wall test.cc

./test.exe

Hello, World!

Check rpm installed
Because you are compiling gcc on your own, yum or rpm are unware of the new gcc version.
rpm -qa | grep gcc
gcc-4.4.7-16.el6.x86_64
libgcc-4.4.7-16.el6.x86_64
libgcc-4.4.7-16.el6.i686
gcc-c++-4.4.7-16.el6.x86_64

2016年4月7日 星期四

Linux CentOS 6.7 and 7 C++ Java Netbeans Python RobotFramework SQLite

Linux CentOS 7 C++ Java Netbeans Eclipse CDT Python RobotFramework
Basic

Download CentOS 7 Everything
Install minimal, 512MB RAM minimal for CentOS 6.9

Add sudoer
adduser ricky
passwd ricky
usermod -aG wheel ricky
echo 'ricky ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers (CentOS 6, maybe 7 also ok)
su - ricky
sudo ls -lart /root

NIC onboot
sudo ifup eth0
vi /etc/sysconfig/network-scritps/ifcfg-eth0
onboot=yes

Install ifconfig, netstats, traceroute
sudo yum -y install net-tools


Set Host Name (CentOS 7 only, optional for X11)
sudo hostnamectl set-hostname centos72

Set Host Name (CentOS 6 only, optional for X11)
sudo vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos6

Change SSHD config
sudo vi /etc/ssh/sshd_config
  • X11Forwarding yes
  • X11UseLocalhost no
Install xauth and xclock
sudo yum -y install xauth xclock openssh-clients

Common

Change Time Zone to HKT
sudo ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date

Enable line number in VI
sudo yum install -y vim
printf "set number" > ~/.vimrc

Install wget

sudo yum install -y wget

NTP Service (CentOS 7)
sudo yum -y install ntp
sudo service ntpd start
ntpq -p

NTP Restart (CentOS 7)
sudo vi /etc/ntp.conf
server 192.168.0.1 iburst
sudo service ntpd restart
ntpq -p

NTP (CentOS 6)
sudo yum -y install ntp ntpdate ntp-doc
sudo chkconfig ntpd on
sudo ntpdate pool.ntp.org
sudo /etc/init.d/ntpd start

ACPI Shutdown
sudo yum -y install acpid
sudo chkconfig acpid on (CentOS 6)
sudo service acpid start (CentOS 6)
systemctl enable acpid.service
systemctl start acpid.service

Check $DISPLAY

Check Host File for $DISPLAY
sudo vi /etc/hosts
192.168.0.101 centos7

Check $DISPLAY after reboot
For CentOS 6,
sudo service sshd restart
exit
For CentOS 7,
reboot
ssh client again
echo $DISPLAY
centos72:10.0

Install Xming
Install Xming X11 display server (https://sourceforge.net/projects/xming/) on your desktop PC and launch it

Enable X11 forward for PuTTY
Connection > SSH > X11 > Enable X11 forwarding

Proxy

Add DNS Server
vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 4.4.4.4

Add Proxy Server
vi ~/.bash_profile
http_proxy=http://192.168.0.1:8080
export http_proxy
https_proxy=http://192.168.0.1:8080
export https_proxy

Setup Yum Proxy
vi /etc/yum.conf
proxy=http://192.168.0.1:8080

Install EPEL repository and xclip (for copying ssh keys using command only)
sudo yum -y install epel-release
sudo yum -y install xclip


Generate public key to remote machine
ssh-keygen -t rsa -C "admin@example.com"
cat ~/.ssh/id_rsa.pub
xclip -sel clip < ~/.ssh/id_rsa.pub
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.2

GUI

Install Desktop (Optional)

sudo yum -y groups install "GNOME Desktop"

Install XRDP
sudo yum install xrdp tigervnc-server
sudo chcon -t bin_t /usr/sbin/xrdp
sudo chcon -t bin_t /usr/sbin/xrdp-sesman
sudo systemctl enable xrdp.service

sudo systemctl start xrdp
sudo systemctl status xrdp
netstat -antup | grep xrdp
sudo vi /etc/xrdp/xrdp.ini
max_bpp=24

C++

glibc
sudo yum -y install glibc* cmake

C++ Development (for CentOS 7)
sudo yum -y group install "Development Tools"
whereis gcc
gcc --version

C++ Development (for CentOS 6)
echo Mandatory Packages:
sudo yum -y install autoconf automake binutils bison flex gcc gcc-c++ gettext libtool make patch pkgconfig redhat-rpm-config rpm-build rpm-sign
echo Default Packages:
sudo yum -y install byacc cscope ctags diffstat doxygen elfutils gcc-gfortran git indent intltool patchutils rcs subversion swig systemtap
echo Optional Packages:

sudo yum -y install cmake git libstdc++-docs
whereis gcc
gcc --version

GCC with Boost on CentOS (Optional)
http://joelinoff.com/blog/?p=1604#more-1604

Compile a Helloworld
rm -f foo.c && printf '#include<stdio.h>\n void main(void){ printf("Hello");}' >> foo.c && gcc foo.c -o foo && ./foo

JAVA

JVM

Installing Java 8 by RPM
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.rpm
sudo rpm -ivh jdk-8u111-linux-x64.rpm

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm

NETBEANS

Installing NetBeans JDK by SH
sudo yum -y install libXtst
wget http://download.netbeans.org/netbeans/8.1/final/bundles/netbeans-8.1-cpp-linux-x64.sh
chmod a+x netbeans-8.1-cpp-linux-x64.sh
./netbeans-8.1-cpp-linux-x64.sh


SO File Path (Required if want permanent environment variables)
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/NetBeansProjects/your/lib
export LD_LIBRARY_PATH

Uninstall Netbeans
/home/ricky/netbeans-8.1/uninstall.sh (no need sudo)

Eclipse
http://www.eclipse.org/downloads/eclipse-packages/?osType=linux&release=undefined

to be continued

SQLite

SQLite Development with C++
sudo yum install -y sqlite-devel


Python and RobotFramework

Python
sudo yum -y install python-devel python-setuptools

PIP
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

RobotFramework
sudo pip --proxy http://10.23.31.130:8080 install paramiko robotframework robotframework-ride robotframework-sshlibrary 

wxPython
yum install wxPython python-paramiko sshpass



GCC Version
On CentOS 7.2
[ricky@pc009 ~]$ cat /etc/*release

CentOS Linux release 7.2.1511 (Core)
$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
On CentOS 7.3
[ricky@centos73 ~]$ cat /etc/*release
CentOS Linux release 7.3.1611 (Core)
[ricky@centos73 ~]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

MiniConda



wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...