随笔-179  评论-666  文章-29  trackbacks-0
  2018年3月8日
一、准备 正式开始前,编译环境gcc、g++等开发库需要提前安装。
nginx依赖以下模块: gzip模块需要 zlib 库 rewrite模块需要 pcre 库 ssl 功能需要openssl库
源码目录为:/usr/local/src
1、安装make yum -y install gcc automake autoconf libtool make
2、安装g++ yum install gcc gcc-c++
3、安装PCRE库 cd /usr/local/src wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz tar -zxvf pcre-8.42.tar.gz cd pcre-8.42/ ./configure make && make install 出现如下报错: make[2]: *** [install-libLTLIBRARIES] Error 1 make[2]: Leaving directory `/usr/local/src/pcre-8.42' make[1]: *** [install-am] Error 2 make[1]: Leaving directory `/usr/local/src/pcre-8.42' make: *** [install] Error 2 权限不够,切换到root,重新make install即可。
4、安装zlib库 cd /usr/local/src wget http://zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11/ ./configure make && make install
5、安装OpenSSL库 cd /usr/local/src wget http://www.openssl.org/source/openssl-1.1.0h.tar.gz tar -zxvf openssl-fips-2.0.16.tar.gz cd openssl-fips-2.0.16/ ./config make && make install 编译安装 Openssl 1.1.1 支持国密标准 https://blog.51cto.com/1012682/2380553 6、创建用户及用户组 一般为了服务器安全,会指定一个普通用户权限的账号做为Nginx的运行角色,这里使用www用户做为Nginx工作进程的用户。后续安装的PHP也以www用户作为工作进程用户。 groupadd -r www useradd -r -g www www 二、NGINX 1、下载 cd /usr/local/src wget http://nginx.org/download/nginx-1.14.0.tar.gz tar –zxvf nginx-1.14.0.tar.gz cd nginx-1.14.0 2、配置 ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi make && make install nginx编译选项说明: --prefix表示nginx要安装到哪个路径下,这里指定刚才新建好的/alidata/server目录下的nginx-1.12.2; --sbin-path表示nginx的可执行文件存放路径 --conf-path表示nginx的主配置文件存放路径,nginx允许使用不同的配置文件启动,通过命令行中的-c选项 --pid-path表示nginx.pid文件的存放路径,将存储的主进程的进程号。安装完成后,可以随时改变的文件名 , 在nginx.conf配置文件中使用 PID指令。默认情况下,文件名 为prefix/logs/nginx.pid --error-log-path表示nginx的主错误、警告、和诊断文件存放路径 --http-log-path表示nginx的主请求的HTTP服务器的日志文件的存放路径 --user表示nginx工作进程的用户 --group表示nginx工作进程的用户组 --with-select_module或--without-select_module表示启用或禁用构建一个模块来允许服务器使用select()方法 --with-poll_module或--without-poll_module表示启用或禁用构建一个模块来允许服务器使用poll()方法 --with-http_ssl_module表示使用https协议模块。默认情况下,该模块没有被构建。建立并运行此模块的OpenSSL库是必需的 --with-pcre表示pcre的源码路径,因为解压后的pcre是放在root目录下的,所以是/root/pcre-8.41; --with-zlib表示zlib的源码路径,这里因为解压后的zlib是放在root目录下的,所以是/root/zlib-1.2.11 --with-openssl表示openssl库的源码路径 配置OK: Configuration summary + using PCRE library: /usr/local/src/pcre-8.42 + using OpenSSL library: /usr/local/src/openssl-1.1.0h + using zlib library: /usr/local/src/zlib-1.2.11 nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx" nginx configuration file: "/usr/local/nginx/nginx.conf" nginx pid file: "/usr/local/nginx/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "/var/tmp/nginx/client/" nginx http proxy temporary files: "/var/tmp/nginx/proxy/" nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/" nginx http uwsgi temporary files: "/var/tmp/nginx/uwsgi" nginx http scgi temporary files: "/var/tmp/nginx/scgi" 3、安装 make && make install 4、启动 /usr/local/nginx/sbin/nginx 启动时报错: nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory) 手动创建该目录即可:mkdir -p /var/tmp/nginx/client 再次启动,打开浏览器访问此机器的IP,浏览器出现Welcome to nginx! 则表示 Nginx 已经安装并运行成功。
5、设置软连接 ln -sf /usr/local/nginx/sbin/nginx /usr/sbin 这样就可以直接执行nginx来启动了。
6、检测nginx nginx -t 显示: nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/nginx.conf test is successful 三、PHP 1、安装PHP需要的常用库 yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel 2、下载 cd /usr/local/src wget http://cn2.php.net/downloads.php/php-7.2.5.tar.gz tar -zxvf php-7.2.5.tar.gz 3、配置 ./configure --prefix=/usr/local/php \ --with-mysql=mysqlnd \ --enable-mysqlnd \ --with-gd \ --enable-gd-jis-conv \ --enable-fpm 4、安装 make && make install 安装信息如下: Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/ Installing PHP CLI binary: /usr/local/php/bin/ Installing PHP CLI man page: /usr/local/php/php/man/man1/ Installing PHP FPM binary: /usr/local/php/sbin/ Installing PHP FPM defconfig: /usr/local/php/etc/ Installing PHP FPM man page: /usr/local/php/php/man/man8/ Installing PHP FPM status page: /usr/local/php/php/php/fpm/ Installing phpdbg binary: /usr/local/php/bin/ Installing phpdbg man page: /usr/local/php/php/man/man1/ Installing PHP CGI binary: /usr/local/php/bin/ Installing PHP CGI man page: /usr/local/php/php/man/man1/ Installing build environment: /usr/local/php/lib/php/build/ Installing header files: /usr/local/php/include/php/ Installing helper programs: /usr/local/php/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php/lib/php/ [PEAR] Archive_Tar: upgrade to a newer version (1.4.3 is not newer than 1.4.3) [PEAR] Console_Getopt: upgrade to a newer version (1.4.1 is not newer than 1.4.1) [PEAR] Structures_Graph: upgrade to a newer version (1.1.1 is not newer than 1.1.1) [PEAR] XML_Util: upgrade to a newer version (1.4.2 is not newer than 1.4.2) [PEAR] PEAR: upgrade to a newer version (1.10.5 is not newer than 1.10.5) /usr/local/src/php-7.2.5/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin ln -s -f phar.phar /usr/local/php/bin/phar Installing PDO headers: /usr/local/php/include/php/ext/pdo/ 5、添加环境变量 vim /etc/profile 在末尾加入 export PHP_HOME=/usr/local/php export PATH=/bin:/usr/bin:/usr/sbin:/sbin:$PATH:PHP_HOME/bin:$PHP_HOME/sbin 保存修改后,使用source命令重新加载配置文件: source /etc/profile 查看环境变量: echo $PATH 6、配置php-fpm cd /usr/local/php/etc cp php-fpm.conf.default php-fpm.conf cd php-fpm.d/ cp www.conf.default www.conf 使用vim命令对php-fpm.conf的内容进行如下修改: pid = /usr/local/php/var/run/php-fpm.pid 使用vim命令对php-fpm.conf的内容进行如下修改: user = www group = www 其他配置可根据需求进行修改,比如pm.max_children(php-fpm 能启动的子进程的最大数量)、pm.start_servers(php启动时,开启的子进程的数量)、pm.min_spare_servers(动态方式空闲状态下的最小php-fpm进程数量)、pm.max_spare_servers(动态方式空闲状态下的最大php-fpm进程数量)等。 7、启动php-fpm /usr/local/php/sbin/php-fpm 可以通过ps aux | grep php查看php进程。 https://www.cnblogs.com/sunshineliulu/p/8991957.html 三、MySQL https://blog.csdn.net/weixin_33859844/article/details/90948191 https://www.cnblogs.com/yangchunlong/p/8477743.html
posted @ 2019-08-13 17:37 Alpha 阅读(342) | 评论 (0)编辑 收藏

