Almalinux9(CentOS9)搭建git服务器 Nginx+fcgi+spawn-fcgi+fcgiwrap+Git

Almalinux9(CentOS9)搭建git服务器 nginx http访问

Nginx+fcgi+spawn-fcgi+fcgiwrap+Git 

先安装依赖

dnf install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel wget -y
dnf -y install fcgi-devel

如果已经安装了git 先卸载 编译安装 才有gitweb

dnf remove git -y

先下载git源码  当前版本v2.38 可以选择最新稳定版

dnf install libcurl-devel curl-devel

cd /usr/local/src/
wget https://github.com/git/git/archive/refs/tags/v2.38.0.tar.gz
tar zxvf v2.38.0.tar.gz
cd git-2.38.0/
make configure
./configure --prefix=/usr/local/git
make
make install

添加git环境变量

echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile
source /etc/profile

查看git是否安装成功

git --version

新版本会报错:git: 'remote-https' is not a git command

echo "export PATH=$PATH:/usr/local/git/libexec/git-core" >> /etc/profile
source /etc/profile

查看用户是否存在

id git
id nginx
useradd git -g git -s /sbin/nologin -M
groupadd git
useradd git -g git -s /sbin/nologin -M

下载spawn-fcgi 并且编译安装spawn-fcgi

cd /usr/local/src/
git clone https://github.com/lighttpd/spawn-fcgi.git
cd spawn-fcgi/
./autogen.sh
./configure
make && make install

下载fcgiwrap 并且编译安装 生成Makefile后编译Makefile文件 删除CFLAGS选项否则报错

-Werror

修改前

CFLAGS = -std=gnu99 -Wall -Wextra -Werror -pedantic -O2 -g3

修改后

CFLAGS = -std=gnu99 -Wall -Wextra  -pedantic -O2 -g3
cd /usr/local/src/
git clone https://github.com/gnosek/fcgiwrap.git
cd fcgiwrap/
autoreconf -i
./configure
make && make install

添加服务 用来启动fcgiwrap.service

cd /etc/systemd/system/
vim fcgiwrap.service
[Unit]
Description=Simple CGI Server
After=nss-user-lookup.target
[Service]

ExecStart = /usr/local/sbin/fcgiwrap -f -s unix:/run/fcgiwrap.socket & 
[Install]
Also=fcgiwrap.socket


vim fcgiwrap.socket
[Unit]
Description=fcgiwrap Socket

[Socket]
ListenStream=/run/fcgiwrap.sock

[Install]
WantedBy=sockets.target

systemctl daemon-reload
systemctl start fcgiwrap.service
systemctl enable fcgiwrap.service

配置gtiweb.conf 添加内容如下

cd /usr/local/git/share/gitweb/
touch gitweb.conf
vim gitweb.conf

# path to git projects (<project>.git)
$projectroot = "/home/git";

# directory to use for temp files
$git_temp = "/tmp";

# target of the home link on top of all pages
$home_link = $my_uri || "/";

# html text to include at home page
$home_text = "indextext.html";

# file with project list; by default, simply scan the projectroot dir.
$projects_list = $projectroot;

# javascript code for gitweb
$javascript = "static/gitweb.js";

# stylesheet to use
$stylesheet = "static/gitweb.css";

# logo to use
$logo = "static/git-logo.png";

# the \'favicon\'
$favicon = "static/git-favicon.png";

安装httpd-tools

dnf -y install httpd-tools

添加用户及密码验证文件 请在要存密码验证文件的目录执行此命令

htpasswd -bc pass.db test 123456

添加nginx的webgit.conf

vim /etc/nginx/conf/nginx.conf

server {
    listen      80;
    server_name localhost;
    root /usr/local/git/share/gitweb;

    client_max_body_size 100m;

    auth_basic "Git User Authentication";
    auth_basic_user_file /etc/nginx/conf/conf.d/pass.db;

    location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
        root /home/git;
    }

    location ~ /.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
        root          /home/git;
        fastcgi_pass  unix:/run/fcgiwrap.socket;
        fastcgi_connect_timeout 24h;
        fastcgi_read_timeout 24h;
        fastcgi_send_timeout 24h;
        fastcgi_param SCRIPT_FILENAME   /usr/local/git/libexec/git-core/git-http-backend;
        fastcgi_param PATH_INFO         $uri;
        fastcgi_param GIT_HTTP_EXPORT_ALL "";
        fastcgi_param GIT_PROJECT_ROOT  /home/git;
        fastcgi_param REMOTE_USER $remote_user;
        include fastcgi_params;
    }

    try_files $uri @gitweb;

    location @gitweb {
        fastcgi_pass  unix:/run/fcgiwrap.socket;
        fastcgi_param GITWEB_CONFIG    /usr/local/git/share/gitweb/gitweb.conf;
        fastcgi_param SCRIPT_FILENAME  /usr/local/git/share/gitweb/gitweb.cgi;
        fastcgi_param PATH_INFO        $uri;
        include fastcgi_params;
    }
}

创建仓库repo.git

git init --bare repo.git
cd repo.git
mv hooks/post-update.sample hooks/post-update
git update-server-info

systemctl restart nginx

浏览器访问此仓库

http://192.168.1.3/repo.git

如果有如下报错:

Can't locate CGI.pm in @INC (you may need to install the CGI module

安装perl cgi

perl -MCPAN -e shell
install CGI::Session

更换好看点的皮肤

cd /usr/local/src
git clone https://github.com/kogakure/gitweb-theme.git
cd gitweb-theme
./setup -vi -t /usr/local/git/share/gitweb/ --install

安装好后就可以开心的撸代码了~。~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 CentOS 7 上安装 Zabbix 6.0、Nginx、MySQL 8、PHP 7.4 的步骤: 1. 安装 EPEL 和 Remi 源: ``` yum install -y epel-release rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm ``` 2. 安装 Nginx: ``` yum install -y nginx systemctl start nginx systemctl enable nginx ``` 3. 安装 PHP 7.4: ``` yum install -y php74-php-fpm php74-php-mysqlnd php74-php-xmlrpc php74-php-gd php74-php-intl php74-php-mbstring php74-php-soap php74-php-xml php74-php-json php74-php-zip systemctl start php74-php-fpm systemctl enable php74-php-fpm ``` 4. 安装 MySQL 8: ``` rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm yum install -y mysql-community-server systemctl start mysqld systemctl enable mysqld ``` 5. 配置 MySQL: ``` mysql_secure_installation ``` 6. 创建 Zabbix 数据库: ``` mysql -u root -p CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin; CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost'; FLUSH PRIVILEGES; EXIT; ``` 7. 导入 Zabbix 数据库: ``` cd /usr/share/doc/zabbix-server-mysql-6.0.0/ zcat create.sql.gz | mysql -u zabbix -p zabbix ``` 8. 安装 Zabbix Server 和 Agent: ``` yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent ``` 9. 配置 Zabbix: ``` vi /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=password ``` 10. 启动 Zabbix Server 和 Agent: ``` systemctl start zabbix-server zabbix-agent systemctl enable zabbix-server zabbix-agent ``` 11. 配置 Nginx: ``` vi /etc/nginx/conf.d/zabbix.conf server { listen 80; server_name localhost; root /usr/share/zabbix; location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_pass unix:/run/php74-php-fpm/zabbix.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` 12. 重启 Nginx: ``` systemctl restart nginx ``` 13. 打开浏览器,输入服务器 IP 地址,进入 Zabbix Web 界面,按照提示进行 Zabbix 配置即可。 注意:以上步骤仅供参考,具体操作根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值