puppet 3+Unicorn+Nginx安装配置

运维 系统运维
Unicorn 效率要比 Webrick 高很多,所以决定要用Unicorn 替换 Webrick……

puppet server 安装

  1. rpm -ivh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-6.noarch.rpm  
  2. yum install puppet-server -y 

puppet server puppet.conf 配置:

  1. cat /etc/puppet/puppet.conf  
  2. [main]  
  3. # The Puppet log directory.  
  4. # The default value is '$vardir/log'.  
  5. logdir = /var/log/puppet  
  6. # Where Puppet PID files are kept.  
  7. # The default value is '$vardir/run'.  
  8. rundir = /var/run/puppet  
  9. # Where SSL certificates are kept.  
  10. # The default value is '$confdir/ssl'.  
  11. ssldir = $vardir/ssl  
  12. autosign = $confdir/autosign.conf { mode = 664 }  
  13. [agent]  
  14. # The file in which puppetd stores a list of the classes  
  15. # associated with the retrieved configuratiion. Can be loaded in  
  16. # the separate ``puppet`` executable using the ``--loadclasses``  
  17. # option.  
  18. # The default value is '$confdir/classes.txt'.  
  19. classfile = $vardir/classes.txt  
  20. # Where puppetd caches the local configuration. An  
  21. # extension indicating the cache format is added automatically.  
  22. # The default value is '$confdir/localconfig'.  
  23. localconfig = $vardir/localconfig  
  24. [development]  
  25. modulepath = /etc/puppet/modules:/usr/share/puppet/modules  
  26. config_version =  
  27. [production]  
  28. modulepath = /etc/puppet/modules:/usr/share/puppet/modules  
  29. config_version = 

Unicorn 安装配置

  1. yum install ruby-devel make gcc  
  2. gem install unicorn rack  
  3. cp /usr/share/puppet/ext/rack/config.ru /etc/puppet/  
  4. vi /etc/puppet/unicorn.conf  
  5. worker_processes 8  
  6. working_directory "/etc/puppet"  
  7. listen '/var/run/puppet/puppetmaster_unicorn.sock', :backlog => 512  
  8. timeout 120  
  9. pid "/var/run/puppet/puppetmaster_unicorn.pid"  
  10. preload_app true  
  11. if GC.respond_to?(:copy_on_write_friendly=)  
  12. GC.copy_on_write_friendly = true 
  13. end  
  14. before_fork do |server, worker|  
  15. old_pid = "#{server.config[:pid]}.oldbin" 
  16. if File.exists?(old_pid); server.pid != old_pid  
  17. begin  
  18. Process.kill("QUIT", File.read(old_pid).to_i)  
  19. rescue Errno::ENOENT, Errno::ESRCH  
  20. # someone else did our job for us  
  21. end  
  22. end  
  23. end 