一、安装git服务器所需软件

打开终端输入以下命令:

ubuntu:~$ sudo apt-get install git-core openssh-server openssh-client
git-core是git版本控制核心软件

安装openssh-server和openssh-client是由于git需要通过ssh协议来在服务器与客户端之间传输文件

然后中间有个确认操作,输入Y后等待系统自动从镜像服务器中下载软件安装,安装完后会回到用户当前目录。如果

安装提示失败,可能是因为系统软件库的索引文件太旧了,先更新一下就可以了,更新命令如下:

ubuntu:~$ sudo apt-get update 

更新完软件库索引后继续执行上面的安装命令即可。

安装python的setuptools和gitosis,由于gitosis的安装需要依赖于python的一些工具,所以我们需要先安装python

的setuptools。

执行下面的命令:

ubuntu:~$ sudo apt-get install python-setuptools
这个工具比较小,安装也比较快,接下来准备安装gitosis,安装gitosis之前需要初始化一下服务器的git用户信息,这个随便填。

ubuntu:~$ git config --global user.name "myname"
ubuntu:~$ git config --global user.email "******@gmail.com"

初始化服务器用户信息后,就可以安装gitosis了,gitosis主要是用于给用户授权,设置权限也算是很方便的。

可以通过以下命令获取gitosis版本文件

