xplicit / HyperFastCgi

Performant nginx to mono fastcgi server
MIT License
129 stars 48 forks source link

Installation problem (HyperFastCgi from source on FreeBSD 10.2) #45

Closed pavel-l-kirichenko closed 8 years ago

pavel-l-kirichenko commented 8 years ago
git clone https://github.com/xplicit/HyperFastCgi.git

Установил gcc (во FreeBSD системный компилятор Clang):

cd /usr/ports/lang/gcc5/
make config install clean

Сделал алиас gcc:

cd /usr/local/bin/gcc
gcc-ar5*     gcc-nm5*     gcc-ranlib5* gcc5*        
ln -s gcc5 gcc

Запустил скрипт:

cd ./HyperFastCgi/
./autogen.sh --prefix=/usr
Running libtoolize ...
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'build/m4'.
libtoolize: copying file 'build/m4/libtool.m4'
libtoolize: copying file 'build/m4/ltoptions.m4'
libtoolize: copying file 'build/m4/ltsugar.m4'
libtoolize: copying file 'build/m4/ltversion.m4'
libtoolize: copying file 'build/m4/lt~obsolete.m4'
libtoolize: Consider adding '-I build/m4' to ACLOCAL_AMFLAGS in Makefile.am.
Running aclocal -I .  -I build/m4/shamrock -I build/m4/shave ...
Running automake --gnu  ...
configure.ac:25: installing './compile'
configure.ac:7: installing './missing'
src/libnative/Makefile.am: installing './depcomp'
Running autoconf ...
Running ./configure --prefix=/usr ...
checking build system type... amd64-unknown-freebsd10.2
checking host system type... amd64-unknown-freebsd10.2
checking target system type... amd64-unknown-freebsd10.2
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... nawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... yes
checking whether make supports nested variables... (cached) yes
checking for pkg-config... /usr/local/bin/pkg-config
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/local/bin/ld
checking if the linker (/usr/local/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking how to convert amd64-unknown-freebsd10.2 file names to amd64-unknown-freebsd10.2     format... func_convert_file_noop
checking how to convert amd64-unknown-freebsd10.2 file names to toolchain format... func_convert_file_noop
checking for /usr/local/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/local/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... freebsd10.2 ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking pkg-config is at least version 0.9.0... yes
checking for GLIB... yes
checking for LIBEVENT... yes
checking for LIBEVENT_PTHREADS... yes
checking for MONO_MODULE... yes
checking for gmcs... no
checking for dmcs... /usr/local/bin/dmcs
checking for mono... /usr/local/bin/mono
checking for gacutil... /usr/local/bin/gacutil
checking for sn... /usr/local/bin/sn
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating build/Makefile
config.status: creating build/m4/Makefile
config.status: creating build/m4/shave/shave
config.status: creating build/m4/shave/shave-libtool
config.status: creating src/Makefile
config.status: creating src/HyperFastCgi/Makefile
config.status: creating src/HyperFastCgi/scripts/Makefile
config.status: creating src/libnative/Makefile
config.status: creating samples/Makefile
config.status: creating src/HyperFastCgi/scripts/hyperfastcgi4
config.status: executing depfiles commands
config.status: executing libtool commands

hyperfastcgi-0.4

  Build Environment
    Install prefix:          /usr
    Datadir:                 /usr/share
    Libdir:                  /usr/lib
    Build documentation:     
    Mono 2.0 compiler:       not found
    Mono 4.0 compiler:       /usr/local/bin/dmcs
    Target frameworks:       .NET 4.0

Тут начинаются проблемы:

make
Making all in src
Making all in HyperFastCgi
make[2]: "/root/HyperFastCgi/src/HyperFastCgi/Makefile" line 877: Need an operator
make[2]: "/root/HyperFastCgi/src/HyperFastCgi/Makefile" line 882: Need an operator
make[2]: "/root/HyperFastCgi/src/HyperFastCgi/Makefile" line 884: Need an operator
make[2]: Fatal errors encountered -- cannot continue
make[2]: stopped in /root/HyperFastCgi/src/HyperFastCgi
*** Error code 1

Stop.
make[1]: stopped in /root/HyperFastCgi/src
*** Error code 1

Stop.
make: stopped in /root/HyperFastCgi
xplicit commented 8 years ago

Чтобы откомпилировалось во freebsd надо в файл /src/libnative/socket-helper.c

добавить следующие includes:

#include <netinet/in.h>
#include <string.h>

после чего использовать gmake вместо make.

pavel-l-kirichenko commented 8 years ago

Спасибо! Поправил, установил:

root@rat-3o3r3d3:~ # hyperfastcgi4 --help
HyperFastCgi.exe 0.4.4.0
(c) Sergey Zhukov
…

Но дальше затык.

Версии софта:

root@rat-3o3r3d3:~ # mono --version
Mono JIT compiler version 4.2.1 (Stable 4.2.1.124/39edf24 Tue Dec 22 15:13:39 UTC 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notification:  kqueue
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            sgen
root@rat-3o3r3d3:~ # nginx -v
nginx version: nginx/1.8.0 

Отредактировал файл server.config:

<configuration>
    <server type="HyperFastCgi.ApplicationServers.SimpleApplicationServer">
        <!-- Host factory defines how host will be created. SystemWebHostFactory creates host in AppDomain in standard ASP.NET way --> 
        <host-factory>HyperFastCgi.HostFactories.SystemWebHostFactory</host-factory>
        <!-- <threads> creates threads at startup. Value "0" means default value --> 
        <threads min-worker="40" max-worker="0" min-io="4" max-io="0" />
        <!--- Sets the application host root directory -->
        <!-- <root-dir>/usr/local/www/nginx</root-dir> -->
    </server>
    <listener type="HyperFastCgi.Listeners.NativeListener">
        <apphost-transport type="HyperFastCgi.Transports.NativeTransport">
            <multithreading>Single</multithreading>
        </apphost-transport>
        <protocol>InterNetwork</protocol>
        <address>127.0.0.1</address>
        <port>9000</port>
    </listener>
    <apphost type="HyperFastCgi.AppHosts.AspNet.AspNetApplicationHost">
        <log level="Debug" write-to-console="true" />
        <add-trailing-slash>false</add-trailing-slash>
    </apphost>
    <web-applications>
        <web-application>
            <name>ApplicationServer</name>
            <vhost>a1.ratord.ru</vhost>
            <vport>443</vport>
            <vpath>/</vpath>
            <path>/usr/local/www/nginx/a1.ratord.ru</path>
        </web-application>
        <web-application>
            <name>MainApplicationServer</name>
            <vhost>ma1.ratord.ru</vhost>
            <vport>443</vport>
            <vpath>/</vpath>
            <path>/usr/local/www/nginx/ma1.ratord.ru</path>
        </web-application>
    </web-applications>
</configuration>

Запускаю hyperfastcgi4, и начинаются проблемы:

root@rat-3o3r3d3:~ # hyperfastcgi4 /config=/root/HyperFastCgi/samples/server.config /loglevels=All /printlog
[2015-12-25 18:48:35Z] Debug   HyperFastCgi
[2015-12-25 18:48:35Z] Debug   Threadpool minw=40,minio=4,maxw=400,maxio=400
[2015-12-25 18:48:35Z] Debug   Root directory: /root
[2015-12-25 18:48:36Z] Error   Can't create host System.IO.FileNotFoundException: Could not load file or assembly 'HyperFastCgi, Version=0.4.4.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies
File name: 'HyperFastCgi, Version=0.4.4.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
  at (wrapper xdomain-invoke) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at (wrapper remoting-invoke-with-check) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at System.Web.Hosting.ApplicationHost.CreateApplicationHost (System.Type hostType, System.String virtualDir, System.String physicalDir) <0x186b70 + 0x00c20> in <filename unknown>:0 
  at HyperFastCgi.HostFactories.SystemWebHostFactory.CreateApplicationHost (System.Type appHostType, System.String vhost, Int32 vport, System.String vpath, System.String path) <0x185d10 + 0x00035> in <filename unknown>:0 
  at HyperFastCgi.ApplicationServers.SimpleApplicationServer.CreateAppHost (System.Type appHostType, System.Object appHostConfig, HyperFastCgi.Configuration.WebAppConfig appConfig, IListenerTransport listenerTransport, System.Type appHostTransportType, System.Object appHostTransportConfig) <0x185800 + 0x000a3> in <filename unknown>:0 
[2015-12-25 18:48:36Z] Error   Can't create host System.IO.FileNotFoundException: Could not load file or assembly 'HyperFastCgi, Version=0.4.4.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies
File name: 'HyperFastCgi, Version=0.4.4.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
  at (wrapper xdomain-invoke) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at (wrapper remoting-invoke-with-check) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at System.Web.Hosting.ApplicationHost.CreateApplicationHost (System.Type hostType, System.String virtualDir, System.String physicalDir) <0x186b70 + 0x00c20> in <filename unknown>:0 
  at HyperFastCgi.HostFactories.SystemWebHostFactory.CreateApplicationHost (System.Type appHostType, System.String vhost, Int32 vport, System.String vpath, System.String path) <0x185d10 + 0x00035> in <filename unknown>:0 
  at HyperFastCgi.ApplicationServers.SimpleApplicationServer.CreateAppHost (System.Type appHostType, System.Object appHostConfig, HyperFastCgi.Configuration.WebAppConfig appConfig, IListenerTransport listenerTransport, System.Type appHostTransportType, System.Object appHostTransportConfig) <0x185800 + 0x000a3> in <filename unknown>:0 
[2015-12-25 18:48:36Z] Debug   Listening on port: 9000
[2015-12-25 18:48:36Z] Debug   Listening on address: 127.0.0.1
libev.c:461: Listen():  libevent version: 2.0.22-stable
libev.c:475: Listen():  libevent is using kqueue for events.

Настроил сайт nginx'а:

upstream fastcgi_backend {
  #server unix:/tmp/my-web-app.socket;
  server 127.0.0.1:9000;
  keepalive 32;
}

# HTTP server
server {
        listen   80;
        listen [::]:80;

        server_name  a1.ratord.ru www.a1.ratord.ru;
        access_log   /var/log/nginx/a1.ratord.ru.access.log;

        # Перенаправление на https
        rewrite ^ https://a1.ratord.ru$request_uri? permanent; #301-redirect
}

# HTTPS server
server {

        listen 443 ssl spdy;

        server_name  a1.ratord.ru www.a1.ratord.ru;
        access_log   /var/log/nginx/a1.ratord.ru.access.log;

    location / {
        root /usr/local/www/nginx/a1.ratord.ru/;
        index login.aspx;
        fastcgi_index login.aspx;
        fastcgi_keep_conn on;
        fastcgi_pass fastcgi_backend;
        include /usr/local/etc/nginx/fastcgi_params;
    }

    … (настройки ssl, не привожу, чтобы не засорять эфир)

}

При попытке зайти на сайт в логе hyperfastcgi4 получаю:

fcgi-transport.c:394: parse_params():   Can't find app! HOST='a1.ratord.ru' port=443 path='/login.aspx'

P.S. Читал документацию внимательно, но так и не понял отличия в конфигурационном файле server.config элементов root-dir и path. Это одно и то же?

xplicit commented 8 years ago

Во freebsd в отличии от Ubuntu, все устанавливается в /usr/local, а не в /usr, поэтому при вызове autogen.sh, нужно использовать префикс /usr/local.

./autogen.sh --prefix=/usr/local
gmake
gmake install

root-dir и path - разные вещи, в #22 можно более детально почитать, как используется root-dir

pavel-l-kirichenko commented 8 years ago

Сергей, огромное спасибо. Всё работает. По сравнению с xsp (раньше использовали) — hyperfastcgi4 летает.

Предложение: могу в вики проекта написать страничку по установке и настройке hyperfastcgi4 на FreeBSD.

xplicit commented 8 years ago

Было бы здорово, если бы в wiki появилось описание шагов для установки на FreeBSD. (Про правку headers в socket-helper.c там можно не писать, я сделаю патч для build script, который решит эту проблему)

pavel-l-kirichenko commented 8 years ago

Страничку создал. Правда, английский у меня пока не самый лучший, но я старался :)