调试:

  1. unicorn -c /etc/puppet/unicorn.conf  
  2. I, [2014-08-15T08:55:36.452577 #9031] INFO -- : Refreshing Gem list  
  3. I, [2014-08-15T08:55:38.779972 #9031] INFO -- : unlinking existing socket=/var/run/puppet/puppetmaster_unicorn.sock  
  4. I, [2014-08-15T08:55:38.780441 #9031] INFO -- : listening on addr=/var/run/puppet/puppetmaster_unicorn.sock fd=6 
  5. I, [2014-08-15T08:55:38.787469 #9059] INFO -- : worker=0 spawned pid=9059 
  6. I, [2014-08-15T08:55:38.790368 #9059] INFO -- : worker=0 ready  
  7. I, [2014-08-15T08:55:38.792410 #9060] INFO -- : worker=1 spawned pid=9060 
  8. I, [2014-08-15T08:55:38.795405 #9060] INFO -- : worker=1 ready  
  9. I, [2014-08-15T08:55:38.796387 #9061] INFO -- : worker=2 spawned pid=9061 
  10. I, [2014-08-15T08:55:38.799071 #9061] INFO -- : worker=2 ready  
  11. I, [2014-08-15T08:55:38.801353 #9062] INFO -- : worker=3 spawned pid=9062 
  12. I, [2014-08-15T08:55:38.804052 #9062] INFO -- : worker=3 ready  
  13. I, [2014-08-15T08:55:38.805570 #9063] INFO -- : worker=4 spawned pid=9063 
  14. I, [2014-08-15T08:55:38.808220 #9063] INFO -- : worker=4 ready  
  15. I, [2014-08-15T08:55:38.810281 #9064] INFO -- : worker=5 spawned pid=9064 
  16. I, [2014-08-15T08:55:38.812904 #9064] INFO -- : worker=5 ready  
  17. I, [2014-08-15T08:55:38.814869 #9065] INFO -- : worker=6 spawned pid=9065 
  18. I, [2014-08-15T08:55:38.817497 #9065] INFO -- : worker=6 ready  
  19. I, [2014-08-15T08:55:38.817731 #9031] INFO -- : master process ready  
  20. I, [2014-08-15T08:55:38.819580 #9066] INFO -- : worker=7 spawned pid=9066 
  21. I, [2014-08-15T08:55:38.822096 #9066] INFO -- : worker=7 ready 

按ctrl+c结束

编写启动脚本

  1. vi /etc/init.d/puppet-unicorn  
  2. #!/bin/bash  
  3. # unicorn-puppet  
  4. # chkconfig: - 98 02  
  5. #  
  6. # description: Enables periodic system configuration checks through unicorn-puppet.  
  7. # processname: unicorn-puppet  
  8. # Source function library.  
  9. . /etc/rc.d/init.d/functions  
  10. lockfile=/var/lock/puppetmaster-unicorn  
  11. pidfile=/var/run/puppet/puppetmaster_unicorn.pid  
  12. RETVAL=0 
  13. DAEMON=/usr/bin/unicorn  
  14. DAEMON_OPTS="-D -c /etc/puppet/unicorn.conf" 
  15. start() {  
  16. echo -n $"Starting puppet unicorn: "  
  17. daemon $DAEMON $DAEMON_OPTS  
  18. RETVAL=$?  
  19. echo  
  20. [ $RETVAL = 0 ] && touch ${lockfile}  
  21. return $RETVAL  
  22. }  
  23. stop() {  
  24. echo -n $"Stopping puppet unicorn: "  
  25. kill `cat $pidfile`  
  26. RETVAL=$?  
  27. [ $RETVAL -eq 0 ] && rm -f {$lockfile} {$pidfile}  
  28. [ $RETVAL -eq 0 ] && echo_success || echo_failure  
  29. echo  
  30. return $RETVAL  
  31. }  
  32. restart() {  
  33. stop  
  34. start  
  35. }  
  36. usage() {  
  37. echo "Usage: $0 {start|stop|restart}" ;  
  38. return 3  
  39. }  
  40. case "$1" in  
  41. start)  
  42. start  
  43. ;;  
  44. stop)  
  45. stop  
  46. ;;  
  47. restart)  
  48. restart  
  49. ;;  
  50. *)  
  51. usage  
  52. ;;  
  53. esac  
  54. exit $RETVAL 
  1. chmod +x /etc/init.d/puppet-unicorn  
  2. chkconfig puppet-unicorn on 

配置nginx

  1. vi /etc/nginx/conf.d/puppets-unicorn  
  2. upstream puppetmaster_unicorn {  
  3. server unix:/var/run/puppet/puppetmaster_unicorn.sock fail_timeout=0;  
  4. }  
  5. server {  
  6. listen 8140;  
  7. ssl on;  
  8. ssl_session_timeout 5m;  
  9. ssl_certificate /var/lib/puppet/ssl/certs/puppet.test.com.pem;  
  10. ssl_certificate_key /var/lib/puppet/ssl/private_keys/puppet.test.com.pem;  
  11. ssl_client_certificate /var/lib/puppet/ssl/ca/ca_crt.pem;  
  12. ssl_ciphers SSLv2:-LOW:-EXPORT:RC4+RSA;  
  13. ssl_verify_client optional;  
  14. root /usr/share/empty;  
  15. proxy_set_header Host $host;  
  16. proxy_set_header X-Real-IP $remote_addr;  
  17. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  18. proxy_set_header X-Client-Verify $ssl_client_verify;  
  19. proxy_set_header X-Client-DN $ssl_client_s_dn;  
  20. proxy_set_header X-SSL-Issuer $ssl_client_i_dn;  
  21. proxy_read_timeout 120;  
  22. location / {  
  23. proxy_pass http://puppetmaster_unicorn;  
  24. proxy_redirect off;  
  25. }  
  26. }  
  27. /etc/init.d/nginx start  
  28. chkconfig nginx on 

参考网址:

https://linuxmoz.com/rhel-centos-install-puppet-nginx-unicorn/

http://projects.puppetlabs.com/projects/1/wiki/using_unicorn

原文链接:http://my.oschina.net/u/142602/blog/301400

责任编辑:牛小雨 来源: 酒瓶不倒的博客
相关推荐

2010-02-06 14:00:05

Linux Nginx

2012-06-19 15:51:22

集群系列2

2011-04-02 14:21:46

MRTG安装

2011-03-02 10:41:41

Vsftpd安装

2011-04-01 15:00:35

2011-02-23 10:43:17

2011-02-25 17:48:52

2010-06-07 11:22:28

2011-03-30 15:05:40

MRTG安装

2011-03-25 15:01:44

Cacti安装

2011-11-08 21:55:58

MRTG 配置

2011-02-25 17:19:09

Pureftpd安装

2011-04-02 15:26:51

Cacti安装

2011-03-11 16:42:38

Ubuntu安装LAMP

2011-03-25 13:40:28

Cacti安装配置

2013-11-28 09:44:00

2012-09-04 14:52:28

Puppet

2011-04-02 15:26:58

Cacti安装

2011-04-02 15:17:59

2009-07-17 17:34:15

JRuby On Ra
点赞
收藏

51CTO技术栈公众号