Install OpenVZ and configure OpenVZ Web Panel in CentOS

Install OpenVZ and configure OpenVZ Web Panel in CentOS

Note: This tutorial is based on a KVM-based VPS or dedicated server.
Prerequisites: VPS or server installed with CentOS 6 or above. Update the system and install the vim editor.

1. Turn off selinux and configure iptables (important)

 vim /etc/sysconfig/selinux

Added content:

 SELINUX=disabled

save.
Open port 3000 of iptables:

 /sbin/iptables -I INPUT -p tcp --dport 3000 -j ACCEPT /etc/rc.d/init.d/iptables save /etc/init.d/iptables restart

2. Install OpenVZ

Configure YUM repository

 cd /etc/yum.repos.d wget http://download.openvz.org/openvz.repo rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ yum update -y

Install OpenVZ kernel and tools such as vzctl and vzquota

 yum install vzkernel yum install vzctl vzquota

Configure OS kernel parameters, enter the /etc/sysctl.conf file, and modify the following two parameters

In order for VE to access the external network, IP needs to be forwarded

 net.ipv4.ip_forward = 1

Mainly controls the debug function of kernel system information

 kernel.sysrq = 1

Make the above configuration file effective

 modprobe bridge lsmod|grep bridge

Now reboot and check if the VZ service is running after reboot.

 chkconfig --list vz

If the following information is returned, it means it is running.

 vz 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Before starting, you can check whether the OpenVZ service has been started.

 service vz status service vz start

3. Install OpenVZ Web Panel

 wget -O - https://raw.githubusercontent.com/sibprogrammer/owp/master/installer/ai.sh | sh

After the installation is complete, log in to the control panel using the following information

 http://:3000

4. Add hw-daemon.rb content

 vim /opt/ovz-web-panel/utils/hw-daemon/hw-daemon.rb

