Home Database Mysql Tutorial Running your own CloudFoundry based on your IaaS. Part 2

Running your own CloudFoundry based on your IaaS. Part 2

Jun 07, 2016 pm 03:20 PM
running your

(接着Part 1的工作) Step.3 Configure the new VM created by Template 当安装单节点CloudFoundry完成之后,我们就可以用vmc来测试下组件启动是否正常。测试之后,我们就可以使用IaaS的Template功能,把这个安装了完整CloudFoundry的虚拟机做成一个模板,

(接着Part 1的工作)


Step.3 Configure the new VM created by Template

当安装单节点CloudFoundry完成之后,我们就可以用vmc来测试下组件启动是否正常。测试之后,我们就可以使用IaaS的Template功能,把这个安装了完整CloudFoundry的虚拟机做成一个模板,留到做集群的时候使用。这一步,你完全可以使用自己喜爱的IaaS来做这件事情,比如CloudStack, Openstack, Amazon EC2之类的。这里我以CloudStack为例子。

1、给这个模板虚拟机的ROOT Volume做一个快照snapshot。(或者关机,再直接给这个VM做个Template)

2、然后基于snapshot创建模板

3、接下来就可以使用这个快照创建新VM了。这里的配置我使用的是2G内存 20G硬盘。


但是,这个新创建的虚拟机里的CF是直接启动不起来的。因为IP已经变了。我们需要配置一下。

这里我写了一个脚本,负责把虚拟机里关于CF配置中的IP部分改成新的虚拟机IP,并且重启关键的postgresql服务。(也跟IP相关)

echo -e "\033[32m================== Reconfiguring the CloudFoundry now ===================\n \033[0m"

