ubuntu server conf

迅800發表於2017-08-04

ubuntu server conf


linux user manager

$sudo adduser newuser

How To Grant a User Sudo Privileges,Search for the line that looks like this
$visudo
->root    ALL=(ALL:ALL) ALL

Below this line, copy the format you see here, changing only the word "root" to reference the new user that you would like to give sudo privileges to:
->root    ALL=(ALL:ALL) ALL
->newuser ALL=(ALL:ALL) ALL

How To Delete a User
#deluser newuser
or
#deluser --remove-home newuser
or
#sudo deluser --remove-home newuser

#visudo

->root    ALL=(ALL:ALL) ALL
->newuser ALL=(ALL:ALL) ALL   # DELETE THIS LINE

Install Nginx, MySQL, PHP (LEMP) Stack On Ubuntu 16.04

Note: Depending on your installation you may need to remove apache2. You can do that by running the commands:
$sudo apt remove apache2*
$sudo apt autoremove

Installing Nginx on Ubuntu 16.04
$sudo apt install nginx
$sudo service nginx start

Installing MySQL on Ubuntu 16.04
#sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty universe'
#sudo apt-get update
#sudo apt install mysql-server-5.6 * see note below if you get an error
#sudo apt install mysql-client-5.6
#sudo mysql_secure_installation
#dpkg -l | grep mysql-server

Installing PHP7 on Ubuntu 16.04
$sudo apt install php7.0 php7.0-fpm php7.0-mysql
$apt install libapache2-mod-php7.0 php7.0 php7.0-fpm php7.0-mysql php7.0-cli php7.0-json php7.0-opcache php7.0-readline php7.0-intl php7.0-xml php7.0-mbstring
$sudo apt-get install curl

$sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old
$sudo nano /etc/nginx/sites-available/default
-->
server {
        listen       80;
        server_name  your_site_name.com;
        root /usr/share/nginx/html;
        index index.php index.html;
        location / {
                try_files $uri $uri/ =404;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /var/www/html;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

$sudo service nginx restart

nginx + fpm conf

server {
 listen 80;
 server_name dev.myproj.com;

 location ~ \.php$ {
 root  /var/www/myproj/www;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;
 }
 location / {
 root  /var/www/myproj/www;
 index  index.php;
 }
}

server
{
listen 80;
server_name local.emp.clcw.com.cn;
index index.php index.html index.htm;
access_log /var/log/nginx/local.emp.clcw.com.cn.log;
root /home/vagrant/www/emp.clcw.com.cn;


location /
{

    if (!-e $request_filename){
        rewrite ^/index.php(.*)$ /index.php?s=$1 last;
        rewrite ^(.*)$ /index.php?s=$1 last;
        break;
    }
}

location ~ .*\.(php|php5)?$
{
    fastcgi_pass 127.0.0.1:9001;
    #fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
         if (-f $request_filename) {
          expires -1s;
          break;
          }
        }

location ~ /\.ht{
    deny all;
}

}

create git repository

Start using Git on the command line

The most common use case for  git init --bare is to create a remote central repository:
$ssh <user>@<host> cd path/above/repo git init --bare my-project.git
or
$git init --bare mautic.git

Initializes a new Git repository and copies files from the  <template_directory> into the repository.
$git init <directory> --template=<template_directory>

$git clone ssh://john@example.com/path/to/my-project.git

Cloning to a specific folder
$git clone <repo> <directory>

Cloning a specific tag
$git clone -branch <tag> <repo>

Shallow clone
$git clone -depth=1 <repo>

clone only the new_feature branch from the remote Git repository.
$git clone -branch new_feature git://remoterepository.git

This means that a repository will be set up with the history of the project that can be pushed and pulled from, but cannot be edited directly.
$git clone --bare

Git URLs, Git has its own URL syntax which is used to pass remote repository locations to Git commands.

Git URL protocols:

-SSH
$ssh://[user@]host.xz[:port]/path/to/repo.git/
$git clone ssh://coober@192.168.0.62/var/workspace/git_respository/mautic.git

-GIT
$git://host.xz[:port]/path/to/repo.git/

- HTTP
http[s]://host.xz[:port]/path/to/repo.git/

git config

Usage
$git config user.email

git config levels and files:

    - --local
    Local configuration values are stored in a file that can be found in the repo's .git directory: .git/config

    - --global
    Global configuration values are stored in a file that is located in a user's home directory. ~ /.gitconfig

    - --system

Writing a value
$git config --global user.email "your_email@example.com"
$git config --global merge.tool kdiff3
$ git config --global color.ui false

Aliases
$git config --global alias.ci commit
$git config --global alias.amend git ci --amend

$git --version
$git config --global --list
$git pull REMOTE NAME-OF-BRANCH -u

Create a branch
$git checkout -b NAME-OF-BRANCH
$git checkout NAME-OF-BRANCH
$git status
$git add CHANGES IN RED
$git commit -m "DESCRIBE THE INTENTION OF THE COMMIT"
$git push REMOTE NAME-OF-BRANCH

Delete all changes in the Git repository, but leave unstaged things
$git checkout .

Delete all changes in the Git repository, including untracked files
$git clean -f

Merge created branch with master branch
$git checkout NAME-OF-BRANCH
$git merge master

Merge master branch with created branch
$git checkout master
$git merge NAME-OF-BRANCH

GitLab Installation

官網 https://about.gitlab.com/installation/#ubuntu
文件 https://docs.gitlab.com/ee/README.html

1. Install and configure the necessary dependencies
$sudo apt-get install curl openssh-server ca-certificates postfix

2. Add the GitLab package server and install the package
$curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
$sudo apt-get install gitlab-ce

If you are not comfortable installing the repository through a piped script, you can find the entire script here and select and download the package manually and install using:
dpkg -i gitlab-ce-XXX.deb

3. Configure and start GitLab
sudo gitlab-ctl reconfigure

4. Browse to the hostname and login
The default account's username is root. Provide the password you created earlier and login. After login you can change the username if you wish

GitLab start stop

文件 https://docs.gitlab.com/ee/administration/restart_gitlab.html

Omnibus GitLab restart
$sudo service gitlab-ctl status restart stop start
$sudo gitlab-ctl restart nginx

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

$sudo gitlab-ctl kill <service>

Reconfigure Omnibus GitLab with:
$sudo gitlab-ctl reconfigure

GitLab User Account

文件 https://docs.gitlab.com/ee/ssh/README.html

Before generating a new SSH key pair check if your system already has one at the default location by opening a shell, or Command Prompt on Windows, and running the following command:
Windows Command Prompt:
$type %userprofile%\.ssh\id_rsa.pub

Git Bash on Windows / GNU/Linux / macOS / PowerShell:
$cat ~/.ssh/id_rsa.pub


Generating a new SSH key pair
$ssh-keygen -t rsa -C "your.email@example.com" -b 4096

Note: If you want to change the password of your SSH key pair, you can use
$ssh-keygen -p <keyname>.

GitLab server conf

文件

conf in:
/etc/gitlab/gitlab.rb

install in:
/var/opt/gitlab/git-data/

#grep -v '#' gitlab.rb |grep -v ^$
->external_url 'http://192.168.0.62:8081'
->gitlab_rails['gitlab_shell_ssh_port'] = 81
->nginx['listen_addresses']= ['192.168.0.62']

access gitlab from browser
http://192.168.0.62:8081
Username: root
Password: 5iveL!fe  12345678

change password for root:
gitlab-rails console production
->user = User.where(id: 1).first   or  user = User.find_by(email: 'admin@local.host')
->user.password = 'secret_pass'
->user.password_confirmation = 'secret_pass'
->user.save!



--gitlab backup---------
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

write conf /etc/gitlab/gitlab.rb
->gitlab_rails['backup_path'] = '/mnt/backups'

recover
gitlab-rake gitlab:backup:restore BACKUP=1393513186

create database db_linkall_demo default charset utf8 collate utf8_general_ci;

->grant all privileges on db_linkall_demo.* to dbuser@localhost identified by ‘111111’;
->flush privileges;

相關文章