ubuntu:~$ git clone https://github.com/res0nat0r/gitosis.git
注意:中间有两个是数字零

获取gitosis文件后,进入到文件目录下面

ubuntu:/tmp$ cd gitosis/

接着使用python命令安装目录下的setup.py的python脚本进行安装

ubuntu:/tmp/gitosis$ sudo python setup.py install

到这里,整个安装步骤就完成了,下面就开始对git进行一些基本的配置。

二、创建git管理员账户、配置git

创建一个账户(git)作为git服务器的管理员,可以管理其他用户的项目权限。

ubuntu:/tmp/gitosis$ sudo useradd -m git
ubuntu:/tmp/gitosis$ sudo passwd git

然后再/home目录下创建一个项目仓库存储点,并设置只有git用户拥有所有权限,其他用户没有任何权限。

ubuntu:/tmp/gitosis$ sudo mkdir /home/gitrepository
ubuntu:/tmp/gitosis$ sudo chown git:git /home/gitrepository/
ubuntu:/tmp/gitosis$ sudo chmod 700 /home/gitrepository/

由于gitosis默认状态下会将仓库放在用户的repositories目录下,例如git用户的仓库地址默认在/home/git/repositories/目录下,这里我们需要创建一个链接映射。让他指向我们前面创建的专门用于存放项目的仓库目录/home/gitrepository。

ubuntu:/tmp/gitosis$ sudo ln -s /home/gitrepository /home/git/repositories

这里我将在服务器端生成ssh公钥,如果想在其他机器上管理也可以在其他机器上生成一个ssh的公钥。

ubuntu:/home/git$ ssh-keygen -t rsa

这里会提示输入密码,我们不输入直接回车即可。

然后用刚生成公钥id_rsa.pub来对gitosis进行初始化。

向gitosis添加公钥并初始化:

$ cp ~/.ssh/id_rsa.pub /tmp

$ sudo -H -u gitadmin gitosis-init < /tmp/id_rsa.pub

Ubuntu完美搭建Git服务器

出现如上信息说明gitosis已经初始化成功。

gitosis主要是通过gitosis-admin.git仓库来管理一些配置文件的,如用户权限的管理。这里我们需要对其中的一个post-update文件添加可执行的权限。

ubuntu:/home/git$ sudo chmod 755 /home/gitrepository/gitosis-admin.git/hooks/post-update

三、服务器上创建项目仓库

使用git账户在服务器上创建一个目录(mytestproject.git)并初始化成git项目仓库。

ubuntu:/home/git$ su git
$ cd /home/gitrepository
$ mkdir mytestproject.git
$ git init --bare mytestproject.git
$ exit

如果出现以下信息就说明已经成功创建了一个名为mytestproject.git的项目仓库了,新建的这个仓库暂时还是空的,不能被客户端clone,还需要对gitosis进行一些配置操作。

四、使用gitosis管理用户操作项目的权限

首先需要在前面生成ssh公钥(用来初始化gitosis)的机器上将gitosis-admin.git的仓库clone下来。

在客户端机器上新建一个目录用于存放gitosis-admin.git仓库

ubuntu:~$ mkdir gitadmin
ubuntu:~$ cd gitadmin/
ubuntu:~/gitadmin$ git clone git@192.168.1.106:gitosis-admin.git