Add the following content:

 #!/usr/bin/env ruby require 'webrick' require 'xmlrpc/server.rb' # workaround for clients with incorrect DNS records Socket.do_not_reverse_lookup = true ENV['PATH'] += ':/usr/sbin' DAEMON_VERSION = '1.3' CURRENT_DIR = File.expand_path(File.dirname(__FILE__)) + '/' CONFIG_FILE = CURRENT_DIR + 'hw-daemon.ini' PID_FILE = CURRENT_DIR + 'hw-daemon.pid' LOG_FILE = CURRENT_DIR + 'hw-daemon.log' SSL_CERT_FILE = CURRENT_DIR + "/certs/server.crt" SSL_PKEY_FILE = CURRENT_DIR + "/certs/server.key" $SERVER_ADDRESS = "0.0.0.0" $SERVER_PORT = 7767 $AUTH_KEY = "" $DEBUG = false $LOG = WEBrick::Log.new(LOG_FILE) $SSL_ENABLE = false $SSL_CERT = '' $SSL_PKEY = '' $THREADS = {} class HwDaemonApiHandler < XMLRPC::WEBrickServlet def version DAEMON_VERSION end def exec(command, args = '') output = `#{command} #{args} 2>&1` exit_code = $? $LOG.debug("Exec command: #{command} #{args}; code: #{exit_code}; output:\n#{output}") { 'exit_code' => exit_code >> 8, 'output' => output } end def job(command, args = '') job_id = generate_id t = Thread.new do result = self.exec(command, args) $THREADS[job_id]['result'] = result end $THREADS[job_id] = { 'thread' => t } { 'job_id' => job_id } end def job_status(job_id) found = $THREADS.has_key?(job_id) result = '' if found alive = $THREADS[job_id]['thread'].alive? result = $THREADS[job_id]['result'] unless alive end { 'found' => found, 'alive' => alive, 'result' => result } end def write_file(filename, content) File.open(filename, 'w') { |file| file.write(content) } $LOG.debug("Writing file: #{filename}") end def service(request, response) WEBrick::HTTPAuth.basic_auth(request, response, '') do |user, password| user == 'admin' && password == $AUTH_KEY end super end def handle(method, *params) $LOG.debug("Execute method: #{method}") super end private def generate_id symbols = [('0'..'9'),('a'..'f')].map{ |i| i.to_a }.flatten (1..32).map{ symbols[rand(symbols.length)] }.join end end class HwDaemonUtil def initialize check_environment if (0 == ARGV.size) do_help end load_config $LOG.level = WEBrick::Log::DEBUG if $DEBUG if $SSL_ENABLE require 'webrick/https' $SSL_CERT = OpenSSL::X509::Certificate.new(File.open(SSL_CERT_FILE).read) if File.readable?(SSL_CERT_FILE) $SSL_PKEY = OpenSSL::PKey::RSA.new(File.open(SSL_PKEY_FILE).read) if File.readable?(SSL_PKEY_FILE) end command = ARGV[0] case command when 'start' do_start when 'stop' do_stop when 'restart' do_restart when 'status' do_status else do_help end end def check_environment if RUBY_VERSION !~ /1\.8\..+/ puts "Ruby #{RUBY_VERSION} is not supported." exit(1) end if !File.exists?('/proc/vz/version') puts "Daemon should be run on the server with OpenVZ." exit(1) end end def do_start puts "Starting the daemon..." servlet = HwDaemonApiHandler.new servlet.add_handler("hwDaemon", servlet) servlet.set_default_handler do |name, *args| raise XMLRPC::FaultException.new(-99, "Method #{name} missing or wrong number of parameters!") end server = WEBrick::HTTPServer.new( :Port => $SERVER_PORT, :BindAddress => $SERVER_ADDRESS, :Logger => $LOG, :SSLEnable => $SSL_ENABLE, :SSLVerifyClient => ($SSL_ENABLE ? OpenSSL::SSL::VERIFY_NONE : nil), :SSLCertificate => $SSL_CERT, :SSLPrivateKey => $SSL_PKEY, :SSLCertName => [ [ "CN", WEBrick::Utils::getservername ] ] ) server.mount('/xmlrpc', servlet) ['INT', 'TERM'].each { |signal| trap(signal) { server.shutdown } } WEBrick::Daemon.start do write_pid_file server.start delete_pid_file end end def do_stop if (File.exists?(PID_FILE)) pid = File.read(PID_FILE) $LOG.debug("Killing process with PID #{pid.to_i}") Process.kill('TERM', pid.to_i) end puts "Daemon was stopped." end def do_restart do_stop do_start end def do_status if (File.exists?(PID_FILE)) puts "Daemon is running." else puts "Daemon is stopped." exit(1) end end def do_help puts "Usage: ruby hw-daemon.rb (start|stop|restart|status|help)" exit(1) end def load_config file = File.new(CONFIG_FILE, 'r') while (line = file.gets) key, value = line.split('=', 2).each { |v| v.strip! } case key when 'address' $SERVER_ADDRESS = value when 'port' $SERVER_PORT = value when 'key' $AUTH_KEY = value when 'ssl' $SSL_ENABLE = true if value == 'on' when 'debug' $DEBUG = true if value == 'on' end end file.close end def write_pid_file open(PID_FILE, "w") { |file| file.write(Process.pid) } end def delete_pid_file if File.exists?(PID_FILE) File.unlink PID_FILE end end end HwDaemonUtil.new

via: http://www.facebooksx.com/centosopenvzopenvzwebpanel.html
This is a very good and practical tutorial, but I’m afraid the blogger will give up, so I’m putting it here.

<<:  Demi Cloud: 199 yuan/year/888MB memory/50GB space/200GB traffic/KVM/Guizhou

>>:  WootHosting: $11/year/500GB space/5TB traffic/Los Angeles

Recommend

CrazyDomain domain name discount; info domain name 8 US dollars/10 years

CrazyDomain is a relatively stable merchant, and ...

PeakServers: $10/year/128MB memory/5GB space/100GB bandwidth/KVM/Dallas

PeakServers has launched KVM VPS and now has a fu...

TropiHost: $5.5/month/4GB RAM/100GB storage/1TB bandwidth/OpenVZ

TropiHost, which we have introduced before, is of...

ByteTime: $119/month/E5-2670/96GB memory/1TB SSD hard drive/100TB traffic/5 IP

ByteTime, a seemingly newly established hosting p...

buyshared: $20/year/20GB SSD/1TB traffic/independent IP

buyshared, Buyvm specializes in providing virtual...

LetBox: $5.9/month/2GB memory/1TB space/3TB traffic/KVM/Los Angeles/Dallas

LetBox, which has been introduced many times, now...

NameCheap New Year's Day offer: com registration only $4.88/year

NameCheap does not need much introduction. Domain...

X3host: $25/year/2GB RAM/150GB storage/unlimited traffic/OpenVZ/Phoenix/New York

X3host, an American hosting provider, seems to be...

Komputer King: $35/year/3GB RAM/20GB SSD space/1TB bandwidth/OpenVZ/Los Angeles

Komputer King, an American hosting company, claim...