localip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`

grep 172.17.4.221 -rl /root/cloudfoundry/.deployments/devbox/config

if [ $? -ne 0 ]; then
 
    echo -e "Nothing need to be done here \n"

else
    sed -i "s/172.17.4.221/${localip}/g" `grep 172.17.4.221 -rl /root/cloudfoundry/.deployments/devbox/config`
    echo -e "\033[33m\nThe IP address of this CloudFoundry node has been set to ${localip} \033[0m\n"

fi

grep 172.17.4.221 -rl /etc/postgresql

if [ $? -ne 0  ]; then
    echo -e "Nothing need to be done here \n"

else
  
    sed -i "s/172.17.4.221/${localip}/g" `grep 172.17.4.221 -rl /etc/postgresql`
    echo -e "\033[33m\nThe IP address of postgresql node has been set to ${localip} \033[0m\n"

fi


echo -e "\033[34mRestarting PostgreSQL ...\n\033[0m"

/etc/init.d/postgresql-8.4 stop
/etc/init.d/postgresql-8.4 start

/etc/init.d/postgresql stop
/etc/init.d/postgresql start

echo -e "\033[32m\nReconfiguration successed!\n\033[0m"
echo -e "\033[32m\nYou can use export CLOUD_FOUNDRY_EXCLUDED_COMPONENT=\"comp1|comp2|...\" to choose services\n\033[0m"
Copy after login



172.17.4.221就是模板VM的IP。这个脚本非常简单,所以功能有限:

1、grep抓取本机IP信息的那句对于多个网卡(或者安装过VMPlayer之类的)的VM会有问题

2、CloudFoundry路径是写死的

所以,诸位大牛自己可以写一份更好的。


Step4. Configure and connect the VMs together

修改过IP之后,一个新的完整功能的CF节点就可以工作了。CloudFoundry设计非常简洁,模块间耦合度很低,天生就是用来搭建集群的。所以我们接下来的工作很简单:只要分别启动这些VM上所需的组件,并且用NATS把它们连起来即可!

这是我们最简单的一个的多节点部署方案:


node0: LoadBalancer(Nginx)
node1: CC, uaa, router0
node2: dea 0, mysql_node0
node3: dea 1, mysql_node1
node4: NATS, HM
node5: router1,mysql_gateway

这其实就是一个multi-router, multi-dea and multi-mysql的部署而已。

好了,把这些节点一个个克隆出来,然后做下面的简单工作:

1、login到每个VM中,比如node1

2、找到./devbox/config/cloud_controller.yml中nats://nats:nats@172.17.4.219:4222

3、修改该IP为node4的IP,

4、对其它的node做这项工作,然后启动该节点上需要的那几个组件即可(../vcap_dev start xxx xxx ...)

需要特殊处理的情况:

1、HM和CC需要共享数据库,所以如果你的HM是在独立的节点上,把这个IP改成你CC的IP


# This database is shared with the cloud controller.
database_environment:
  production:
    database: cloud_controller
    host: 172.17.13.86
Copy after login


另外,把CC的external_url改为api.yourdomain.com。需要注意的是,CF所有组件配置文件中诸如*.vcap.me这样的url都要改,所以需要每个组件都查看一下config。

(这里的*.yourdomain.com域名最终会被绑定到LB上,后面很快有说明)

2、多个Service节点的情况,别忘了给他们编号(index)


index: 1
pid: /var/vcap/sys/run/mysql_node.pid
node_id: mysql_node_1
#CloudFoundry need this index to distinguish those mysql nodes.
Copy after login

3、在NATS节点上需要单独启动NATS服务

/etc/init.d/nats-server   start


4、Multi-routers:这里我们的策略是用一个Nginx在多个Router前负责分配流量,Nginx节点是独立的,他的配置文件需要这么写:


 upstream cf_routers {
    server ip_of_router_0;
    server ip_of_router_1;
  }

  server {
    listen       80;
   
# if you do not have a domain, try to use your hosts file.
    server_name  *.yourdomain.com
    server_name_in_redirect off;
    location / {
      access_log   /root/cloudfoundry/.deployments/devbox/log/nginx_access.log main;
      proxy_buffering             off;
      proxy_set_header            Host $host;
      proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_redirect              off;
      proxy_connect_timeout       10;
      proxy_send_timeout          30;
      proxy_read_timeout          30;

      proxy_pass                 http://cf_routers;
    }
  }

别忘了配置完之后重启一下:/etc/init.d/nginx restart

最后,在你的IaaS层的网络功能里把*.yourdomain.com绑定到这个LB上就可以了,以后target这个domain就可以使用你的集群环境。


Step 5. Other things TODO


截止到这里,你的集群搭建工作其实已经完成了。不过,还有些后续的东西可以做。


首先,这里的CC和HM是单节点的。如果要做成多节点怎么办?其实,这几个节点需要共享如下两个目录:

droplets: /var/vcap/shared/droplets

resources: /var/vcap/shared/resources

所以,我们需要做一个NFS的server,然后几个CC节点都从这个server上mount如上两个目录的文件到它们本地的存储中。这里NFS是原生的,其实你可以替换成支持FUSE的其他文件系统,CF是支持这部分的修改的。

当然,别忘了多个CC对应的是同一个external_url,即api.yourdomain.com,所以别忘了修改CC各自的配置文件。

这时,你对CF的target请求按照如下流程走:

vmc target api.yourdomain.com -> LB -> LB选择某一个Router -> Router选择某一个CloudController


其次,多个CC&HM节点之间还需要共享一个跨node的数据库(从CC&HM的配置文件可以看到这个数据库的配置),然后在上述配置文件中连接CC&HM到这个数据库的master节点上。


顺便说一句,我们的工作其实是在无意中模仿了BOSH。我们实验室在模板VM中建立并启动了一个Http Sever,负责接收Client端的任务请求。这其实也是类似于agent的工作。不过跟BOSH相比,我们的这种部署方法也只是半自动的。只不过,我们实验室用的IaaS不止CloudStack,所以做很多套BOSH CPI目前来看还不太需要。大家可以参考CLoudFoundry官方提供的资料来学习BOSH。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL: From Small Businesses to Large Enterprises MySQL: From Small Businesses to Large Enterprises Apr 13, 2025 am 12:17 AM

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

How does MySQL index cardinality affect query performance? How does MySQL index cardinality affect query performance? Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

See all articles