clone正确会显示以下信息

Ubuntu完美搭建Git服务器

clone下来会有一个gitosis.conf的配置文件和一个keydir的目录。gitosis.conf用于配置用户的权限信息,keydir主要用户存放ssh公钥文件(一般以“用户名.pub”命名,gitosis.conf配置文件中需使用相同用户名),用于认证请求的客户端机器。

现在让需要授权的用户使用前面的方式各自在其自己的机器上生成相应的ssh公钥文件,管理员把他们分别按用户名命名好,复制到keydir目录下。

ubuntu:~$ cp /home/aaaaa/Desktop/zhangsan.pub /home/aaaaa/gitadmin/gitosis-admin/keydir/

ubuntu:~$ cp /home/aaaaa/Desktop/lisi.pub /home/aaaaa/gitadmin/gitosis-admin/keydir/

继续编辑gitosis.conf文件

[gitosis]

[group gitosis-admin] 
####管理员组
members = charn@ubuntu 
####管理员用户名,需要在keydir目录下找到相应的.pub文件,多个可用空格隔开(下同)
writable = gitosis-admin####可写的项目仓库名,多个可用空格隔开(下同)

[group testwrite] 
####可写权限组
members = zhangsan####组用户
writable = mytestproject####可写的项目仓库名

[group
 testread] ####只读权限组
members =lisi####组用户
readonly= mytestproject####只读项目仓库名

因为这些配置的修改只是在本地修改的,还需要推送到服务器中才能生效。

ubuntu:~/gitadmin/gitosis-admin$ git add .
ubuntu:~/gitadmin/gitosis-admin$ git commit -am "add a user permission"
ubuntu:~/gitadmin/gitosis-admin$ git push origin master

推送成功会显示下面提示信息

Ubuntu完美搭建Git服务器

又是后新增的用户不能立即生效,这时候需要重新启动一下sshd服务

ubuntu:~/gitadmin/gitosis-admin$ sudo /etc/init.d/ssh restart

现在,服务端的git就已经安装和配置完成了,接下来就需要有权限的组成员在各自的机器上clone服务器上的相应

项目仓库进行相应的工作了。

五、客户端(windows)使用git

下载安装windows版本的git客户端软件,下载地址:http://msysgit.github.io/

安装完成后右键菜单会出现几个git相关的菜单选项,我们主要使用其中的git
 bash通过命令行来进行操作。

在本地新建一个目录,使用git初始化这个目录,然后再里面新建一个文本文件用于测试,最后关联到git服务器仓库

中的相关项目,最后上传本地版本到服务器。

$ mkdir testgit
$ cd testgit
$ git init
$ echo "this is a test text file,will push to server" > hello.txt
$ git add .
$ git commit -am "init a base version,add a first file for push to server"
$ git remote add origin git@serverip:mytestproject.git
$ git push origin master

这样服务端就创建好了一个mytestproject.git的仓库的基础版本了,现在其他组员只要从服务端进行clone就可以了。

window下面进入到需要克隆的本地目录下面右键选择git bash选项,输入

$ git clone git@serverip:mytestproject.git

就可以把项目clone到本地仓库了。

下面进行简单的修改和提交操作

$ cd mytestproject
$ echo "this is another text file created by other" >another.txt
$ git add .
$ git commit -am "add a another file by other"
$ git push origin master

最后推送到服务器成功会显示如下信息

Ubuntu完美搭建Git服务器


gitolite搭建git仓库(服务端+客户端)

http://blog.csdn.net/ChiChengIT/article/details/49863383

posted @ 2018-03-13 15:35 Alpha 阅读(1112) | 评论 (0)编辑 收藏
     摘要: Git 教程http://www.runoob.com/git/git-tutorial.htmlGit本地服务器搭建及使用Git是一款免费、开源的分布式版本控制系统。众所周知的Github便是基于Git的开源代码库以及版本控制系统,由于其远程托管服务仅对开源免费,所以搭建本地Git服务器也是个较好的选择,本文将对此进行详细讲解。(推荐一家提供私有源代码免费托管的网站:Bitbucket,目前支持...  阅读全文
posted @ 2018-03-08 10:44 Alpha 阅读(3164) | 评论 (0)编辑 收藏